Mac shell aliases (.zshrc)
Mac shell aliases (.zshrc)
aliases to improve productivity, grouped by area: system, ports/pid, youtube-dl, git, npm
###################################### System One Time Configuration ###################################################
: '
only once is enough
shopt -s globstar ## to enable globstar useful ** in for file matching
shopt globstar ## to see globstar is enabled or not
shopt -u globstar ## to disable globstar
'
###################################### System ###################################################
alias a=" alias"
alias ob="open -t ~/.zshrc" ## open bash " notepad ~/.bashrc" ## "open -t ~/.zshrc" in mac -t -> defaut text editor
alias oa="open -t ~/.zshrc"
alias eb="open -t ~/.zshrc" ## edit bash
alias ea="open -t ~/.zshrc" ## edit alias
alias cls=" clear"
alias cf="open -t " # + file name ## create file
alias of="open -t " # + file name ## open file
alias af="open -t about.txt" # about file
###################################### Ports & PID ###################################################
## --------------------to see ports ...below commands needs corresponding access----so login is required
alias ports-listen="lsof -i -P -n | grep LISTEN" # to see listening ports
alias p-l="lsof -i -P -n | grep LISTEN" # to see listening ports
alias ports-all="lsof -i -P -n" # to see all running process
alias ports-search="lsof -i -P -n | grep " # port no ## to search particular port no and PID
## lsof -i:portNo <-- this also we can use to see port info
alias kill-process="kill " # PID
alias kill-process-force="kill -9 " # PID
alias k-p-f="kill -9 " # PID
###################################### youtube-dl ###############################################
: '
17 3gp 176x144
36 3gp 320x240
5 flv 400x240
43 webm 640x360
18 mp4 640x360
22 mp4 1280x720 (best)
'
alias y="youtube-dl " #+url
alias yv="youtube-dl -f 22 " #+url ( with video id ) ## mp4
alias yp="youtube-dl -f 22 " #+url ( with out video id and with playlist id) ## mp4
alias ypi="youtube-dl -f 22 -o '#%(playlist_index)s - %(title)s.%(ext)s' " # url ## youtube playlist index
###################################### git ###################################################
alias g="git"
alias gac="git add -A && git commit -a -m " # + commit message ## ***
alias gacm="git add -A && git commit -a -m " # + commit message
alias gi="git init "
alias gic="gi && gac " # git init and commit
alias gcl=" git clone " # + url ## ***
alias gs=" git status " ## ***
alias glg="git log" ## ***
alias glgg="git log --graph" ## ***
alias gst="git add -A && git stash push -m " # + stash message # "git add -A && git stash" ***
alias gstp="git stash pop" # ***
alias gsta="git stash apply" # ***
alias gstl="git stash list" # ***
alias gstc="git stash clear" # ***
##-------------remote related
alias gr="git remote " #
alias gra="git remote add " # name + url
alias grao="git remote add origin " # + url
alias grso="git remote set-url origin " # +url , to change/set url
alias grsu="git remote set-url " # remoteName url
alias grv="git remote -v " # to see origin url
alias grrmo="git remote rm origin " # instead of origin we can give any name
alias grro="git remote rm origin " # instead of origin we can give any name
##-------------the same above alias r--> rt ( rt =remote ) rm= remove
alias grt="git remote " #
alias grta="git remote add " # name + url
alias grtao="git remote add origin " # + url
alias grtso="git remote set-url origin " # +url , to change/set url
alias grtsu="git remote set-url " # remoteName url
alias grtv="git remote -v " # to see origin url
alias grts="git remote -v " # to see origin url # s = see
alias grtrmo="git remote rm origin " # instead of origin we can give any name ## r= remove // rm= remove
alias grtro="git remote rm origin " # instead of origin we can give any name
alias grtrm="git remote rm origin " # instead of origin we can give any name
alias grtr="git remote rm origin " # instead of origin we can give any name
alias gp="git push " # + remote branch name
alias gpo="git push origin" # branch name ## ***
alias gpom=" git push origin master "
alias gpr="git push -u " # remoteName branchName ***
alias gpu="git push -u " # remoteName branchName
## force push
alias gP="git push -f " # + remote branch name
alias gPo="git push -f --all origin" # branch name
alias gPom="git push -f --all origin master "
: '
all forced action related char should be in upper case
eg: gP
'
alias gpf="git push -f " # + remote branch name
alias gpof="git push -f --all origin" # branch name
alias gpomf="git push -f --all origin master "
alias gl=" git pull " # + remote branch name
alias glo="git pull origin" # branch name ## ***
alias glom=" git pull origin master "
alias gf="git fetch " # remote branch name
alias gfo="git fetch origin " # branch name
alias gfom="git fetch origin master "
## branch
alias gbl=" git branch " # , to see local branches ## ***
alias gbr=" git branch -a " # , to see remote branches ## ***
alias gb="git branch"
alias gob="git ls-remote -h origin"
## branch actions
alias gb=" git branch " # + branch name ## to create branch
alias gc="git checkout" # + branch name ## to checkout ## ***
alias gcb=" git checkout -b " # + branch name ## it'll create new branch and do checkout
## to pull particular commit in new branch
alias gcbc="git checkout -b " # +branch name + commit id
alias gpc="git checkout -b particular-commit " # +commit id ## it'll create 'particular-commit' branch with given commit
## ***
alias goc="git checkout -b old-commit " # +commit id ## ***
: '
git checkout -b new-branch commit_id
( it will create a new branch with name new-branch with the code till the commit commit_id)
or
git checkout -b new-branch
git merge commit_id
'
alias gm="git merge" # + branch name ## ***
alias gmXt="git merge -Xtheirs " # +branchname (i.e if conflicts exists, accept theirs/upstream changes) ***
alias gmXo="git merge -Xours " # +branchname ( i.e if conflicts exists, accept ours/downstream changes) ***
alias gms=" git merge --squash " # branch name
## squash merge won't add all feature branch commits, rather it'll force us to do a single merge commit ( only single commit )
: '
-Xours / -Xtheirs is opposite in git rebase case
git rebase -Xours branchName ...then if conflicts are there...ignore ours
ref https://demisx.github.io/git/rebase/2015/07/02/git-rebase-keep-my-branch-changes.html
'
## ( allowing unrelated histories )
alias gmf="git merge --allow-unrelated-histories " # + branch name
: '
## to merge remote branch
git merge remotes/origin/branchName or gm remotes/origin/branchName
'
: '
Revert , Reset, Rebase
https://opensource.com/article/18/6/git-reset-revert-rebase-commands
'
alias gcp="git cherry-pick" # commit ids
## revert
alias grvt="git revert " # commit id ***
## unstaging
alias gu="git reset HEAD -- ." # unstaging all files
alias gua="git reset HEAD -- ." # unstaging all files
alias guf="git reset HEAD -- " # path to file
## rebase
alias grb="git rebase" # + branch name
alias grbm="git rebase master"
alias grbo="git pull --rebase origin" #+ branch name
alias grbom="git pull --rebase origin master"
alias glrbo="git pull --rebase origin" #+ branch name
alias glrbom="git pull --rebase origin master"
alias grbXo="git rebase -Xours " #+branchName ( i.e if conflicts are there ignore ours...accept theirs) ***
alias grbXt="git rebase -Xtheirs " #+branchName ( i.e if conflicts are there ingore theirs ) ***
: '
-Xours / -Xtheirs is opposite in git merge case
git merge -Xtheirs branchName ...then if conflicts are there...accept theirs
'
## delete branch
alias gbd="git branch -d" # + branch name , it works only if it is merged with master # ***
alias gbD="git branch -D" # + branch name , delete forcefully ## ***
alias gpdo="git push -d origin" # branch name , to delete remote(origin) branch
alias gdb="git branch -d" # + branch name , it works only if it is merged with master
alias gDb="git branch -D" # + branch name , delete forcefully
alias gdob="git push -d origin" # branch name , to delete remote(origin) branch
alias gbdl="git branch -d" # + local branch name , it works only if it is merged with master
alias gbdr="git branch -d" # + remote branch name , to delete remote(origin) branch
alias gbdo="git branch -d" # + origin branch name , to delete remote(origin) branch
## ----------------------------------- tags---------------------------------
: '
tags are reference point to particular commit--> generally used to maintain releases
tag also refernce to commit, so we can do all action what we can do with commits
like : creating braches, pushing tags, deleting tags
'
## creation / list
alias gt="git tag " ## to list all tags or ## + tag-name to create
## to create tag 'git tag tag-name' use the above alias
: '
-----------------------------------to create annotated tag with message-----------------------------
$ git tag v.1.1 -a -m "relaese version v.1.1
// annotaged tag will be stored as a seperate object and it will contain extran info
--------------------------------to search tag with wild cards
$ git tag -l "name.*"
'
## info
alias gts="git show " ## + tag name ---to see all tag info
## pushing
alias gtp="git push origin " ## tag-name to push to remote
alias gtpa="git tag push origin --all" ## to push all trags
## delete --> same as branch
alias gtd="git tag -d " # +tag-name // if more than one comma(,) seperated
alias gtdr=" git push origin -d " # +tag-name
## checkout tag as a branch
alias gtb=" git checkout -b " ## + branch-name + tag-name
## to create tag at particular commit
alias gtc=" git tag " ## tag-name + commitId
## remove files
# from repo and file system
alias grm="git rm" # + file_name or -r folder_name
alias grma=" git rm -r *" # remove all
alias grmA="grma && grma" # removes even hidden and only extension files/folders
alias grmfl="git rm" # +file name , folder/t.txt
alias grmfo="git rm -r" # +folder name
# from repo not from file system
alias grmc="git rm --cached" # file_name or -r folder_name
alias grmcfl="git rm -c" # +file name , folder/t.txt
alias grmcfo="git rm -r --cached" # +folder name
## git clean , deleting all untracked files/changes
alias gclean="git clean -f"
## git reset ,unstage all changes that have been added to stage area ( stage= state after adding and before commit)
alias greset="git reset ."
## resetting to other branch ( *** if dont't give branch ...it'll reset to current branch)
alias grs="git reset " # + branchName // the current branch will be reset to the given branch ***
alias gRs="git reset --hard " # + branchName // hard reset ...if conflicts are there ***
## this we can use it for revert git pull ...usefull if merge conflicts are coming...when we pull
alias grsh="git reset --hard " # + branchName // hard reset ...if conflicts are there
## git reset --hard commitId -> will reset head to particular commit ( revert the code ) ***
## not to add specific files or folders
alias gar="git add -A && git reset --" # + file_name or -r folder_name
## config
alias gcgun="git config --global user.name" # + name
alias gcgue="git config --global user.email" # + email
alias gcls="git config --list"
alias gcun="git config user.name" # + name
alias gcue="git config user.email" # + email
## to open config files--- config 'C' capital c
alias gCg="git config --global -e" # global config files
alias gCs="git config --system -e" # system config files
alias gCl="git config --local -e" # local config files
## to see files
alias ls="ls"
alias lsb="git ls-tree -r" # +branch name
alias lsh="git ls-tree -r head" # list current head(branch)
## to see diff between files
alias gd="git diff" # + br-1:f.txt br-2:f.txt or commit1Id:f.txt commit2Id:f.txt
## SSH Key
alias gssh="ssh-keygen" # generate ssh-key
alias sssh="cat ~/.ssh/*.pub" # show ssh
alias ossh="gedit ~/.ssh/*.pub" # open ssh
alias cssh="xclip -sel clip < ~/.ssh/*.pub" # copy ssh // xclip should be installed
alias vsshgh="ssh -T git@github.com" # verify ssh with git-hub
alias vsshgl="ssh -T git@gitlab.com" # verify ssh with git-lab
: '
ssh files will stored in home folder of the user by default
eg; if user is root
identification file in /root/.ssh/id_rsa.
public key in /root/.ssh/id_rsa.pub.
'
## to terminate another processing bash
alias terminate="rm -f .git/index.lock"
alias term="rm -f .git/index.lock"
## to enable auto-complete
: '
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
this will install scrpt file in root directory
'
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
####################################### npm configurations ####################################
alias ns="npm start"
alias nrd="npm run dev"
alias nrt="npm run test"
alias nrs="npm run serve"
alias nr="npm run" # + any npm cmd
alias rmn="rm -r node_modules" # remove node modules
alias rmna="rm -r ./**/node_modules" # remove node modules
# mkdir -p "${HOME}/.npm-global"
NPM_PACKAGES="${HOME}/.npm-global"
npm config set prefix $NPM_PACKAGES
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"