Skip to content

Instantly share code, notes, and snippets.

@lardawge
Last active July 26, 2019 22:44
Show Gist options
  • Save lardawge/6bbf7c095afb97735e65dc31cabb1787 to your computer and use it in GitHub Desktop.
Save lardawge/6bbf7c095afb97735e65dc31cabb1787 to your computer and use it in GitHub Desktop.
Shortcuts and scripts for Git
# Run brew install git bash-completion
# Add bash-completion to your ~/.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion || {
# if not found in /usr/local/etc, try the brew --prefix location
[ -f "$(brew --prefix)/etc/bash_completion.d/git-completion.bash" ] && \
. $(brew --prefix)/etc/bash_completion.d/git-completion.bash
}
DULL=0
BRIGHT=1
FG_BLACK=30
FG_RED=31
FG_GREEN=32
FG_YELLOW=33
FG_BLUE=34
FG_VIOLET=35
FG_CYAN=36
FG_WHITE=37
FG_NULL=00
BG_BLACK=40
BG_RED=41
BG_GREEN=42
BG_YELLOW=43
BG_BLUE=44
BG_VIOLET=45
BG_CYAN=46
BG_WHITE=47
BG_NULL=00
##
# ANSI Escape Commands
##
ESC="\033"
NORMAL="$ESC[m"
RESET="$ESC[${DULL};${FG_WHITE};${BG_NULL}m"
RED="$ESC[${DULL};${FG_RED}m"
GREEN="$ESC[${DULL};${FG_GREEN}m"
YELLOW="$ESC[${DULL};${FG_YELLOW}m"
function minutes_since_last_commit {
now=`date +%s`
last_commit=`git log --pretty=format:'%at' -1`
seconds_since_last_commit=$((now-last_commit))
minutes_since_last_commit=$((seconds_since_last_commit/60))
echo $minutes_since_last_commit
}
grb_git_prompt() {
local g="$(__gitdir)"
if [ -n "$g" ]; then
local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit`
if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
local COLOR=${RED}
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then
local COLOR=${YELLOW}
else
local COLOR=${GREEN}
fi
local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m${NORMAL}"
local BRANCH_NAME="${RED}%s${NORMAL}"
# The __git_ps1 function inserts the current git branch where %s is
local GIT_PROMPT=`__git_ps1 "(${BRANCH_NAME}|${SINCE_LAST_COMMIT})"`
echo ${GIT_PROMPT}
fi
}
PS1="\[$GREEN\]\u@\h:\[$NORMAL\]\w \$(grb_git_prompt) \n:) "
# This goes into user directory for global usage
[user]
email = [github email]
name = [name]
[alias]
co = checkout
br = branch
ci = commit
st = status
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
[color]
branch = auto
diff = auto
interactive = auto
status = auto
[push]
default = simple
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment