Notes

Bash aliases notes

author: Paul Kim

categories: bash, linux, mac, windows

tags: bash, linux, mac, windows

Bash aliases are command shortcuts.

Create bash aliases

  • Ubuntu Linux
  • Windows Subsystem for Linux
cd ~
touch .bash_aliases
chmod 644 .bash_aliases

Note: On Linux, do not create .bash_profile because it will ignore .profile.

Edit bash profile

  • Mac - edit .bash_profile
  • Git Bash for Windows - edit .bash_profile

Some of my bash aliases

# list files only
alias lsfo='stat -c '\''%n'\'' *'

# list files with permission in octal
alias lsp='stat -c '\''%a %n'\'' *'

# sudo update/grade/remove
alias supsugar='sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y'

# mysql aliases
alias start-mysql='sudo systemctl start mysql.service'
alias restart-mysql='sudo systemctl restart mysql.service'
alias stop-mysql='sudo systemctl stop mysql.service'
alias status-mysql='sudo systemctl status mysql.service'

# enable SQLite autocompletion
# note: put this before android on path.
# because android also has sqlite3 that will get overridden.
alias sqlite3='rlwrap -a -N -c -i sqlite3'

# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# pyenv pyenv-virtualenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi

# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# # add JAVA_HOME to path (not necessary with jenv)
# export PATH=$PATH:$JAVA_HOME/bin

# android
export ANDROID_HOME=/home/paul/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools

# list files only
alias lsfo='stat -f '\''%N'\'' *'

# list files with permission in octal
alias lsp='stat -f '\''%A %N'\'' *'

# brew update/upgrade/doctor
alias bitchesbrew='brew doctor && brew update && brew upgrade && brew cask doctor && brew cask upgrade'

# mysql aliases
alias start-mysql='mysql.server start'
alias restart-mysql='mysql.server restart'
alias stop-mysql='mysql.server stop'
alias status-mysql='mysql.server status'

# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# pyenv pyenv-virtualenv
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi
# suppress `brew doctor` warning about pyenv shims
# (https://github.com/pyenv/pyenv/issues/106)
alias brew='env PATH=${PATH//$(pyenv root)\/shims:/} brew'

# rbenv
eval "$(rbenv init -)"
# # install Ruby Gems to ~/gems
# export GEM_HOME=$HOME/gems
# export PATH=$HOME/gems/bin:$PATH

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# add JAVA_HOME to path (not necessary with jenv)
export PATH=$PATH:$JAVA_HOME/bin

# android
export ANDROID_HOME=/Users/pkim/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools

# access sqlite3 on git bash
alias sqlite3="winpty sqlite3.exe"

# access mysql on git bash
alias mysql="winpty mysql.exe"


ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.