Skip to content

Instantly share code, notes, and snippets.

@csomh
Last active August 30, 2019 13:27
Show Gist options
  • Save csomh/3d27bc71343442366e557d0147b15023 to your computer and use it in GitHub Desktop.
Save csomh/3d27bc71343442366e557d0147b15023 to your computer and use it in GitHub Desktop.
# User specific aliases and functions
alias gl='git log --pretty=format:"%C(auto)%h %s %C(#555555)/ %aN @ %ar%C(auto)%w(0,0,8)%+D" -10'
alias gfl='git log --pretty=format:"%C(auto)%h %s %C(#555555)/ %aN @ %ar%C(auto)%w(0,0,8)%+D"'
alias gll='git log'
alias gs='git status -s -b'
alias gb='git branch'
alias gd='git diff --patience'
alias gg='git grep'
alias gcl="git clean -e '*sublime*' -xd"
alias gitroot='git rev-parse --show-toplevel'
alias g='git'
# make tab completion work for the commands aliased above
if [ -f /usr/share/bash-completion/completions/git ]; then
source /usr/share/bash-completion/completions/git
__git_complete gl _git_log
__git_complete gfl _git_log
__git_complete gll _git_log
__git_complete gb _git_branch
__git_complete gd _git_diff
__git_complete gcl _git_clean
__git_complete g _git
fi
# colors to be used on the prompt
export TERM=screen-256color
WHITE="\[$(tput setaf 252)\]"
BLACK="\[$(tput setaf 234)\]"
LIGHTBLACK="\[$(tput setaf 235)\]"
LIGHTBLACK2="\[$(tput setaf 236)\]"
DARKBLACK="\[$(tput setaf 233)\]"
GREY="\[$(tput setaf 243)\]"
LIGHTGREY="\[$(tput setaf 237)\]"
DARKGREY="\[$(tput setaf 239)\]"
WARMGREY="\[$(tput setaf 59)\]"
PINK="\[$(tput setaf 197)\]"
GREEN="\[$(tput setaf 148)\]"
AQUA="\[$(tput setaf 81)\]"
YELLOW="\[$(tput setaf 186)\]"
ORANGE="\[$(tput setaf 208)\]"
PURPLE="\[$(tput setaf 141)\]"
RED="\[$(tput setaf 196)\]"
DARKRED="\[$(tput setaf 52)\]"
RESET="\[$(tput sgr0)\]"
# save git-prompt.sh from
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
if [ -f $HOME/git-prompt.sh ]; then
source $HOME/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM="verbose name"
GITINFO='$(__git_ps1 "(%s)")'
fi
set_prompt() {
# capture the error code from the last command
local ex=$?
if [[ "$ex" -ne 0 ]]; then
ex="${PINK}[${ex}] "
else
ex=""
fi
# if this is a virtual environment we want it as part of the prompt
if [ -n "$VIRTUAL_ENV" ]; then
venv="${ORANGE}($(basename $VIRTUAL_ENV)) "
else
venv=""
fi
# finally, assemble all the above
export PS1="${venv}${AQUA}\u@\h ${GREEN}\w${GREY} ${GITINFO}\n${ex}${WHITE}\$ "
}
# avoid adding set_prompt multiple times
# See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Controlling-the-Prompt
if [[ $PROMPT_COMMAND != *"set_prompt"* ]]; then
# set_prompt should come first, in order to be able to capture error
# codes
export PROMPT_COMMAND="set_prompt ${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
fi
[core]
editor = vimx
excludesfile = ~/.gitignore
[push]
default = simple
[fetch]
prune = true
[alias]
unstage = reset HEAD --
mr = !sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' -
pr = !sh -c 'git fetch $1 pull/$2/head:pr-$1-$2 && git checkout pr-$1-$2' -
co = checkout
mu = !sh -c 'git merge --ff-only upstream/${1:-master}' -
su = !sh -c 'git co ${1:-master} && git fetch --all && git mu ${1:-master} && git push' -
com = commit -sv
[grep]
lineNumber = true
fallbackToNoIndex = true
*.sublime-project
*.sublime-workspace
*~
.cache/
.eggs/
__pycache__/
*.pyc
.?*swp
.envrc
*,cover
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment