diff --git a/local/bin/git-b b/local/bin/git-b new file mode 100755 index 0000000..ec57e4d --- /dev/null +++ b/local/bin/git-b @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Original by Gary Bernhardt: +# https://github.com/garybernhardt/dotfiles/blob/master/.githelpers +# +# Branch output: +# +# * release/v1.1 (13 days) add pretty_git_branch +# +# The time massaging regexes start with ^[^<]* because that ensures that they +# only operate before the first "<". That "<" will be the beginning of the +# author name, ensuring that we don't destroy anything in the commit message +# that looks like time. + +BRANCH_PREFIX="%(HEAD)" +BRANCH_REF="%(color:red)%(color:bold)%(refname:short)%(color:reset)" +BRANCH_HASH="%(color:yellow)%(objectname:short)%(color:reset)" +BRANCH_DATE="%(color:green)(%(committerdate:relative))%(color:reset)" +BRANCH_AUTHOR="%(color:blue)%(color:bold)<%(authorname)>%(color:reset)" +BRANCH_CONTENTS="%(contents:subject)" + +BRANCH_FORMAT="$BRANCH_PREFIX}$BRANCH_REF}$BRANCH_HASH}$BRANCH_DATE}$BRANCH_AUTHOR}$BRANCH_CONTENTS" + +ANSI_BLACK='\033[30m' +ANSI_BLACK_BOLD='\033[0;30;1m' +ANSI_RED='\033[31m' +ANSI_RED_BOLD='\033[0;31;1m' +ANSI_GREEN='\033[32m' +ANSI_GREEN_BOLD='\033[0;32;1m' +ANSI_YELLOW='\033[33m' +ANSI_YELLOW_BOLD='\033[0;33;1m' +ANSI_BLUE='\033[34m' +ANSI_BLUE_BOLD='\033[0;34;1m' +ANSI_MAGENTA='\033[35m' +ANSI_MAGENTA_BOLD='\033[0;35;1m' +ANSI_CYAN='\033[36m' +ANSI_CYAN_BOLD='\033[0;36;1m' +ANSI_WHITE='\033[37m' +ANSI_WHITE_BOLD='\033[0;37;1m' +ANSI_RESET='\033[0m' + +pretty_git_branch() { + git branch -v --format=${BRANCH_FORMAT} $* | pretty_git_format +} + +pretty_git_format() { + # Replace (2 years ago) with (2 years) + sed -Ee 's/(^[^<]*) ago\)/\1)/' | + # Replace (2 years, 5 months) with (2 years) + sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' | + # Line columns up based on } delimiter + column -s '}' -t | + # Color merge commits specially + sed -Ee "s/(Merge (branch|remote-tracking branch|pull request) .*$)/$(printf $ANSI_RED)\1$(printf $ANSI_RESET)/" | + # Page only if we're asked to. + if [ -n "$GIT_NO_PAGER" ]; then + cat + else + # Page only if needed. + less --quit-if-one-screen --no-init --RAW-CONTROL-CHARS --chop-long-lines + fi +} + +git branch --color -v --format=${BRANCH_FORMAT} --sort=-committerdate $* | pretty_git_format diff --git a/local/bin/git-head b/local/bin/git-head index 360c624..804efff 100755 --- a/local/bin/git-head +++ b/local/bin/git-head @@ -1,4 +1,4 @@ #!/bin/sh -echo "$(git l -1) -$(git show --color -p --pretty="tformat:")" | less -FXRS +git l -1 +git show -p --pretty="tformat:" diff --git a/local/bin/git-ib b/local/bin/git-ib new file mode 100755 index 0000000..5199bab --- /dev/null +++ b/local/bin/git-ib @@ -0,0 +1,32 @@ +#!/bin/sh + +case $1 in + -a) + heads=refs/heads + remotes=refs/remotes + shift + ;; + -r) + remotes=refs/remotes + shift + ;; + *) + heads=refs/heads + ;; +esac + +command=${1:-checkout} +shift + +git for-each-ref \ + --format='%(refname:short) %(color:yellow)(%(committerdate:relative))%(color:reset)' \ + --sort=-committerdate \ + $heads $remotes \ + | fzf \ + --ansi \ + --header "git $command $@" \ + --multi \ + --preview 'git log --patch --color {1}...{1}~5' \ + --reverse \ + | awk '{gsub(/.*\//, ""); print $1}' \ + | xargs git $command $@ diff --git a/local/bin/git-if b/local/bin/git-if new file mode 100755 index 0000000..892e75b --- /dev/null +++ b/local/bin/git-if @@ -0,0 +1,16 @@ +#!/bin/sh + +toplevel=`git rev-parse --show-toplevel` + +command=${1:-add} + +git status --short \ + | fzf \ + --ansi \ + --multi \ + --header "git $command" \ + --preview \ + "echo {} | awk '{print \"$toplevel/\", \$2}' | xargs git diff --color" \ + --reverse \ + | awk "{print \"$toplevel\", \$2}" \ + | xargs git $command diff --git a/local/bin/git-l b/local/bin/git-l index 7aaab17..ba51a8a 100755 --- a/local/bin/git-l +++ b/local/bin/git-l @@ -1,28 +1,63 @@ -#!/bin/sh +#!/bin/bash # # Original by Gary Bernhardt: -# -# https://raw.github.com/garybernhardt/dotfiles/master/.githelpers +# https://github.com/garybernhardt/dotfiles/blob/master/.githelpers # # Log output: # -# 51c333e 2012-07-12 Gary Bernhardt add vim-eunuch +# * 51c333e (12 days) add vim-eunuch +# +# The time massaging regexes start with ^[^<]* because that ensures that they +# only operate before the first "<". That "<" will be the beginning of the +# author name, ensuring that we don't destroy anything in the commit message +# that looks like time. # # The log format uses } characters between each field, and `column` is later # used to split on them. A } in the commit subject or any other field will # break this. -HASH="%C(yellow)%h%Creset" -DATE="%C(green)%ad%Creset" -AUTHOR="%C(bold blue)%an%Creset" -REFS="%C(red)%d%Creset" -SUBJECT="%s" +LOG_HASH="%C(yellow)%h%Creset" +LOG_RELATIVE_TIME="%Cgreen(%ar)%Creset" +LOG_AUTHOR="%C(bold blue)<%an>%Creset" +LOG_REFS="%C(bold red)%d%Creset" +LOG_SUBJECT="%s" + +LOG_FORMAT="$LOG_HASH}$LOG_RELATIVE_TIME}$LOG_AUTHOR}$LOG_REFS $LOG_SUBJECT" -FORMAT="$HASH}$DATE}$AUTHOR}$REFS $SUBJECT" +ANSI_BLACK='\033[30m' +ANSI_BLACK_BOLD='\033[0;30;1m' +ANSI_RED='\033[31m' +ANSI_RED_BOLD='\033[0;31;1m' +ANSI_GREEN='\033[32m' +ANSI_GREEN_BOLD='\033[0;32;1m' +ANSI_YELLOW='\033[33m' +ANSI_YELLOW_BOLD='\033[0;33;1m' +ANSI_BLUE='\033[34m' +ANSI_BLUE_BOLD='\033[0;34;1m' +ANSI_MAGENTA='\033[35m' +ANSI_MAGENTA_BOLD='\033[0;35;1m' +ANSI_CYAN='\033[36m' +ANSI_CYAN_BOLD='\033[0;36;1m' +ANSI_WHITE='\033[37m' +ANSI_WHITE_BOLD='\033[0;37;1m' +ANSI_RESET='\033[0m' -git log --pretty="tformat:${FORMAT}" --date=short $* | +pretty_git_format() { + # Replace (2 years ago) with (2 years) + sed -Ee 's/(^[^<]*) ago\)/\1)/' | + # Replace (2 years, 5 months) with (2 years) + sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' | # Line columns up based on } delimiter column -s '}' -t | - # Page only if we need to - less -FXRS + # Color merge commits specially + sed -Ee "s/(Merge (branch|remote-tracking branch|pull request) .*$)/$(printf $ANSI_RED)\1$(printf $ANSI_RESET)/" | + # Page only if we're asked to. + if [ -n "$GIT_NO_PAGER" ]; then + cat + else + # Page only if needed. + less --quit-if-one-screen --no-init --RAW-CONTROL-CHARS --chop-long-lines + fi +} +git log --color --pretty="tformat:${LOG_FORMAT}" $* | pretty_git_format