Improve programming efficiency tips-1:Customise your own aliases file
Created2021-01-25Updated2021-01-29
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
Create .bashrs file in ‘C:\Users\[username]\.bashrc’
When open git-bash from start menu, it will create bash_profile in ‘C:\Users\[username]’ to open .bashrc
When open bash in VS code, it will run the .bashrc file automatically(I changed my VS code intergrated terminal to bash).
After updating the .bashrs file, the terminal or VS code needs to be restarted for the new aliases to work.
#! .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
Find .bash_profile in MacOS(normally in ‘/Users/[username]/.bash_profile’).
Create .aliases file in folder ‘/Users/[username]’.
Need to run ‘source ~/.bash_profile’ to get the aliases work.
Here is my aliases list for Mac (as I deploy my Hexo blog through Macbook, the list includes aliases for updating my hexo blog)
# .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.