From 93fa0e7c59b2f6c8ad273906177492203535e0e9 Mon Sep 17 00:00:00 2001 From: katherine Date: Sat, 2 Dec 2023 17:44:23 -0700 Subject: add ipfs get func --- .config/init/funcreqs/lget | 2 ++ .config/init/funcs/lget | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .config/init/funcreqs/lget create mode 100755 .config/init/funcs/lget (limited to '.config/init') 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 -- cgit v1.2.3