mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 21:18:53 +00:00
make 'alias' check for recursive calls and insert 'command'; update docs, fix #486
This commit is contained in:
parent
1ae0e5d7cb
commit
a4c646f75c
4 changed files with 16 additions and 5 deletions
|
@ -44,7 +44,7 @@ will run the \c ls command, using the \c -l option, while passing on any additio
|
|||
|
||||
<pre>
|
||||
function mkdir -d "Create a directory and set CWD"
|
||||
mkdir $argv
|
||||
command mkdir $argv
|
||||
if test $status = 0
|
||||
switch $argv[(count $argv)]
|
||||
case '-*'
|
||||
|
|
|
@ -284,7 +284,7 @@ turning on colors on GNU systems is \c '--color=auto'. A wrapper
|
|||
around \c ls might look like this:
|
||||
|
||||
<pre>function ls
|
||||
ls --color=auto $argv
|
||||
command ls --color=auto $argv
|
||||
end
|
||||
</pre>
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue