aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__fish_urlencode.fish
diff options
context:
space:
mode:
authorGravatar Jak Wings <jakwings@gmail.com>2015-12-12 07:35:57 +0800
committerGravatar Kurtis Rader <krader@skepticism.us>2016-02-16 21:49:58 -0800
commit1767681f9a61ac0789f5dafa76126e3446924b6d (patch)
tree04f686b67afee75e2ab01ef8bcf106dd91a54bb6 /share/functions/__fish_urlencode.fish
parent0395c33982db8dd6336b11c1f1106ac08cf21c5b (diff)
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.
Diffstat (limited to 'share/functions/__fish_urlencode.fish')
-rw-r--r--share/functions/__fish_urlencode.fish11
1 files changed, 6 insertions, 5 deletions
diff --git a/share/functions/__fish_urlencode.fish b/share/functions/__fish_urlencode.fish
index ab13beaa..d17451f3 100644
--- a/share/functions/__fish_urlencode.fish
+++ b/share/functions/__fish_urlencode.fish
@@ -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