summaryrefslogtreecommitdiffstats
path: root/Completion/Unix/Command
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-07-05 19:24:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-07-05 19:24:49 +0000
commit0cc033db7cddafebab6ec99e6aee464f816de393 (patch)
tree4be490f0b854c39e7457f368bc01815d3a3d7c84 /Completion/Unix/Command
parent27087: change return codes from failed "." (diff)
downloadzsh-0cc033db7cddafebab6ec99e6aee464f816de393.tar
zsh-0cc033db7cddafebab6ec99e6aee464f816de393.tar.gz
zsh-0cc033db7cddafebab6ec99e6aee464f816de393.tar.bz2
zsh-0cc033db7cddafebab6ec99e6aee464f816de393.tar.lz
zsh-0cc033db7cddafebab6ec99e6aee464f816de393.tar.xz
zsh-0cc033db7cddafebab6ec99e6aee464f816de393.tar.zst
zsh-0cc033db7cddafebab6ec99e6aee464f816de393.zip
Brendan Cully: 27088: new Mercurial completion
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r--Completion/Unix/Command/.distfiles1
-rw-r--r--Completion/Unix/Command/_hg946
2 files changed, 947 insertions, 0 deletions
diff --git a/Completion/Unix/Command/.distfiles b/Completion/Unix/Command/.distfiles
index 0a17eed4b..2eb26662e 100644
--- a/Completion/Unix/Command/.distfiles
+++ b/Completion/Unix/Command/.distfiles
@@ -83,6 +83,7 @@ _growisofs
_gs
_guilt
_gzip
+_hg
_iconv
_id
_ifconfig
diff --git a/Completion/Unix/Command/_hg b/Completion/Unix/Command/_hg
new file mode 100644
index 000000000..ef124ef6e
--- /dev/null
+++ b/Completion/Unix/Command/_hg
@@ -0,0 +1,946 @@
+#compdef hg
+
+# Zsh completion script for mercurial. Rename this file to _hg and copy
+# it into your zsh function path (/usr/share/zsh/site-functions for
+# instance)
+#
+# If you do not want to install it globally, you can copy it somewhere
+# else and add that directory to $fpath. This must be done before
+# compinit is called. If the file is copied to ~/.zsh.d, your ~/.zshrc
+# file could look like this:
+#
+# fpath=("$HOME/.zsh.d" $fpath)
+# autoload -U compinit
+# compinit
+#
+# Copyright (C) 2005, 2006 Steve Borho <steve@borho.org>
+# Copyright (C) 2006-9 Brendan Cully <brendan@kublai.com>
+#
+# Permission is hereby granted, without written agreement and without
+# licence or royalty fees, to use, copy, modify, and distribute this
+# software and to distribute modified versions of this software for any
+# purpose, provided that the above copyright notice and the following
+# two paragraphs appear in all copies of this software.
+#
+# In no event shall the authors be liable to any party for direct,
+# indirect, special, incidental, or consequential damages arising out of
+# the use of this software and its documentation, even if the authors
+# have been advised of the possibility of such damage.
+#
+# The authors specifically disclaim any warranties, including, but not
+# limited to, the implied warranties of merchantability and fitness for
+# a particular purpose. The software provided hereunder is on an "as
+# is" basis, and the authors have no obligation to provide maintenance,
+# support, updates, enhancements, or modifications.
+
+emulate -LR zsh
+setopt extendedglob
+
+local curcontext="$curcontext" state line
+typeset -A _hg_cmd_globals
+
+_hg() {
+ local cmd _hg_root
+ integer i=2
+ _hg_cmd_globals=()
+
+ while (( i < $#words ))
+ do
+ case "$words[$i]" in
+ -R|--repository)
+ eval _hg_root="$words[$i+1]"
+ _hg_cmd_globals+=("$words[$i]" "$_hg_root")
+ (( i += 2 ))
+ continue
+ ;;
+ -R*)
+ _hg_cmd_globals+="$words[$i]"
+ eval _hg_root="${words[$i]#-R}"
+ (( i++ ))
+ continue
+ ;;
+ --cwd|--config)
+ # pass along arguments to hg completer
+ _hg_cmd_globals+=("$words[$i]" "$words[$i+1]")
+ (( i += 2 ))
+ continue
+ ;;
+ -*)
+ # skip option
+ (( i++ ))
+ continue
+ ;;
+ esac
+ if [[ -z "$cmd" ]]
+ then
+ cmd="$words[$i]"
+ words[$i]=()
+ (( CURRENT-- ))
+ fi
+ (( i++ ))
+ done
+
+ if [[ -z "$cmd" ]]
+ then
+ _arguments -s -w : $_hg_global_opts \
+ ':mercurial command:_hg_commands'
+ return
+ fi
+
+ # resolve abbreviations and aliases
+ if ! (( $+functions[_hg_cmd_${cmd}] ))
+ then
+ local cmdexp
+ (( $#_hg_cmd_list )) || _hg_get_commands
+
+ cmdexp=$_hg_cmd_list[(r)${cmd}*]
+ if [[ $cmdexp == $_hg_cmd_list[(R)${cmd}*] ]]
+ then
+ # might be nice to rewrite the command line with the expansion
+ cmd="$cmdexp"
+ fi
+ if [[ -n $_hg_alias_list[$cmd] ]]
+ then
+ cmd=$_hg_alias_list[$cmd]
+ fi
+ fi
+
+ curcontext="${curcontext%:*:*}:hg-${cmd}:"
+
+ zstyle -s ":completion:$curcontext:" cache-policy update_policy
+
+ if [[ -z "$update_policy" ]]
+ then
+ zstyle ":completion:$curcontext:" cache-policy _hg_cache_policy
+ fi
+
+ if (( $+functions[_hg_cmd_${cmd}] ))
+ then
+ _hg_cmd_${cmd}
+ else
+ # complete unknown commands normally
+ _arguments -s -w : $_hg_global_opts \
+ '*:files:_hg_files'
+ fi
+}
+
+_hg_cache_policy() {
+ typeset -a old
+
+ # cache for a minute
+ old=( "$1"(mm+10) )
+ (( $#old )) && return 0
+
+ return 1
+}
+
+_hg_get_commands() {
+ typeset -ga _hg_cmd_list
+ typeset -gA _hg_alias_list
+ local hline cmd cmdalias
+
+ _call_program hg hg debugcomplete -v | while read -A hline
+ do
+ cmd=$hline[1]
+ _hg_cmd_list+=($cmd)
+
+ for cmdalias in $hline[2,-1]
+ do
+ _hg_cmd_list+=($cmdalias)
+ _hg_alias_list+=($cmdalias $cmd)
+ done
+ done
+}
+
+_hg_commands() {
+ (( $#_hg_cmd_list )) || _hg_get_commands
+ _describe -t commands 'mercurial command' _hg_cmd_list
+}
+
+_hg_revrange() {
+ compset -P 1 '*:'
+ _hg_tags "$@"
+}
+
+_hg_tags() {
+ typeset -a tags
+ local tag rev
+
+ _hg_cmd tags | while read tag
+ do
+ tags+=(${tag/ # [0-9]#:*})
+ done
+ (( $#tags )) && _describe -t tags 'tags' tags
+}
+
+# likely merge candidates
+_hg_mergerevs() {
+ typeset -a heads
+ local myrev
+
+ heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"})
+ # exclude own revision
+ myrev=$(_hg_cmd log -r . --template '{rev}\\n')
+ heads=(${heads:#$myrev})
+
+ (( $#heads )) && _describe -t heads 'heads' heads
+}
+
+_hg_files() {
+ if [[ -n "$_hg_root" ]]
+ then
+ [[ -d "$_hg_root/.hg" ]] || return
+ case "$_hg_root" in
+ /*)
+ _files -W $_hg_root
+ ;;
+ *)
+ _files -W $PWD/$_hg_root
+ ;;
+ esac
+ else
+ _files
+ fi
+}
+
+_hg_status() {
+ [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
+ status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"})
+}
+
+_hg_unknown() {
+ typeset -a status_files
+ _hg_status u
+ _wanted files expl 'unknown files' _multi_parts / status_files
+}
+
+_hg_missing() {
+ typeset -a status_files
+ _hg_status d
+ _wanted files expl 'missing files' _multi_parts / status_files
+}
+
+_hg_modified() {
+ typeset -a status_files
+ _hg_status m
+ _wanted files expl 'modified files' _multi_parts / status_files
+}
+
+_hg_resolve() {
+ local rstate rpath
+
+ [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
+
+ _hg_cmd resolve -l ./$PREFIX | while read rstate rpath
+ do
+ [[ $rstate == 'R' ]] && resolved_files+=($rpath)
+ [[ $rstate == 'U' ]] && unresolved_files+=($rpath)
+ done
+}
+
+_hg_resolved() {
+ typeset -a resolved_files unresolved_files
+ _hg_resolve
+ _wanted files expl 'resolved files' _multi_parts / resolved_files
+}
+
+_hg_unresolved() {
+ typeset -a resolved_files unresolved_files
+ _hg_resolve
+ _wanted files expl 'unresolved files' _multi_parts / unresolved_files
+}
+
+_hg_config() {
+ typeset -a items
+ items=(${${(%f)"$(_call_program hg hg showconfig)"}%%\=*})
+ (( $#items )) && _describe -t config 'config item' items
+}
+
+_hg_addremove() {
+ _alternative 'files:unknown files:_hg_unknown' \
+ 'files:missing files:_hg_missing'
+}
+
+_hg_ssh_urls() {
+ if [[ -prefix */ ]]
+ then
+ if zstyle -T ":completion:${curcontext}:files" remote-access
+ then
+ local host=${PREFIX%%/*}
+ typeset -a remdirs
+ compset -p $(( $#host + 1 ))
+ local rempath=${(M)PREFIX##*/}
+ local cacheid="hg:${host}-${rempath//\//_}"
+ cacheid=${cacheid%[-_]}
+ compset -P '*/'
+ if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
+ then
+ remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}")"}##*/}%/})
+ _store_cache "$cacheid" remdirs
+ fi
+ _describe -t directories 'remote directory' remdirs -S/
+ else
+ _message 'remote directory'
+ fi
+ else
+ if compset -P '*@'
+ then
+ _hosts -S/
+ else
+ _alternative 'hosts:remote host name:_hosts -S/' \
+ 'users:user:_users -S@'
+ fi
+ fi
+}
+
+_hg_urls() {
+ if compset -P bundle://
+ then
+ _files
+ elif compset -P ssh://
+ then
+ _hg_ssh_urls
+ elif [[ -prefix *: ]]
+ then
+ _urls
+ else
+ local expl
+ compset -S '[^:]*'
+ _wanted url-schemas expl 'URL schema' compadd -S '' - \
+ http:// https:// ssh:// bundle://
+ fi
+}
+
+_hg_paths() {
+ typeset -a paths pnames
+ _hg_cmd paths | while read -A pnames
+ do
+ paths+=($pnames[1])
+ done
+ (( $#paths )) && _describe -t path-aliases 'repository alias' paths
+}
+
+_hg_remote() {
+ _alternative 'path-aliases:repository alias:_hg_paths' \
+ 'directories:directory:_files -/' \
+ 'urls:URL:_hg_urls'
+}
+
+_hg_clone_dest() {
+ _alternative 'directories:directory:_files -/' \
+ 'urls:URL:_hg_urls'
+}
+
+# Common options
+_hg_global_opts=(
+ '(--repository -R)'{-R+,--repository}'[repository root directory]:repository:_files -/'
+ '--cwd[change working directory]:new working directory:_files -/'
+ '(--noninteractive -y)'{-y,--noninteractive}'[do not prompt, assume yes for any required answers]'
+ '(--verbose -v)'{-v,--verbose}'[enable additional output]'
+ '*--config[set/override config option]:defined config items:_hg_config'
+ '(--quiet -q)'{-q,--quiet}'[suppress output]'
+ '(--help -h)'{-h,--help}'[display help and exit]'
+ '--debug[debug mode]'
+ '--debugger[start debugger]'
+ '--encoding[set the charset encoding (default: UTF8)]'
+ '--encodingmode[set the charset encoding mode (default: strict)]'
+ '--lsprof[print improved command execution profile]'
+ '--traceback[print traceback on exception]'
+ '--time[time how long the command takes]'
+ '--profile[profile]'
+ '--version[output version information and exit]'
+)
+
+_hg_pat_opts=(
+ '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
+ '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
+
+_hg_diff_opts=(
+ '(--text -a)'{-a,--text}'[treat all files as text]'
+ '(--git -g)'{-g,--git}'[use git extended diff format]'
+ "--nodates[don't include dates in diff headers]")
+
+_hg_dryrun_opts=(
+ '(--dry-run -n)'{-n,--dry-run}'[do not perform actions, just print output]')
+
+_hg_style_opts=(
+ '--style[display using template map file]:'
+ '--template[display with template]:')
+
+_hg_commit_opts=(
+ '(-m --message -l --logfile --edit -e)'{-e,--edit}'[edit commit message]'
+ '(-e --edit -l --logfile --message -m)'{-m+,--message}'[use <text> as commit message]:message:'
+ '(-e --edit -m --message --logfile -l)'{-l+,--logfile}'[read the commit message from <file>]:log file:_files')
+
+_hg_remote_opts=(