Alias function

| | [C]olor

This is a useful wrapper function for the alias command:

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

In addition to defining aliases, this function can print aliases that match a pattern:

# print aliases starting with 'h'
$ 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

# print aliases starting with 'x', 't', or 'z'
$ alias [xtz]
alias xopen='xdg-open'
alias trees='tree -h --sort=size'
alias ts='trees'
alias t='tree'

# if no pattern is given, fallback to default alias
$ alias v
bash: alias: v: not found
$ alias v='vim ~/.vimrc'
$ alias v
alias v='vim ~/.vimrc'