abbr.fish: escape the output of abbr --show

Allows abbreviations containing embedded newlines, etc., to be displayed
and exported properly.

Work on #731.
This commit is contained in:
David Adam 2014-11-16 23:12:41 +08:00
parent 206ea15b68
commit 14fa48864a

View file

@ -100,7 +100,9 @@ function abbr --description "Manage abbreviations"
case 'show' case 'show'
for i in $fish_user_abbreviations for i in $fish_user_abbreviations
echo abbr -a \'$i\' # Disable newline splitting
set -lx IFS ''
echo abbr -a \'(__fish_abbr_escape $i)\'
end end
return 0 return 0
@ -114,6 +116,10 @@ function abbr --description "Manage abbreviations"
end end
end end
function __fish_abbr_escape
echo $argv | sed -e s,\\\\,\\\\\\\\,g -e s,\',\\\\\',g
end
function __fish_abbr_get_by_key function __fish_abbr_get_by_key
if not set -q argv[1] if not set -q argv[1]
echo "__fish_abbr_get_by_key: expected one argument, got none" >&2 echo "__fish_abbr_get_by_key: expected one argument, got none" >&2