mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 04:13:08 +00:00
Fix the file URL for Terminal.app
* 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.
This commit is contained in:
parent
0395c33982
commit
1767681f9a
1 changed files with 6 additions and 5 deletions
|
@ -1,10 +1,11 @@
|
|||
function __fish_urlencode --description "URL-encode stdin"
|
||||
set -l IFS ''
|
||||
set -l output
|
||||
while read --array --local lines
|
||||
if [ (count $lines) -gt 0 ]
|
||||
set output $output (printf '%%%02x' "'"$lines"'" | sed -e 's/%2[fF]/\//g')
|
||||
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
|
||||
echo -s $output | sed -e 's/%2[fF]/\//g'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue