mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-24 12:35:44 +08:00
dfb4998778
Improves experience during upgrades, accidentally running an old fish with a new environment. No errors just from printing a prompt. Fixes #3057. Print helpful notice also when launching mismatched fish. Autoloadable string.fish -- only create function if not builtin.
27 lines
561 B
Fish
27 lines
561 B
Fish
function __fish_urlencode --description "URL-encode stdin"
|
|
if not type -q string
|
|
return 1
|
|
end
|
|
|
|
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
|