diff --git a/modules/utility/functions/diff b/modules/utility/functions/diff new file mode 100644 index 0000000..54ed5a8 --- /dev/null +++ b/modules/utility/functions/diff @@ -0,0 +1,23 @@ +# +# Highlights diff output. +# +# Authors: +# Sorin Ionescu +# + +if zstyle -t ':omz:module:utility:diff' color; then + function diff { + if (( $+commands[colordiff] )); then + "$commands[diff]" --unified "$@" | colordiff --difftype diffu + elif (( $+commands[git] )); then + git --no-pager diff --color=auto --no-ext-diff --no-index "$@" + else + "$commands[diff]" --unified "$@" + fi + } +else + unfunction diff +fi + +diff --unified "$@" + diff --git a/modules/utility/functions/make b/modules/utility/functions/make new file mode 100644 index 0000000..4109fc1 --- /dev/null +++ b/modules/utility/functions/make @@ -0,0 +1,21 @@ +# +# Highlights make output. +# +# Authors: +# Sorin Ionescu +# + +if zstyle -t ':omz:module:utility:make' color; then + function make { + if (( $+commands[colormake] )); then + colormake "$@" + else + "$commands[make]" "$@" + fi + } +else + unfunction make +fi + +make "$@" + diff --git a/modules/utility/functions/wdiff b/modules/utility/functions/wdiff new file mode 100644 index 0000000..9014967 --- /dev/null +++ b/modules/utility/functions/wdiff @@ -0,0 +1,30 @@ +# +# Highlights wdiff output. +# +# Authors: +# Sorin Ionescu +# + +if zstyle -t ':omz:module:utility:wdiff' color; then + function wdiff { + if (( $+commands[wdiff] )); then + "$commands[wdiff]" \ + --avoid-wraps \ + --start-delete="$(print -n $FG[red])" \ + --end-delete="$(print -n $FG[none])" \ + --start-insert="$(print -n $FG[green])" \ + --end-insert="$(print -n $FG[none])" \ + "$@" \ + | sed 's/^\(@@\( [+-][[:digit:]]*,[[:digit:]]*\)\{2\} @@\)$/;5;6m\10m/g' + elif (( $+commands[git] )); then + git --no-pager diff --color=auto --no-ext-diff --no-index --color-words "$@" + else + print "zsh: command not found: $0" >&2 + fi + } +else + unfunction wdiff +fi + +wdiff "$@" + diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index 0c4bf96..abd1586 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -107,47 +107,6 @@ else alias topc='top -o cpu' fi -# Diff -if zstyle -t ':omz:module:utility:diff' color; then - function diff { - if (( $+commands[colordiff] )); then - "$commands[diff]" --unified "$@" | colordiff --difftype diffu - elif (( $+commands[git] )); then - git --no-pager diff --color=auto --no-ext-diff --no-index "$@" - else - "$commands[diff]" --unified "$@" - fi - } - - function wdiff { - if (( $+commands[wdiff] )); then - "$commands[wdiff]" \ - --avoid-wraps \ - --start-delete="$(print -n $FG[red])" \ - --end-delete="$(print -n $FG[none])" \ - --start-insert="$(print -n $FG[green])" \ - --end-insert="$(print -n $FG[none])" \ - "$@" \ - | sed 's/^\(@@\( [+-][[:digit:]]*,[[:digit:]]*\)\{2\} @@\)$/;5;6m\10m/g' - elif (( $+commands[git] )); then - git --no-pager diff --color=auto --no-ext-diff --no-index --color-words "$@" - else - print "zsh: command not found: $0" >&2 - fi - } -fi - -# Make -if zstyle -t ':omz:module:utility:make' color; then - function make { - if (( $+commands[colormake] )); then - colormake "$@" - else - "$commands[make]" "$@" - fi - } -fi - # Miscellaneous if (( $+commands[ack] )) alias afind='nocorrect ack' if (( $+commands[ebuild] )) alias ebuild='nocorrect ebuild'