diff options
-rw-r--r-- | .config/init/funcreqs/lget | 2 | ||||
-rwxr-xr-x | .config/init/funcs/lget | 39 |
2 files changed, 41 insertions, 0 deletions
diff --git a/.config/init/funcreqs/lget b/.config/init/funcreqs/lget new file mode 100644 index 0000000..c12105c --- /dev/null +++ b/.config/init/funcreqs/lget @@ -0,0 +1,2 @@ +func_init_prereqs=(ipfs) +func_init_checks=() 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 |