blob: 450f368c42a762d532b1375ffbfa2a432fa689d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
|