Skip to content

Instantly share code, notes, and snippets.

@CDanU
Created June 19, 2018 07:08
Show Gist options
  • Save CDanU/884bfa8a065945c56cfe42fe0214a56b to your computer and use it in GitHub Desktop.
Save CDanU/884bfa8a065945c56cfe42fe0214a56b to your computer and use it in GitHub Desktop.
[user]
email =
name =
logallrefupdates = true
[color]
ui = auto
status = auto
branch = auto
interactive = auto
diff = auto
[color "diff-highlight"]
oldNormal = "#DC322F"
newNormal = "#859900"
oldHighlight = "white #AA0000"
newHighlight = "white #006600"
[log]
decorate = full
[alias]
amend = commit --amend --no-edit
amendd = commit --amend
unstage = reset HEAD --
gab = "! for BRANCH in $(git branch -a | grep remotes | grep -v HEAD | grep -v master); do git branch --track ${BRANCH#remotes/origin/} ${BRANCH}; done"
bls = "!sh .gitconfig_print_branch_with_description.sh"
rmc = rm --cached -r
plr = pull --rebase
cp = cherry-pick
rbi = rebase -i
cma = "! GIT_COMMITTER_DATE=\"`./.fake_timestamp.py`\" git commit --date=\"`./.fake_timestamp.py`\" "
sls = stash list
st = status -sb
cl = clone
ci = commit -v
fix-commit = commit --fixup
fixup = commit --fixup HEAD
br = branch
df = diff
diffword = diff --word-diff
dc = diff --cached
diff-commit = diff-tree -p
sm = submodule
cpc = cherry-pick --continue
cps = cherry-pick --skip
cpa = cherry-pick --abort
dt = difftool
rbm = rebase master
rbc = rebase --continue
rbs = rebase --skip
rba = rebase --abort
mt = mergetool
a = add -p
co = checkout
cob = checkout -b
cop = checkout -p
com = checkout master
rh = reset HEAD
stash-unadded = stash -k
sp = stash pop
clean-remote-branches = remote prune origin
clean-merged-branches = !/bin/sh -c 'git branch --merged | grep -v \\* | xargs -n 1 git branch -d' -
; Log
lg = log -p
lol = log --graph --decorate --pretty=format:'%Cred%h%Creset [%C(blue)%an%Creset %C(yellow)%ar%Creset]%C(red bold)%d%Creset %s' --abbrev-commit
lola = log --graph --decorate --pretty=format:'%Cred%h%Creset [%C(blue)%an%Creset %C(yellow)%ar%Creset]%C(red bold)%d%Creset %s' --abbrev-commit --all
; List
ls = ls-files
ign = ls-files -o -i --exclude-standard
undo = reset HEAD~1 --mixed
last = log -1 HEAD
remotes = remote -v
branches = branch -a
tags = tag -l
; source: http://haacked.com/archive/2014/07/28/github-flow-aliases/
ec = config --global -e
up = !git pull --rebase --prune $@ && git submodule update --init --recursive
save = !git add -A && git commit -m "SAVEPOINT"
cleanup = !git commit -m "cleanup"
wip = !git add -u && git commit -m "WIP"
wipe = !git add -A && git commit -qm "WIPE SAVEPOINT" && git reset HEAD~1 --hard
[merge]
ff = no
summary = true
verbosity = 1
tool = kdiff3
[core]
autocrlf = false
editor = "kate -b"
[branch]
autosetupmerge = true
autosetuprebase = always
[rerere]
enabled = false
[mergetool]
prompt = false
[difftool]
prompt = false
[diff]
; Git diff will use (i)ndex, (w)ork tree, (c)ommit and (o)bject
; instead of a/b/c/d as prefixes for patches
mnemonicprefix = true
algorithm = patience
[diff "odf"]
textconv=odt2txt
[push]
default = tracking
[help]
autocorrect = 0
[gc]
auto=1
[rebase]
autostash = true
autosquash = true
[apply]
whitespace = nowarn
[mergetool "kdiff3NoAuto"]
cmd = kdiff3 --L1 \"$MERGED (Base)\" --L2 \"$MERGED (Local)\" --L3 \"$MERGED (Remote)\" -o \"$MERGED\" \"$BASE\" \"$LOCAL\" \"$REMOTE\"
@CDanU
Copy link
Author

CDanU commented Jun 19, 2018

trim() {
    local var="$*"
    # remove leading whitespace characters
    var="${var#"${var%%[![:space:]]*}"}"
    # remove trailing whitespace characters
    var="${var%"${var##*[![:space:]]}"}"   
    echo -n "$var"
}

function print_branch_with_description()
{
    C_Off="\033[0m"
    C_Cyan="\033[0;36m" # Cyan
    C_Green="\033[0;32m" # Green

    branches=$(git for-each-ref --format='%(refname)' refs/heads/ | sed 's|refs/heads/||')
    for branch in $branches; do
        desc=$(git config branch.$branch.description)
        xtra=0

        o_branch=$branch 
        if [ $branch == $(git rev-parse --abbrev-ref HEAD) ]; then
            o_branch="* ${C_Green}$branch${C_Off}"
            xtra=`expr ${#C_Green} + 1` # green color code len + 1
        else
            o_branch="  $branch"
        fi

        maxlen=`expr 80 + $xtra` # increase cut pos if color codes are used

        #printf -v points '%*s' $maxlen; points="${points// /=}" # save '.' maxlen times into points
        ## alternative head -c $maxlen /dev/zero | tr '\0' '='

        commit_count=`git rev-list --count $branch`

        echo -en "$(printf "% 5d\n" $commit_count) $o_branch $(printf '.%.0s' {1..80})" | head -c $maxlen
        echo -e " ${C_Cyan}$desc${C_Off}"
    done
}
print_branch_with_description

@CDanU
Copy link
Author

CDanU commented Jun 19, 2018

#!/usr/bin/python
from sys import exit
from subprocess import check_output, CalledProcessError
from dateutil.parser import parse as date_parse
from datetime import date, timedelta, datetime


if __name__ == "__main__":
    init_datetime = datetime.now()
    edit_datetime = init_datetime + timedelta(minutes=-init_datetime.minute + 59,
                                              seconds=-init_datetime.second)

    if edit_datetime.hour < 12:
        edit_datetime = edit_datetime \
                        + timedelta(hours=(-edit_datetime.hour - 1))
    else:
        edit_datetime = edit_datetime \
                        + timedelta(hours=(-edit_datetime.hour + 12))

    # try to get last commit timestamp to increment the seconds by one if
    # commits are close to each other, if this fails seconds remains 0
    try:
        last_commit_t = check_output(["git", "show", "-s", "--format=%aI", "HEAD"])
        # https://stackoverflow.com/questions/127803#answer-30696682
        ct = date_parse(last_commit_t)

        if ct.day == edit_datetime.day and \
           ct.hour == edit_datetime.hour and \
           ct.minute == edit_datetime.minute:
            edit_datetime = edit_datetime \
                            + timedelta(seconds=ct.second + 1)
    except CalledProcessError:
        pass

    print(edit_datetime)
    exit(0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment