fish-shell/share/functions/__fish_urlencode.fish
Kurtis Rader 11a60c8374 reformat all fish scripts
I hate doing this but I am tired of touching a fish script as part of
some change and having `make style` radically change it. Which makes
editing fish scripts more painful than it needs to be. It is time to do
a wholesale reformatting of these scripts to conform to the documented
style as implemented by the `fish_indent` program.
2016-11-27 21:27:22 -08:00

27 lines
695 B
Fish

function __fish_urlencode --description "URL-encode stdin"
set -l join ''
set -l chars
# Set locale to C and IFS to "" in order to split a line into bytes.
while begin
set -lx LC_ALL C
set -lx IFS ''
read -az chars
end
printf '%s' $join
# chomp off a trailing newline
if test "$chars[-1]" = \n
set -e chars[-1]
set join '%0A%00'
else
set join '%00'
end
for c in $chars
if string match -q -r '[/._~A-Za-z0-9-]' $c
printf '%s' $c
else
printf '%%%02X' "'$c"
end
end
end
end