[Bash]: Setting Alias on Terminal
bash
04/16/2019
Start
Bash (Terminal's default command line interpreter) allows you to create aliases. You can think of aliases as nothing more than a keyboard shortcut.
To add/modify alias on terminal:
Creating alias is simple. On command line, you can type
alias ll="ls -alh"
Creating this alias allows user to type in 'll' instead of 'ls -alh' on a command-line (to view list of all itmes with its file size). However, this is not permanent; once the terminal is quit, this alias will be removed. Unless:
Setting a permanent alias
By using your favorite text editor, open .bash_profile
in your home directory. On Windows, you would need to have git bash installed.
vim ~/.bash_profile# ORnano ~/.bash_profile
Using zsh? Create alias inside
~/.zshrc
In this file you can simply add in
alias ll="ls -alh"
and save it. This will work after you restart your terminal
alias
By typing 'alias' on command line shows you what alias you currently have (not functions)
Another example:
function postup() { git add . git commit -m "[UPDATE]: updated post" git push}function pu() { git add . git commit -m "[UPDATE]: updated post" git push}
You can also create a function to have a multiple command prompt in one keyword. I use this commonly when modifying a post on this page.
Usage:
postup
is equivalent to typing:
git add .git commit -m "[UPDATE]: updated post"git push
Using a different commit message:
function lazy() { git add . git commit -a -m "$1" git push}
Usage:
lazy "added a new post"
More useful aliases
# Clears the screenalias c="clear"
# Moves your directory to your desired location. I use this often to get to my project folderalias movdir="/your/favorite/directory"
# Open the folder in finderalias o="open ."
Above two commands can be a good combination;
movedir
->o
To open a folder on Windows in command line, use
start .
instead ofopen .
# Shows how long the system has been upalias ut="uptime"
alias dev="npm run dev"
# Push to heroku productionalias hero="git push heroku master"
alias sql="mysql -u root"
function newrepo() { git init git add . git commit -m "[INITIAL]: initial commit 🔥" git remote add origin $1 git push -u origin master}
Alias to shorten categorized commit messages
Refer to Categorize your GitHub Commit Messages
function add() { git add . git commit -a -m "[ADD]: $1" git push}
Note: Make sure to include message inside "" on command-line. Ex)
add "some message"
function update() { git add . git commit -a -m "[UPDATE]: $1" git push}
function update() { git add . git commit -a -m "[UPDATE]: $1" git push}
function styles() { git add . git commit -a -m "[STYLES]: $1" git push}