diff options
Diffstat (limited to 'git')
| -rw-r--r-- | git/Makefile | 4 | ||||
| -rwxr-xr-x | git/git-cdiff | 44 | ||||
| -rwxr-xr-x | git/new-c-proj | 8 |
3 files changed, 54 insertions, 2 deletions
diff --git a/git/Makefile b/git/Makefile index 1794675..cca3bd0 100644 --- a/git/Makefile +++ b/git/Makefile @@ -16,9 +16,12 @@ install: test ! -d ~/.config/bash/aliases.d/git ln -sf -- ~/.dotfiles/git/bash-aliases ~/.config/bash/aliases.d/git ../check-installed-shebang ge + ../check-installed-shebang git-cdiff + ../check-in-path diff mkdir -p -- ~/.local/bin ln -sf -- ~/.dotfiles/git/ge ~/.local/bin/ ln -sf -- ~/.dotfiles/git/new-c-proj ~/.local/bin/ + ln -sf -- ~/.dotfiles/git/git-cdiff ~/.local/bin/ uninstall: +! ../check-installed git @@ -28,6 +31,7 @@ uninstall: -rmdir -- ~/.config/bash/aliases.d -unlink -- ~/.local/bin/ge -unlink -- ~/.local/bin/new-c-proj + -unlink -- ~/.local/bin/git-cdiff clean: -rm -f -- .config diff --git a/git/git-cdiff b/git/git-cdiff new file mode 100755 index 0000000..15d91e9 --- /dev/null +++ b/git/git-cdiff @@ -0,0 +1,44 @@ +#!/bin/dash +if test -z "${GIT_CDIFF_CONTEXT}"; then + git difftool -y -x "diff -c --color=always" "$@" +elif printf '%s' "${GIT_CDIFF_CONTEXT}" | grep -q '^-'; then + git difftool -y -x "diff ${GIT_CDIFF_CONTEXT} --color=always" "$@" +else + git difftool -y -x "diff -C${GIT_CDIFF_CONTEXT} --color=always" "$@" +fi | { + # this part of the pipeline is optional, it just makes GNU diff colouring bit nicer + if test "$TERM" = linux; then + sed '/^\(\x1b\[[0-9;]*m\)* /s/\x1b\[[0-9;]*m//g' + else + sed '/^\(\x1b\[[0-9;]*m\)* /s/^/\x1b\[2m/g' + fi +} | { + # this part of the pipeline is optional (and breaks diff format), it adds line number to the margin + if printf '%s' "${GIT_CDIFF_CONTEXT}" | grep -q '^-'; then + exec cat + fi + if test "$TERM" = linux; then + linecolour="35" + else + linecolour="2;35" + fi + lineno=x + while IFS= read -r line; do + if printf '%s\n' "$line" | sed 's/\x1b\[[0-9;]*m//g' | grep -q '^\(\*\*\* \|--- \)[0-9]*,[0-9]* \(\*\*\*\*\|----\)$'; then + lineno="$(printf '%s' "$line" | sed 's/\x1b\[[0-9;]*m//g' | sed 's/^\(\*\*\* \|--- \)\([0-9]*\),.*$/\2/')" + printf '%s\n' "$line" + elif test ! "$lineno" = x && printf '%s\n' "$line" | sed 's/\x1b\[[0-9;]*m//g' | grep -q '^\(!\|+\|-\| \) '; then + printf '\e[%sm%5i \e[m%s\n' "$linecolour" "$lineno" "$line" + lineno=$(( $lineno + 1 )) + else + lineno=x + printf '%s\n' "$line" + fi + done +} | { + if test -t 1; then + less -FRX + else + cat + fi +} diff --git a/git/new-c-proj b/git/new-c-proj index 7676e9f..503bdf9 100755 --- a/git/new-c-proj +++ b/git/new-c-proj @@ -19,7 +19,7 @@ git init . cat > LICENSE <<EOF ISC License -© $(date +%Y) Mattias Andrée <maandree@kth.se> +© $(date +%Y) Mattias Andrée <m@maandree.se> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -39,7 +39,9 @@ cat > .gitignore <<EOF *~ *.o *.a +*.t *.lo +*.to *.su *.so *.so.* @@ -52,7 +54,9 @@ cat > .gitignore <<EOF EOF mkdir -p -- .git/info -printf '%s\n' '_*' '.hidden' '.makeenv' >> .git/info/exclude +printf '%s\n' '_*' '._*' '.hidden' '.makeenv' >> .git/info/exclude + +printf '%s\n' 'MAKEENV_OPTS_OPT_ATTACHED_ARG = j' 'CC = gcc-extreme -std=c99' >> .makeenv if printf '%s\n' "$1" | grep '^lib' >/dev/null 2>/dev/null; then UPPERCASE="$(printf '%s\n' "$1" | tr '[a-z-]' '[A-Z_]')" |
