aboutsummaryrefslogtreecommitdiffstats
path: root/.config/init/funcs
diff options
context:
space:
mode:
Diffstat (limited to '.config/init/funcs')
-rwxr-xr-x.config/init/funcs/lget39
1 files changed, 39 insertions, 0 deletions
diff --git a/.config/init/funcs/lget b/.config/init/funcs/lget
new file mode 100755
index 0000000..450f368
--- /dev/null
+++ b/.config/init/funcs/lget
@@ -0,0 +1,39 @@
+#!/usr/bin/env zsh
+# grab files from ipfs
+
+source "$HOME/.config/init/helpers" || exit 1
+
+setopt HIST_SUBST_PATTERN
+
+local pat='^http://localhost:8080/ipfs/.+\?filename=.+$'
+
+local name
+local hash
+
+local escapes
+typeset -A escapes
+escapes=('%20' ' ' '%22' '"' '%23' '#' '%24' '$'
+ '%25' '%' '%26' '&' '%27' "'" '%2b' '+'
+ '%2C' ',' '%2F' '/' '%3A' ':' '%3B' ';'
+ '%3C' '<' '%3D' '=' '%3E' '>' '%3F' '?'
+ '%40' '@' '%5B' '[' '%5C' '\' '%5D' ']'
+ '%5E' '^' '%60' '`' '%7B' '{' '%7C' '|'
+ '%7D' '}' '%7E' '~' '%28' '(' '%29' ')')
+
+[[ "$1" ]] \
+ || abort "please specify at least one url to get"
+
+for i in $@; do
+ [[ $i =~ $tpat ]] \
+ || abort "bad url \`$i\`"
+done
+
+for i in $@; do
+ name=${i:s/*\filename=/}
+ for k in ${(@k)escapes}; name=${name:gs/$k/$escapes[$k]/}
+
+ hash=${i:s|http://localhost:8080/ipfs/|}
+ hash=${hash:s|\?filename=*|}
+
+ ipfs get -o $name $hash
+done