mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-07 15:31:14 -03:00
* When using a UTF-8 locale, set locale to C temporarily in order to read one byte at a time. * Use the builtin printf in a forward-compatible way. (GNU) * Improve the readability of the code.
12 lines
367 B
Fish
12 lines
367 B
Fish
function __fish_urlencode --description "URL-encode stdin"
|
|
set -l output
|
|
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 --array chars; end
|
|
if count $chars > /dev/null
|
|
set output $output (printf '%%%02x' "'"$chars)
|
|
end
|
|
end
|
|
echo -s $output | sed -e 's/%2[fF]/\//g'
|
|
end
|