Mercurial > dotfiles
changeset 229:e5a40e768cf8
zfun: import newer _hg for improved hg completions
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Sat, 09 Oct 2010 15:21:50 -0500 |
parents | 0c8939baa35c |
children | ff600674c701 |
files | .zfun/_hg |
diffstat | 1 files changed, 150 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/.zfun/_hg +++ b/.zfun/_hg @@ -4,13 +4,34 @@ # it into your zsh function path (/usr/share/zsh/site-functions for # instance) # -# Copyright (C) 2005-6 Steve Borho -# Copyright (C) 2006-8 Brendan Cully <brendan@kublai.com> +# 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: # -# This is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 2 of the License, or (at your -# option) any later version. +# fpath=("$HOME/.zsh.d" $fpath) +# autoload -U compinit +# compinit +# +# Copyright (C) 2005, 2006 Steve Borho <steve@borho.org> +# Copyright (C) 2006-10 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 @@ -118,7 +139,7 @@ typeset -A _hg_cmd_globals typeset -gA _hg_alias_list local hline cmd cmdalias - _call_program hg hg debugcomplete -v 2>/dev/null | while read -A hline + _call_program hg hg debugcomplete -v | while read -A hline do cmd=$hline[1] _hg_cmd_list+=($cmd) @@ -145,38 +166,24 @@ typeset -A _hg_cmd_globals typeset -a tags local tag rev - _hg_cmd tags 2> /dev/null | while read tag + _hg_cmd tags | while read tag do - tags+=(${tag/ # [0-9]#:*}) + tags+=(${tag/ # [0-9]#:*}) done (( $#tags )) && _describe -t tags 'tags' tags } -_hg_branches() { - typeset -a branches - local branch +# likely merge candidates +_hg_mergerevs() { + typeset -a heads + local myrev - _hg_cmd branches -a 2> /dev/null | while read branch - do - branches+=(${branch/ # [0-9]#:*}) - done - (( $#branches )) && _describe -t branches 'branches' branches -} + heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"}) + # exclude own revision + myrev=$(_hg_cmd log -r . --template '{rev}\\n') + heads=(${heads:#$myrev}) -_hg_branchtags() { - typeset -a branchtags - local branch tag - - _hg_cmd tags 2> /dev/null | while read tag - do - branchtags+=(${tag/ # [0-9]#:*}) - done - - _hg_cmd branches -a 2> /dev/null | while read branch - do - branchtags+=(${branch/ # [0-9]#:*}) - done - (( $#branchtags )) && _describe -t branchtags 'branchtags' branchtags + (( $#heads )) && _describe -t heads 'heads' heads } _hg_files() { @@ -198,7 +205,7 @@ typeset -A _hg_cmd_globals _hg_status() { [[ -d $PREFIX ]] || PREFIX=$PREFIX:h - status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX 2>/dev/null)"}) + status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"}) } _hg_unknown() { @@ -220,11 +227,11 @@ typeset -A _hg_cmd_globals } _hg_resolve() { - local rstate rpah + local rstate rpath [[ -d $PREFIX ]] || PREFIX=$PREFIX:h - _hg_cmd resolve -l ./$PREFIX 2> /dev/null | while read rstate rpath + _hg_cmd resolve -l ./$PREFIX | while read rstate rpath do [[ $rstate == 'R' ]] && resolved_files+=($rpath) [[ $rstate == 'U' ]] && unresolved_files+=($rpath) @@ -268,7 +275,7 @@ typeset -A _hg_cmd_globals compset -P '*/' if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid" then - remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}" 2> /dev/null)"}##*/}%/}) + 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/ @@ -306,7 +313,7 @@ typeset -A _hg_cmd_globals _hg_paths() { typeset -a paths pnames - _hg_cmd paths 2> /dev/null | while read -A pnames + _hg_cmd paths | while read -A pnames do paths+=($pnames[1]) done @@ -351,7 +358,7 @@ typeset -A _hg_cmd_globals _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]") + "--nodates[omit dates from diff headers]") _hg_dryrun_opts=( '(--dry-run -n)'{-n,--dry-run}'[do not perform actions, just print output]') @@ -370,7 +377,7 @@ typeset -A _hg_cmd_globals '--remotecmd[specify hg command to run on the remote side]:') _hg_cmd() { - _call_program hg hg "$_hg_cmd_globals[@]" "$@" + _call_program hg HGPLAIN=1 hg "$_hg_cmd_globals[@]" "$@" 2> /dev/null } _hg_cmd_add() { @@ -416,6 +423,27 @@ typeset -A _hg_cmd_globals '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt' } +_hg_cmd_bisect() { + _arguments -s -w : $_hg_global_opts \ + '(-)'{-r,--reset}'[reset bisect state]' \ + '(--good -g --bad -b --skip -s --reset -r)'{-g,--good}'[mark changeset good]'::revision:_hg_tags \ + '(--good -g --bad -b --skip -s --reset -r)'{-b,--bad}'[mark changeset bad]'::revision:_hg_tags \ + '(--good -g --bad -b --skip -s --reset -r)'{-s,--skip}'[skip testing changeset]' \ + '(--command -c --noupdate -U)'{-c+,--command}'[use command to check changeset state]':commands:_command_names \ + '(--command -c --noupdate -U)'{-U,--noupdate}'[do not update to target]' +} + +_hg_cmd_branch() { + _arguments -s -w : $_hg_global_opts \ + '(--force -f)'{-f,--force}'[set branch name even if it shadows an existing branch]' \ + '(--clean -C)'{-C,--clean}'[reset branch name to parent branch name]' +} + +_hg_cmd_branches() { + _arguments -s -w : $_hg_global_opts \ + '(--active -a)'{-a,--active}'[show only branches that have unmerge heads]' +} + _hg_cmd_bundle() { _arguments -s -w : $_hg_global_opts $_hg_remote_opts \ '(--force -f)'{-f,--force}'[run even when remote repository is unrelated]' \ @@ -571,10 +599,11 @@ typeset -A _hg_cmd_globals } _hg_cmd_merge() { - _arguments -s -w : $_hg_global_opts \ - '(--force -f)'{-f,--force}'[force a merge with outstanding changes]' \ - '(--rev -r)'{-r,--rev}'[revision to merge]:revision:_hg_branches' \ - ':revision:_hg_branches' + _arguments -s -w : $_hg_global_opts \ + '(--force -f)'{-f,--force}'[force a merge with outstanding changes]' \ + '(--rev -r 1)'{-r,--rev}'[revision to merge]:revision:_hg_mergerevs' \ + '(--preview -P)'{-P,--preview}'[review revisions to merge (no merge is performed)]' \ + ':revision:_hg_mergerevs' } _hg_cmd_outgoing() { @@ -704,6 +733,11 @@ typeset -A _hg_cmd_globals '*:files:_files' } +_hg_cmd_summary() { + _arguments -s -w : $_hg_global_opts \ + '--remote[check for push and pull]' +} + _hg_cmd_tag() { _arguments -s -w : $_hg_global_opts \ '(--local -l)'{-l,--local}'[make the tag local]' \ @@ -728,13 +762,33 @@ typeset -A _hg_cmd_globals _hg_cmd_update() { _arguments -s -w : $_hg_global_opts \ '(--clean -C)'{-C,--clean}'[overwrite locally modified files]' \ - '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_branchtags' \ - ':revision:_hg_branchtags' + '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \ + ':revision:_hg_tags' } -# bisect extension -_hg_cmd_bisect() { - _arguments -s -w : $_hg_global_opts ':evaluation:(help init reset next good bad)' +## extensions ## + +# bookmarks +_hg_bookmarks() { + typeset -a bookmark bookmarks + + _hg_cmd bookmarks | while read -A bookmark + do + if test -z ${bookmark[-1]:#[0-9]*} + then + bookmarks+=($bookmark[-2]) + fi + done + (( $#bookmarks )) && _describe -t bookmarks 'bookmarks' bookmarks +} + +_hg_cmd_bookmarks() { + _arguments -s -w : $_hg_global_opts \ + '(--force -f)'{-f,--force}'[force]' \ + '(--rev -r --delete -d --rename -m)'{-r+,--rev}'[revision]:revision:_hg_tags' \ + '(--rev -r --delete -d --rename -m)'{-d,--delete}'[delete a given bookmark]' \ + '(--rev -r --delete -d --rename -m)'{-m+,--rename}'[rename a given bookmark]:bookmark:_hg_bookmarks' \ + ':bookmark:_hg_bookmarks' } # HGK @@ -747,13 +801,13 @@ typeset -A _hg_cmd_globals # MQ _hg_qseries() { typeset -a patches - patches=(${(f)"$(_hg_cmd qseries 2>/dev/null)"}) + patches=(${(f)"$(_hg_cmd qseries)"}) (( $#patches )) && _describe -t hg-patches 'patches' patches } _hg_qapplied() { typeset -a patches - patches=(${(f)"$(_hg_cmd qapplied 2>/dev/null)"}) + patches=(${(f)"$(_hg_cmd qapplied)"}) if (( $#patches )) then patches+=(qbase qtip) @@ -763,15 +817,27 @@ typeset -A _hg_cmd_globals _hg_qunapplied() { typeset -a patches - patches=(${(f)"$(_hg_cmd qunapplied 2>/dev/null)"}) + patches=(${(f)"$(_hg_cmd qunapplied)"}) (( $#patches )) && _describe -t hg-unapplied-patches 'unapplied patches' patches } +# unapplied, including guarded patches +_hg_qdeletable() { + typeset -a unapplied + unapplied=(${(f)"$(_hg_cmd qseries)"}) + for p in $(_hg_cmd qapplied) + do + unapplied=(${unapplied:#$p}) + done + + (( $#unapplied )) && _describe -t hg-allunapplied-patches 'all unapplied patches' unapplied +} + _hg_qguards() { typeset -a guards local guard compset -P "+|-" - _hg_cmd qselect -s 2>/dev/null | while read guard + _hg_cmd qselect -s | while read guard do guards+=(${guard#(+|-)}) done @@ -789,7 +855,7 @@ typeset -A _hg_cmd_globals _arguments -s -w : $_hg_global_opts \ '(--keep -k)'{-k,--keep}'[keep patch file]' \ '*'{-r+,--rev}'[stop managing a revision]:applied patch:_hg_revrange' \ - '*:unapplied patch:_hg_qunapplied' + '*:unapplied patch:_hg_qdeletable' } _hg_cmd_qdiff() { @@ -860,6 +926,7 @@ typeset -A _hg_cmd_globals '(--merge -m)'{-m+,--merge}'[merge from another queue]:' \ '(--name -n)'{-n+,--name}'[merge queue name]:' \ '(--force -f)'{-f,--force}'[apply if the patch has rejects]' \ + '--move[reorder patch series and apply only the patch]' \ ':patch:_hg_qunapplied' } @@ -906,4 +973,34 @@ typeset -A _hg_cmd_globals ':revision:_hg_tags' } +# Patchbomb +_hg_cmd_email() { + _arguments -s -w : $_hg_global_opts $_hg_remote_opts \ + '(--git -g)'{-g,--git}'[use git extended diff format]' \ + '--plain[omit hg patch header]' \ + '(--outgoing -o)'{-o,--outgoing}'[send changes not found in the target repository]' \ + '(--bundle -b)'{-b,--bundle}'[send changes not in target as a binary bundle]' \ + '--bundlename[name of the bundle attachment file (default: bundle)]:' \ + '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \ + '--force[run even when remote repository is unrelated (with -b/--bundle)]' \ + '*--base[a base changeset to specify instead of a destination (with -b/--bundle)]:revision:_hg_tags' \ + '--intro[send an introduction email for a single patch]' \ + '(--inline -i --attach -a)'{-a,--attach}'[send patches as attachments]' \ + '(--attach -a --inline -i)'{-i,--inline}'[send patches as inline attachments]' \ + '*--bcc[email addresses of blind carbon copy recipients]:email:' \ + '*'{-c+,--cc}'[email addresses of copy recipients]:email:' \ + '(--diffstat -d)'{-d,--diffstat}'[add diffstat output to messages]' \ + '--date[use the given date as the sending date]:date:' \ + '--desc[use the given file as the series description]:files:_files' \ + '(--from -f)'{-f,--from}'[email address of sender]:email:' \ + '(--test -n)'{-n,--test}'[print messages that would be sent]' \ + '(--mbox -m)'{-m,--mbox}'[write messages to mbox file instead of sending them]:file:' \ + '*--reply-to[email addresses replies should be sent to]:email:' \ + '(--subject -s)'{-s,--subject}'[subject of first message (intro or single patch)]:subject:' \ + '--in-reply-to[message identifier to reply to]:msgid:' \ + '*--flag[flags to add in subject prefixes]:flag:' \ + '*'{-t,--to}'[email addresses of recipients]:email:' \ + ':revision:_hg_revrange' +} + _hg "$@"