__fish_urlencode: rework to behave properly on BSD/OS X

Work on #68.
This commit is contained in:
David Adam 2014-11-20 13:53:24 +08:00
parent 8e8549ef7a
commit 0abdf9eeff

View File

@ -1,9 +1,10 @@
function __fish_urlencode --description "URL-encode stdin"
while read f
set lines (echo "$f" | sed -E -e 's/./\n\\0/g;/^$/d;s/\n//')
set -l IFS ''
set -l output
while read --array --local lines
if [ (count $lines) -gt 0 ]
printf '%%%02x' "'"$lines"'" | sed -e 's/%2[fF]/\//g';
set output $output (printf '%%%02x' "'"$lines"'" | sed -e 's/%2[fF]/\//g')
end
end
echo
echo -s $output
end