~/.bash aliases

From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search

Bash alias is often defined in ~/.bashrc file. However, it is possible to use ~/.bash_aliases file too on certain Linux distros.

Alias definitions in ~/.bash aliases file

You may want to put all your additions into a separate file like ~/.bash_aliases, instead of adding them directly to ~/.bashrc file.

Calling ~/bash aliases

The ~/.bash_aliases must be called by your $HOME/.bashrc file as follows:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

Sample ~/bash_aliases file

You can add anything you want including shell aliases. For instance:

export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\\$ "

         .'     '.
        /  _   _  \
        | (o)_(o) |
         \(     ) /
         //'._.'\ \
        //   .   \ \
       ||   .     \ \
       |\   :     / |
       \ `) '   (`  /_
     _)``".____,.'"` (_
     )     )'--'(     (
      '---`      `---`

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/home/vivek/google-cloud-sdk/path.bash.inc' ]; then . '/home/vivek/google-cloud-sdk/path.bash.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/home/vivek/google-cloud-sdk/completion.bash.inc' ]; then . '/home/vivek/google-cloud-sdk/completion.bash.inc'; fi

export HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
export PROMPT_COMMAND="history -a; history -n"
export HISTIGNORE="ls:ll:cd:pwd:bg:fg:history"
export HISTSIZE=100000
export HISTFILESIZE=10000000
shopt -s histappend histreedit histverify
shopt -s no_empty_cmd_completion
export HISTTIMEFORMAT="%d/%m/%y %T "
alias update='sudo -- sh -c "apt update && apt -y upgrade && apt -y --purge autoremove && sudo apt -y clean"'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias l.='ls -d .* --color=auto'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'

export PATH=$PATH:/home/vivek/.2fa/
	local services
	services=$(find "/home/vivek/.2fa/" -type d -printf "%f " | sed 's/.2fa\///')
	complete -W "$services" decrypt.key.sh
	complete -W "$services" ~/.2fa/decrypt.key.sh

complete -F _decrypt_key_sh decrypt.key.sh
complete -C '/usr/local/bin/aws_completer' aws
export EDITOR=vim
export VISUAL=vim

See also