Skip to content

Instantly share code, notes, and snippets.

@emgiezet
Last active December 16, 2015 01:19
Show Gist options
  • Select an option

  • Save emgiezet/5353795 to your computer and use it in GitHub Desktop.

Select an option

Save emgiezet/5353795 to your computer and use it in GitHub Desktop.

Revisions

  1. emgiezet revised this gist Jun 3, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion .gitconfig
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    fixme = grep --heading --break -e 'FIX: *' -e 'FIXME: *'
    todo = grep --heading --break -e 'TODO: *'

    standup = !clear && git log --since '1 day ago' --no-merges --pretty=format':%C(yellow)%h %aN%n %B%n' --author $(git config --global --get user.name)
    standup = !"git log --reverse --branches --since='$(if [[ "Mon" == "$(date +%a)" ]]; then echo "last friday"; else echo "yesterday"; fi)' --author=$(git config --get user.email) --format=format:'%C(cyan) %ad %C(yellow)%h %Creset %s %Cgreen%d' --date=local"

    st = status -s

    @@ -40,6 +40,9 @@
    ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
    lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
    ld = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative

    mylds = !"git log --pretty=format:'%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]' --decorate --date=short --author=$(git config --get user.email)"

    lc = "!f() { git ll "$1"^.."$1"; }; f"
    lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
    #list all aliases
  2. emgiezet created this gist Apr 10, 2013.
    125 changes: 125 additions & 0 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,125 @@
    # Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
    # Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
    # A big thanks to \amethyst on Freenode

    if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
    elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
    fi

    if tput setaf 1 &> /dev/null; then
    tput sgr0
    if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
    PREPOSITION=$(tput setaf 7) #WHITE
    USER=$(tput setaf 27) #BLUE
    DEVICE=$(tput setaf 39) #INDIGO
    DIR=$(tput setaf 76) #GREEN
    GIT_STATUS=$(tput setaf 154) #YELLOW
    else
    MAGENTA=$(tput setaf 5)
    ORANGE=$(tput setaf 4)
    DIR=$(tput setaf 2)
    PURPLE=$(tput setaf 1)
    PREPOSITION=$(tput setaf 7)
    fi
    BOLD=$(tput bold)
    NORMAL=$PREPOSITION
    RESET=$(tput sgr0)
    else
    MAGENTA="\033[1;31m"
    ORANGE="\033[1;33m"
    DIR="\033[1;32m"
    PURPLE="\033[1;35m"
    PREPOSITION="\033[1;37m"
    BOLD=""
    RESET="\033[m"
    fi

    get_git_branch () {
    # Grab the branch | ltrim unused rows Remove asterisk
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
    }

    get_origin_diff () {
    # Grab the branches
    BRANCH=$(get_git_branch)
    REMOTE_BRANCH=origin/$BRANCH

    # Look up the result
    git log $REMOTE_BRANCH..$BRANCH -1 --no-color 2> /dev/null | head -n1
    }

    parse_git_behind () {
    # Grab the branch
    BRANCH=$(get_git_branch)

    # TODO: Echo filled in delta when dirty and unsynced
    # If the diff begins with "commit"
    [[ $(get_origin_diff | sed -e "s/^\(commit\).*/\1/") == "commit" ]] ||
    # or it has not been merged into origin
    [[ $(git branch -r --no-color 2> /dev/null | grep origin/$BRANCH 2> /dev/null | tail -n1) == "" ]] &&
    # echo our character
    echo 1
    }

    parse_git_dirty () {
    # nothing to commit, working directory clean
    # nothing to commit (working directory clean)
    [[ $(git status 2> /dev/null | tail -n1 | sed -E "s/nothing to commit..working directory clean.?/1/") != "1" ]] && echo 1
    }
    parse_git_branch () {
    # Grab the branch
    BRANCH=$(get_git_branch)

    # If there are any branches
    if [[ $BRANCH != "" ]]; then
    # Echo the branch
    OUTPUT=$BRANCH

    # Grab the git dirty and git behind
    DIRTY_BRANCH=$(parse_git_dirty)
    BRANCH_BEHIND=$(parse_git_behind)

    # If we are dirty and behind, append
    if [[ $DIRTY_BRANCH == 1 && $BRANCH_BEHIND == 1 ]]; then
    OUTPUT=$OUTPUT""
    # Otherwise, if we are behind, append
    elif [[ $BRANCH_BEHIND == 1 ]]; then
    OUTPUT=$OUTPUT""
    # Otherwise, if we are dirty, append
    elif [[ $DIRTY_BRANCH == 1 ]]; then
    OUTPUT=$OUTPUT"*"
    fi

    # Echo our output
    echo $OUTPUT
    fi
    }

    # ⍺ - alpha ⍺
    # λ - lambda λ λ
    # ∴ - therefore ∴ ∴
    # ± - plus-minus ± ±
    # ∓ - plus-minus-alt ± ∓
    # Δ - Δ Δ
    # ∇ - ∇ ∇
    # ▵ - Smaller delta ▵
    # ▴ - Smaller filled ▴
    # ▲ - Slightly bigger delta △
    # △ - Slightly bigger filled ▲

    parse_on_git () {
    # git branch --no-color 1> /dev/null 2> /dev/null && echo "∓" && return
    echo "$"
    }

    # Convenience method/variable
    BRANCH () {
    echo $(get_git_branch)
    }

    # When on clean git branch, $USER at $COMPUTER in $PWD on $branch
    # When on dirty git branch, $USER at $COMPUTER in $PWD on $branch*
    # When on unsynced git branch, $USER at $COMPUTER in $PWD on $branch▵
    # When on unsynced and dirty git branch, $USER at $COMPUTER in $PWD on $branch▴

    PS1="\[${BOLD}${USER}\]\u \[$PREPOSITION\]at \[$DEVICE\]\h \[$PREPOSITION\]in \[$DIR\]\w\[$PREPOSITION\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$GIT_STATUS\]\$(parse_git_branch)\[$NORMAL\]\n$(parse_on_git) \[$RESET\]"
    109 changes: 109 additions & 0 deletions .gitconfig
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,109 @@
    [user]
    name = emgiezet

    [diff]
    external = git-meld

    # alias {{{
    [alias]
    lg1 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
    lg2 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' --abbrev-commit
    lg = !"git lg1"

    fixme = grep --heading --break -e 'FIX: *' -e 'FIXME: *'
    todo = grep --heading --break -e 'TODO: *'

    standup = !clear && git log --since '1 day ago' --no-merges --pretty=format':%C(yellow)%h %aN%n %B%n' --author $(git config --global --get user.name)

    st = status -s

    cl = clone

    ci = commit
    cm = commit -m
    cma = commit -a -m
    ca = commit --amend
    amend = commit --amend
    caa = commit -a --amend -C HEAD
    filelog = log -u
    fl = log -u

    ai = add --interactive

    co = checkout
    br = branch
    #"!git branch -ra | grep -v done"
    bra = branch -ra
    #list commands
    le = log --oneline --decorate
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
    ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
    lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
    ld = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
    lc = "!f() { git ll "$1"^.."$1"; }; f"
    lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
    #list all aliases
    la = "!git config -l | grep alias | cut -c 7-"
    diff = diff --word-diff
    d = diff --word-diff
    dc = diff --cached
    #list modified files in last commit
    dl = "!git ll -1"
    #diff last commit
    dlc = diff --cached HEAD^
    dr = "!f() { git diff "$1"^.."$1"; }; f"
    diffr = "!f() { git diff "$1"^.."$1"; }; f"
    branch = branch -ra

    #reset commands
    r = reset
    r1 = reset HEAD^
    r2 = reset HEAD^^
    rh = reset --hard
    rh1 = reset HEAD^ --hard
    rh2 = reset HEAD^^ --hard

    #git svn
    svnr = svn rebase
    svnd = svn dcommit
    svnl = svn log --oneline --show-commit

    #stash
    sl = stash list
    sa = stash apply
    ss = stash save

    cp = cherry-pick
    grep = grep -Ii
    gr = grep -Ii
    #grep from root folder
    gra = "!f() { A=$(pwd) && TOPLEVEL=$(git rev-parse --show-toplevel) && cd $TOPLEVEL && git grep --full-name -In $1 | xargs -I{} echo $TOPLEVEL/{} && cd $A; }; f"

    #grep on filename
    f = "!git ls-files | grep -i"

    #rename branch tree to done-
    done = "!f() { git branch | grep "$1" | cut -c 3- | grep -v done | xargs -I{} git branch -m {} done-{}; }; f"

    #assume aliases
    assume = update-index --assume-unchanged
    unassume = update-index --no-assume-unchanged
    #show assumed files
    assumed = "!git ls-files -v | grep ^h | cut -c 3-"
    #unassume all the assumed files
    unassumeall = "!git assumed | xargs git update-index --no-assume-unchanged"
    assumeall = "!git st -s | awk {'print $2'} | xargs git assume"

    lasttag = describe --tags --abbrev=0
    lt = describe --tags --abbrev=0

    #merges
    ours = "!f() { git co --ours $@ && git add $@; }; f"
    theirs = "!f() { git co --theirs $@ && git add $@; }; f"
    # }}}
    edit-conflicts = "!f() { git status -s | grep ^UU | awk '{print $2}' ; }; vim `f`"

    [branch]
    autosetupmerge = true
    [help]
    autocorrect = 1