23

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

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Labithiotis
  • 3,519
  • 7
  • 27
  • 47
  • 1
    See: `help alias` – Cyrus Oct 09 '16 at 09:36
  • If your alias is complex enough to need a comment or description, it should probably be a function instead. – chepner Oct 09 '16 at 14:55
  • `fish` and `bash` are two different shells, from completely different families with no pretense or attempt at mutual compatibility. Asking for both in the same question is questionable -- it'd be like asking how to do the same thing in LISP and C. – Charles Duffy Dec 31 '18 at 02:57
  • 1
    (Moreover, questions about interactive use belong on [unix.se] or [SuperUser](https://superuser.com/), not Stack Overflow -- per https://stackoverflow.com/help/on-topic, only questions "unique to software development" are topical here; and aliases aren't even enabled in scripts at all!) – Charles Duffy Dec 31 '18 at 02:58

5 Answers5

28

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'
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
heemayl
  • 39,294
  • 7
  • 70
  • 76
12

If someone stumbles upon this like I did:

Current fish version (3.0.2) has alias (without params) that lists all aliases.

(Similarly abbr lists all abbreviations.)

(@heemayl pointed out that bash has alias as well...)

vekerdyb
  • 1,213
  • 12
  • 26
7

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.

Kurtis Rader
  • 6,734
  • 13
  • 20
4

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'
stantronic
  • 397
  • 7
  • 14
0

Fish:

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

⏵ functions ls
function ls
    command ls -A -x --si --color --classify --group-directories-first $argv;
end
Gringo Suave
  • 29,931
  • 6
  • 88
  • 75