TIL: alias search

I’ve accumulated a significant amount of shell aliases over the years. Every now and then I forget the alias I’m looking for, especially for the ones I use less frequently. Here’s a meta-alias to ease this task:

alias als='alias | grep -i --'

It lists all aliases with the alias command and pipes the output into case-insensitive grep. The two dashes -- at the end are required to prevent grep from interpreting a search term starting with a dash as an argument.

Examples of usage:

> als '^gd'
gd='git ls-files'
gdc='git ls-files --cached'
gdi='git status --porcelain --short --ignored| sed -n "s/^!! //p"'
gdk='git ls-files --killed'
gdm='git ls-files --modified'
gdu='git ls-files --other --exclude-standard'
gdx='git ls-files --deleted'

> als -abor
gma='git merge --abort'
gra='git rebase --abort'

> als xarg
xargs0='tr ''\n'' ''\0'' | xargs -0'

More posts here.