List all aliases available in fish/bash shell

2019-06-16 18:42发布

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

4条回答
三岁会撩人
2楼-- · 2019-06-16 19:22

In 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'
查看更多
来,给爷笑一个
3楼-- · 2019-06-16 19:22

Fish:

⏵ functions
abbr, ack, acs, alias, calc, cd…

⏵ functions ls
function ls
    command ls -A -x --si --color --classify --group-directories-first $argv;
end
查看更多
贼婆χ
4楼-- · 2019-06-16 19:29

You can add your own fish function to list aliases like so:

$ 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'
查看更多
Evening l夕情丶
5楼-- · 2019-06-16 19:36

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.

查看更多
登录 后发表回答