列出fish/bash shell中可用的所有别名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39942004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List all aliases available in fish/bash shell
提问by Labithiotis
Is there a way to list all aliases, something like:
有没有办法列出所有别名,例如:
$ ls-aliases
.. "cd .."
la "ls -Gla"
gs "git stash"
etc...
Also is it possible to add human readable descriptions to aliases ?
是否可以向别名添加人类可读的描述?
I'm on a MacOSX
我在 MacOSX 上
回答by heemayl
In bash
:
在bash
:
To list all aliases:
列出所有别名:
alias
To add a comment, just put it at the end of the command, e.g.:
要添加评论,只需将其放在命令的末尾,例如:
$ alias foo='echo bar #some description'
$ foo
bar
$ alias foo
alias foo='echo bar #some description'
回答by Kurtis Rader
Note that in fish the alias
command creates a function using the alias name that wraps the alias value. So there isn't currently any way to list just "aliases". You can use the functions
command to list the names of all the defined functions (which by definition includes aliases). If you want the names one per line just functions | cat
.
请注意,在fish 中,该alias
命令使用包装别名值的别名创建了一个函数。所以目前没有任何方法可以只列出“别名”。您可以使用该functions
命令列出所有已定义函数的名称(根据定义,它包括别名)。如果您想要每行一个名称,只需functions | cat
.
回答by stantronic
You can add your own fish function to list aliases like so:
您可以添加自己的 fish 函数来列出别名,如下所示:
$ function aliases --description "list all fish aliases" 0|19:02:45
for f in (functions)
functions $f | grep \'alias
end
end
Then save it
然后保存
$ funcsave aliases
And call it
并称之为
$ aliases
Example output:
示例输出:
function fishc --description 'alias fishc=vim ~/.config/fish/config.fish'
function flutter --description 'alias flutter=~/Repos/DevResources/flutter/bin/flutter'
function imgcat --description 'alias imgcat=~/.iterm2/imgcat'
function imgls --description 'alias imgls=~/.iterm2/imgls'
function inkscape --description 'alias inkscape=/usr/local/Cellar/inkscape/0.92.2_1/bin/inkscape'
回答by vekerdyb
If someone stumbles upon this like I did:
如果有人像我一样偶然发现这个:
Current fish
version (3.0.2) has alias
(without params) that lists all aliases.
当前fish
版本 (3.0.2) 具有alias
(不带参数)列出所有别名。
(Similarly abbr
lists all abbreviations.)
(同样abbr
列出所有缩写。)
(@heemayl pointed out that bash
has alias
as well...)
(@heemayl 指出也bash
有alias
......)
回答by Gringo Suave
Fish:
鱼:
? functions
abbr, ack, acs, alias, calc, cd…
? functions ls
function ls
command ls -A -x --si --color --classify --group-directories-first $argv;
end