Write an alias function that acts like alias(1) except when given a pattern. In that case it should print matching aliases.

Challenge accepted:

alias() {
    if [[ $1 =~ [][*] ]]; then
        command grep "^alias $1" ~/.bash_aliases
        eval builtin alias $(sed "s/=\(.*\)/='\1'/" <<< $1)

This is what happens:

  1. Detect regex characters [, ], *
  2. If regex is detected grep aliases
  3. Else use regular alias(1)

Works as advertised:

$ alias h.*
alias h="heroku"
alias hl="heroku logs -t"
alias hc="heroku run console"
alias hstat="curl -o /dev/null -sIw '%{http_code}\n'" $1

$ alias [xtz]
alias xopen='xdg-open'
alias trees='tree -h --sort=size'
alias ts='trees'
alias t='tree'

$alias v
bash: alias: v: not found
$alias v='vim ~/.vimrc'
$alias v
alias v='vim ~/.vimrc'