Skip to content

Instantly share code, notes, and snippets.

@luispabon
Last active April 5, 2019 15:33
Show Gist options
  • Select an option

  • Save luispabon/ca0b41ea2a6c9e14fce5d0c2708f0116 to your computer and use it in GitHub Desktop.

Select an option

Save luispabon/ca0b41ea2a6c9e14fce5d0c2708f0116 to your computer and use it in GitHub Desktop.
##################################################
# Fancy PWD display function
##################################################
# The home directory (HOME) is replaced with a ~
# The last pwdmaxlen characters of the PWD are displayed
# Leading partial directory names are striped off
# /home/me/stuff -> ~/stuff if USER=me
# /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20
##################################################
bash_prompt_command() {
# How many characters of the $PWD should be kept
local pwdmaxlen=25
# Indicate that there has been dir truncation
local trunc_symbol=".."
local dir=${PWD##*/}
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
if [ ${pwdoffset} -gt "0" ]
then
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
fi
}
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
info=`git branch | grep ^* | sed 's/^* //g'`
echo "[$info]"
}
bash_prompt() {
case $TERM in
xterm*|rxvt*)
local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
;;
*)
local TITLEBAR=""
;;
esac
local NONE="\[\033[0m\]" # unsets color to term's fg color
# regular colors
local K="\[\033[0;30m\]" # black
local R="\[\033[0;31m\]" # red
local G="\[\033[0;32m\]" # green
local Y="\[\033[0;33m\]" # yellow
local B="\[\033[0;34m\]" # blue
local M="\[\033[0;35m\]" # magenta
local C="\[\033[0;36m\]" # cyan
local W="\[\033[0;37m\]" # white
# emphasized (bolded) colors
local EMK="\[\033[1;30m\]"
local EMR="\[\033[1;31m\]"
local EMG="\[\033[1;32m\]"
local EMY="\[\033[1;33m\]"
local EMB="\[\033[1;34m\]"
local EMM="\[\033[1;35m\]"
local EMC="\[\033[1;36m\]"
local EMW="\[\033[1;37m\]"
# background colors
local BGK="\[\033[40m\]"
local BGR="\[\033[41m\]"
local BGG="\[\033[42m\]"
local BGY="\[\033[43m\]"
local BGB="\[\033[44m\]"
local BGM="\[\033[45m\]"
local BGC="\[\033[46m\]"
local BGW="\[\033[47m\]"
local UC=$W # user's color
[ $UID -eq "0" ] && UC=$R # root's color
# Git branch parsing
local GITBRANCH=$parse_git_branch
PS1="$TITLEBAR ${EMK}[${UC}\u${EMK}@${UC}localhost ${EMY}\${NEW_PWD}${EMK}]${EMR}\$(parse_git_branch)${EMR}${W}\\$ ${NONE}"
}
PROMPT_COMMAND=bash_prompt_command
EDITOR=nano
bash_prompt
unset bash_prompt
PATH=$PATH:~/bin
export PATH
alias ls='ls --color'
alias l='ls -la --block-size=KB'
alias whereami='env|grep -i realname'
alias clearztm='curl -i -H "Cache-Control: no-cache"'
alias upgrade='sudo apt update; sudo apt dist-upgrade -y; sudo apt autoremove -y; sudo apt clean'
alias ls="ls --color"
alias l="ls -la --block-size=KB"
alias ll="l"
alias df="df -h"
alias watch="watch -n1"
# Git
alias gst="git status"
alias gb="git branch"
alias gl="git lg"
alias gf="git fetch"
alias st="gst"
alias gd="git diff"
alias sd="gd"
alias ga="git add"
alias gc="git commit"
alias gco="git checkout"
alias gs="git rebase -i"
alias gfu="git fetch upstream"
alias gr="git rebase"
alias gru="git rebase upstream/dev"
alias gp="git push"
alias gpo="git push origin"
alias gpu="git push upstream"
alias composer="composer.phar"
export LS_COLORS="no=00:fi=00:di=01;90:ln=01;36:pi=40;33:so=01;90:do=01;90:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=01;35:ow=01;35:*.tar=01;31:*.tgz=01;31:*.taz=01;31:*.zip=01;31:*.gz=01;31:*.bz2=01;31:*.rpm=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.php=01;93:*.sql=01;31:*.tif=01;35:*.tiff=01;35:*.png=01;35"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment