aboutsummaryrefslogtreecommitdiffstats
path: root/.config/init/funcs
diff options
context:
space:
mode:
authorkatherine <ageha@airen-no-jikken.icu>2023-12-02 17:44:23 -0700
committerkatherine <ageha@airen-no-jikken.icu>2023-12-02 17:44:23 -0700
commit93fa0e7c59b2f6c8ad273906177492203535e0e9 (patch)
tree3b05052892414ba7010a481910c2af8a92c86092 /.config/init/funcs
parentc58ca45eeee2bc11e0af233aa0d8a0512ecb0ba7 (diff)
downloaddotfiles-93fa0e7c59b2f6c8ad273906177492203535e0e9.tar.gz
add ipfs get func
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