diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2008-10-23 22:11:16 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2008-10-23 22:11:16 +0200 |
commit | ddb88acf45fca2aad858c594c8639517789a06ee (patch) | |
tree | 915554dec2fbc9233dd05913e9de3b7a224740a6 /etc | |
parent | e11b8be3b52a1646d2b4e83712dee135c5d1c2f4 (diff) |
Added git-hook function
Diffstat (limited to 'etc')
-rw-r--r-- | etc/completions/_git-hook | 26 | ||||
-rw-r--r-- | etc/function | 2 | ||||
-rw-r--r-- | etc/functions/git-hook | 63 |
3 files changed, 90 insertions, 1 deletions
diff --git a/etc/completions/_git-hook b/etc/completions/_git-hook new file mode 100644 index 0000000..b57c7a1 --- /dev/null +++ b/etc/completions/_git-hook @@ -0,0 +1,26 @@ +#compdef git-hook + +typeset hook_dir expl + +if [[ -n $GIT_DIR && -d $GIT_DIR ]] { + hook_dir=$GIT_DIR/hooks +} elif [[ -d hooks ]] { + hook_dir=$PWD/hooks +} elif [[ -d .git/hooks ]] { + hook_dir=$PWD/.git/hooks +} elif [[ $PWD == */hooks ]] { + hook_dir=$PWD +} + +if (( CURRENT == 2 )) { + _wanted ation expl 'action' \ + compadd list enable disable +} elif (( CURRENT == 3 )) { + if [[ ${words[2]} == 'enable' ]] { + _wanted hook expl 'git hook' \ + _path_files -W $hook_dir -g '*(^x)' + } elif [[ ${words[2]} == 'disable' ]] { + _wanted hook expl 'git hook' \ + _path_files -W $hook_dir -g '*(x)' + } +} diff --git a/etc/function b/etc/function index 01d6dfd..a8f4007 100644 --- a/etc/function +++ b/etc/function @@ -7,7 +7,7 @@ autoload catch throw autoload zargs # own functions -autoload check_com chpwd dirinfo extr plonkhost put reload rtab salias +autoload check_com chpwd dirinfo extr git-hook plonkhost put reload rtab salias autoload world-readable xexport xsource youtube-watch colors diff --git a/etc/functions/git-hook b/etc/functions/git-hook new file mode 100644 index 0000000..fb12c4d --- /dev/null +++ b/etc/functions/git-hook @@ -0,0 +1,63 @@ +## vim:ft=zsh +## Small function to help with git hooks +## Written 2008 by Daniel Friesel <derf@derf.homelinux.org> + +autoload fdie +typeset hook_dir action=$1 hook=$2 + +if [[ -n $GIT_DIR && -d $GIT_DIR ]] { + hook_dir=$GIT_DIR/hooks +} elif [[ -d hooks ]] { + hook_dir=$PWD/hooks +} elif [[ -d .git/hooks ]] { + hook_dir=$PWD/.git/hooks +} elif [[ $PWD == */hooks ]] { + hook_dir=$PWD +} else { + fdie 'No git or hook directory found.'; return +} + +function usage { + cat <<- ENDOFHELP + Usage: git-hook enable|disable <hook> + ENDOFHELP +} + +if [[ $#* < 1 ]] { + usage; return +} + +function hook_enable { + if [[ -e $hook_dir/$hook ]] { + if ! [[ -x $hook_dir/$hook ]] { + chmod u+x $hook_dir/$hook + } + } else { + fdie "No such hook: '$hook'"; return + } +} + +function hook_disable { + if [[ -e $hook_dir/$hook ]] { + if [[ -x $hook_dir/$hook ]] { + chmod u-x $hook_dir/$hook + } + } else { + fdie "No such hook: '$hook'"; return + } +} + +function hook_list { + for hook in $hook_dir/*; { + [[ -x $hook ]] && echo -n $green + echo -n ${hook:t} + echo $reset + } +} + +case $action in + enable) shift 2; hook_enable $* ;; + disable) shift 2; hook_disable $* ;; + list) shift; hook_list $* ;; + *) usage ;; +esac |