diff --git a/doc_src/function.txt b/doc_src/function.txt index 4761a5d93..10d9eec05 100644 --- a/doc_src/function.txt +++ b/doc_src/function.txt @@ -44,7 +44,7 @@ will run the \c ls command, using the \c -l option, while passing on any additio
function mkdir -d "Create a directory and set CWD" - mkdir $argv + command mkdir $argv if test $status = 0 switch $argv[(count $argv)] case '-*' diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index f03b30363..1df30947b 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -284,7 +284,7 @@ turning on colors on GNU systems is \c '--color=auto'. A wrapper around \c ls might look like this:function ls - ls --color=auto $argv + command ls --color=auto $argv end@@ -292,7 +292,7 @@ There are a few important things that need to be noted about wrapper functions: - Wrappers should always take care to add the $argv variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command. -- If the wrapped command is not the first command to be called by the wrapper, it is necessary to prefix the call to the command with the word 'command' in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs. +- If the wrapper has the same name as the wrapped command, it is necessary to prefix the call to the command with the word 'command' in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs. \subsubsection syntax-function-autoloading Autoloading functions diff --git a/doc_src/type.txt b/doc_src/type.txt index 593da3b91..dde723644 100644 --- a/doc_src/type.txt +++ b/doc_src/type.txt @@ -10,7 +10,7 @@ With no options, indicate how each name would be interpreted if used as a comman - \c -h or \c --help print this message - \c -a or \c --all print all of possible definitions of the specified names - \c -f or \c --no-functions suppresses function and builtin lookup -- \c -t or \c --type print a string which is one of alias, keyword, function, builtin, or file if name is an alias, shell reserved word, function, builtin, or disk file, respectively +- \c -t or \c --type print a string which is one of keyword, function, builtin, or file if name is a shell reserved word, function, builtin, or disk file, respectively - \c -p or \c --path either return the name of the disk file that would be executed if name were specified as a command name, or nothing if 'type -t name' would not return 'file' - \c -P or \c --force-path either return the name of the disk file that would be executed if name were specified as a command name, or nothing no file with the specified name could be found in the PATH diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 25eec3ea0..cbd41d0fb 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -11,6 +11,7 @@ function alias --description "Legacy function for creating shellscript functions set -l name set -l body + set -l prefix switch (count $argv) case 0 @@ -34,5 +35,15 @@ function alias --description "Legacy function for creating shellscript functions return 1 end - eval "function $name; $body \$argv; end" + switch (type -t $name) + case file + set prefix command + case builtin + set prefix builtin + case function + printf ( _ "%s: A function with the name '%s' already exists. Use the 'functions' or 'funced' commands to edit it.") alias "$name" + return 1 + end + + eval "function $name; $prefix $body \$argv; end" end