Last active
April 12, 2020 10:49
-
-
Save zigotica/2454be48c0da4d1abb449ecb9f1a9bd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################################### | |
# PATH | |
##################################################################################### | |
export homebrew="/usr/local/bin:/usr/local/sbin" | |
export PATH="$homebrew:$PATH" | |
export PATH="/usr/local/heroku/bin:$PATH" | |
export PATH="/opt/anaconda2/bin:$PATH" | |
export NVM_DIR="/Users/zgtc/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm | |
##################################################################################### | |
# COLORS & ICONS | |
##################################################################################### | |
: ${os_icon:=''} | |
: ${node_icon:=''} | |
: ${branch_icon:=''} | |
: ${clean_icon:='✔'} | |
: ${merge_icon:=''} | |
: ${ahead_icon:='↑'} | |
: ${behind_icon:='↓'} | |
: ${staged_icon:='✚'} | |
: ${untracked_icon:='✘'} | |
Red="$(tput setaf 1)" | |
Green="$(tput setaf 2)" | |
Yellow="$(tput setaf 3)" | |
Blue="$(tput setaf 4)" | |
White="$(tput setaf 7)" | |
##################################################################################### | |
# PROMPT | |
##################################################################################### | |
dev_jump() { | |
echo "\n ${Yellow}└─" | |
} | |
dev_start() { | |
echo "${Yellow}(" | |
} | |
dev_end() { | |
echo "${Yellow})" | |
} | |
node_v() { | |
if hash node 2>/dev/null; then | |
local v=$(node -v) | |
fi | |
[ "$v" != "" ] && echo -ne "${Green}${node_icon} ${v:1}" | |
} | |
git_dirty() { | |
local repo_status=$(git status 2>&1 | tail -n1) | |
[[ $repo_status != "nothing to commit, working directory clean" ]] && echo " ${Red}*" | |
} | |
git_branch() { | |
_branch="$(git symbolic-ref --short HEAD)" | |
test -n "$_branch" && echo -ne "${Yellow} ${branch_icon}$_branch" | |
} | |
staged() { | |
count="$(git diff --cached --name-only | wc -l)" | |
count=`echo $count | xargs` | |
if [[ $count != "0" ]]; then | |
echo -ne "${Green} ${staged_icon}${count}" | |
else | |
echo "" | |
fi | |
} | |
unstaged() { | |
count="$(git diff --name-status | wc -l)" | |
count=`echo $count | xargs` | |
if [[ $count != "0" ]]; then | |
echo -ne "${Red} ?${count}" | |
else | |
echo "" | |
fi | |
} | |
untracked() { | |
count="$(git ls-files --others --exclude-standard | wc -l)"`echo $count | sed 's/ *$//g'` | |
count=`echo $count | xargs` | |
if [[ $count != "0" ]]; then | |
echo -ne "${Red} ${untracked_icon}${count}" | |
else | |
echo "" | |
fi | |
} | |
behindahead() { | |
# current branch name | |
br="$(git rev-parse --abbrev-ref HEAD)" | |
if [[ $br != "HEAD" ]]; then | |
# check if remote 'origin' exists | |
# yes, for simplicity we assume our remote is 'origin' | |
r="$(git remote get-url origin 2>&1 | tail -n1)" | |
if [[ $r != "fatal: No such remote 'origin'" ]]; then | |
# check if remote branch exists | |
ub="$(git ls-remote --heads ${r} ${br} 2>&1 | sed -n 2p)" | |
if [[ $ub != 0 ]] && [[ $ub != "fatal: Could not read from remote repository." ]]; then | |
#echo "we have upstream branch in remote origin" | |
upstream="origin/${br}" | |
bh=`git rev-list ${br}..${upstream} --count `; | |
bh=`echo $bh | xargs` | |
ah=`git rev-list ${upstream}..${br} --count `; | |
ah=`echo $ah | xargs` | |
if [[ $bh != "0" ]] || [[ $ah != "0" ]]; then | |
echo -ne "${Red} ${merge_icon}" | |
fi | |
if [[ $bh != "0" ]]; then | |
echo -ne "${Red} ${behind_icon}${bh}" | |
fi | |
if [[ $ah != "0" ]]; then | |
echo -ne "${Green} ${ahead_icon}${ah}" | |
fi | |
if [[ $bh == "0" ]] && [[ $ah == "0" ]]; then | |
echo -ne "${Green} ${clean_icon}" | |
fi | |
fi | |
fi | |
fi | |
} | |
real_time_prompt() { | |
PS1="\[\033]0;\W\007\]"; | |
PS1+="\[${os_icon}\] \u \[${Blue}\]\w " | |
# modify prompt if we are in a git repo folder and have branches to show stats about | |
if `git status &> /dev/null`; then | |
PS1+="$(dev_jump)\[${Yellow}\]$(dev_start)" | |
PS1+="$(node_v)" | |
PS1+="$(git_branch)$(git_dirty)$(staged)$(unstaged)$(untracked)" | |
# branches count > 0 (maybe we just init'ed git repo) | |
bc="$(git branch --list | wc -l | xargs)" | |
if [[ $bc != "0" ]]; then | |
PS1+="$(behindahead)" | |
fi | |
PS1+="$(dev_end)" | |
fi | |
PS1+="\[${White}\]$ " | |
export PS1 | |
} | |
PROMPT_COMMAND='real_time_prompt' | |
##################################################################################### | |
# BASH GIT COMPLETION | |
##################################################################################### | |
gitcompletionpath="/usr/local/Cellar/git/2.7.4/etc/bash_completion.d/git-completion.bash" | |
[[ -s $gitcompletionpath ]] && source $gitcompletionpath | |
##################################################################################### | |
# SHORTCUTS | |
##################################################################################### | |
# paths | |
alias ..='cd ..' | |
alias ...='cd ../..' | |
alias projectes='cd ~/Documents/projectes/' | |
alias profile='s ~/.bash_profile' | |
alias reload="source ~/.bash_profile" | |
alias fuck='sudo $(history -p \!\!)' # add sudo to last command | |
# quick server from folder | |
alias zerve='python -m SimpleHTTPServer 7777' | |
# console | |
alias ls="exa -l -h -g -a" | |
alias lst="exa -l -h -g -a -T -L=2" | |
# youtube downloader, ffmpeg, ... | |
alias ytd="youtube-dl -f 'bestvideo+bestaudio/best/best' --merge-output-format mkv " | |
alias trims='function cut(){ ffmpeg -ss $1 -i "$2" -c copy "$3"; };cut' | |
alias trime='function cut(){ ffmpeg -ss 0 -t $1 -i "$2" -c copy "$3"; };cut' | |
alias host="sudo vi /etc/hosts" | |
# editor | |
export EDITOR="code -w" | |
alias s="code ." | |
#weinre WEb INspector REmote | |
alias weinreall="weinre -boundHost -all-" | |
# Install npm plugins from package.json and save to devDependencies | |
alias npmdev="npm install --save-dev" | |
##################################################################################### | |
# Git | |
##################################################################################### | |
alias gs="git status" | |
alias gl="git log --pretty=format:'%Cgreen%h%Creset -%Creset %s%C(yellow)%d %Cblue(%aN, %cr)%Creset' --abbrev-commit --date=relative --first-parent" | |
alias glg="git log --graph --pretty=format:'%Cgreen%h%Creset -%Creset %s%C(yellow)%d %Cblue(%aN, %cr)%Creset' --abbrev-commit --date=relative" | |
alias gall="git add ." | |
alias gback="git reset --soft HEAD~1 && git reset HEAD ." | |
alias grall="git clean -df ." # removes all untracked files | |
alias gp="git pull" | |
alias gam="git commit -am" | |
alias gpom="git push origin master" | |
alias gc="git checkout" | |
alias gcd="git checkout develop" | |
alias gb="git branch --list -a" | |
alias gg="git log --oneline --abbrev-commit --branches=* --graph --decorate --color" | |
alias gatpc="git branch --merged | grep -Gv '*' | xargs git branch -d" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment