Improve programming efficiency tips-1:Customise your own aliases file

Different terminals have different ways of setting alias file. I will use git bash as an example to demonstrate setting aliases in both MacOS and Windows system.

Windows

  1. Create .bashrs file in ‘C:\Users\[username]\.bashrc’
  2. When open git-bash from start menu, it will create bash_profile in ‘C:\Users\[username]’ to open .bashrc
  3. When open bash in VS code, it will run the .bashrc file automatically(I changed my VS code intergrated terminal to bash).
  4. After updating the .bashrs file, the terminal or VS code needs to be restarted for the new aliases to work.
  5. Here is the aliases list I set for myself:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! .bashrs file
# navigation
alias ls='ls -F --color=auto --show-control-chars'
alias ll='ls -l'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias dt='cd "C:\Users\Cindy Wang\Desktop"'
alias ht='cd "C:\xampp\htdocs"'
alias htbap='code "C:\xampp\htdocs\BugAndPlan"'
alias htmyb='code "C:\xampp\htdocs\myBugTracker"'
alias htpost='code "C:\xampp\htdocs\postMVC"'
#alias bp='code "C:\Program Files\Git\etc\profile.d\aliases.sh"'
alias bp='code "C:\Users\Cindy Wang\.bashrc"'

#cli
alias cls='clear'
alias rf='rm -i'
alias tf='touch'
alias md='mkdir'

#laravel cli
alias ln='laravel new'
alias ui='composer require laravel/ui'
alias bs=' php artisan ui bootstrap --auth'
alias vue=' php artisan ui vue --auth'
alias react=' php artisan ui react --auth'
alias cpenv='cp .env.example .env'
alias ser='php artisan serve'
alias prauth='php artisan make:controller Auth\\'
alias prmc='php artisan make:controller' #prmc UserController -r
alias prm='php artisan migrate'
alias prmma='php artisan make:migration' # 'php artisan make:migration add_role_to_users_table --table=users'
alias prmr='php artisan migrate:rollback'
alias prmm='php artisan make:model'
alias prmid='php artisan make:middleware' # Admin
alias prms='php artisan make:seeder' # Role
alias prsc='php artisan db:seed --class' # Role

alias prl='php artisan route:list'

#npm
alias i='npm install'
alias run='npm run dev'
alias irun='npm install && npm run dev'

Mac

  1. Find .bash_profile in MacOS(normally in ‘/Users/[username]/.bash_profile’).
  2. Create .aliases file in folder ‘/Users/[username]’.
  3. Need to run ‘source ~/.bash_profile’ to get the aliases work.
  4. Here is my aliases list for Mac (as I deploy my Hexo blog through Macbook, the list includes aliases for updating my hexo blog)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# .aliases file
# Nav
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"
# alias d="cd ~/Documents/Dropbox"
# alias dl="cd ~/Downloads"
alias dt="cd ~/Desktop"
alias p="cd ~/projects"
# alias g="git"
# alias h="history"
# alias j="jobs"

# edit .bash_profile
alias bpa="atom ~/.bash_profile"
alias bpvs="code ~/.bash_profile"
alias alvs="code ~/.aliases"
alias bpr="source ~/.bash_profile"

#HexoBlog
alias hcg="hexo clean&&hexo g"
alias hd="hexo d"

After using aliases, it is saving my time from typing same long command line again and again. I also only need to remember one aliases list which can be used on both Windows and MacOs system. When I am programming, I usually open the aliases list to add more whenever necessary.

reference:
https://gist.github.com/wzup/36b5159d8c580b827384