diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 318009f14..51c6055a9 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -17,9 +17,11 @@ function alias --description 'Creates a function wrapping a command' if not set -q argv[1] # Print the known aliases. for func in (functions -n) - set -l output (functions $func | string match -r -- "function .* --description '(alias .*)'" | string split \n) - set -q output[2] - and echo $output[2] + set -l output (functions $func | string match -r -- "^function .* --description 'alias (.*)'") + if set -q output[2] + set output (string replace -r '^'$func'[= ]' '' -- $output[2]) + echo alias $func (string escape -- $output[1]) + end end return 0 else if not set -q argv[2] diff --git a/tests/alias.in b/tests/alias.in index b3423b56f..6276a5f96 100644 --- a/tests/alias.in +++ b/tests/alias.in @@ -5,3 +5,10 @@ function foo end alias my_alias "foo; and echo foo ran" my_alias + +alias a-2='echo "hello there"' + +echo '# bare `alias` should list the aliases we have created and nothing else' +# We have to exclude two aliases because they're an artifact of the unit test +# framework and we can't predict the definition. +alias | grep -Ev '^alias (fish_indent|fish_key_reader) ' diff --git a/tests/alias.out b/tests/alias.out index b07ca34b6..5da9852d3 100644 --- a/tests/alias.out +++ b/tests/alias.out @@ -1,2 +1,5 @@ ran foo foo ran +# bare `alias` should list the aliases we have created and nothing else +alias a-2 'echo "hello there"' +alias my_alias 'foo; and echo foo ran' diff --git a/tests/test1.in b/tests/test1.in index 86f7999c9..47ff18809 100644 --- a/tests/test1.in +++ b/tests/test1.in @@ -1,5 +1,5 @@ # -#Test aliases, loops, conditionals and some basic elements +#Test function, loops, conditionals and some basic elements # for i in 1 2 #Comment on same line as command @@ -30,7 +30,7 @@ for i in \ end -# Simple alias tests +# Simple function tests function foo echo >../test/temp/fish_foo.txt $argv