##// END OF EJS Templates
add --options to debugcomplete and change bash_completion to use it...
add --options to debugcomplete and change bash_completion to use it make debugcomplete print one item per line (this is not needed for the bash_completion script, but should be easier to use in other scripts)

File last commit:

r2034:5e7aff1b default
r2034:5e7aff1b default
Show More
bash_completion
160 lines | 3.0 KiB | application/x-sh | BashLexer
TK Soh
bash_completion: extended patterns require extglob option
r1311 shopt -s extglob
mpm@selenic.com
Add bash_completion to contrib...
r916 _hg_commands()
{
Thomas Arendsen Hein
Make bash_completion more robust for e.g. broken hgrc or old hg installations.
r1888 local commands
commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands=""
Benoit Boissinot
new command debugcomplete...
r1887 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
mpm@selenic.com
Add bash_completion to contrib...
r916 }
_hg_paths()
{
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"
COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
mpm@selenic.com
Add bash_completion to contrib...
r916 }
Daniel Kobras
Less annoying directory completion (see http://bugs.debian.org/343458)...
r1587 _hg_repos()
{
local i
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 for i in $(compgen -d -- "$cur"); do
test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
Daniel Kobras
Less annoying directory completion (see http://bugs.debian.org/343458)...
r1587 done
}
mpm@selenic.com
bash: Add smarter completion of add/commit/remove/forget/diff/revert...
r935 _hg_status()
{
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 local files="$("$hg" status -n$1 . 2>/dev/null)"
COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
mpm@selenic.com
bash: Add smarter completion of add/commit/remove/forget/diff/revert...
r935 }
mpm@selenic.com
Add bash_completion to contrib...
r916 _hg_tags()
{
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 local tags="$("$hg" tags 2>/dev/null |
sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')"
COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
mpm@selenic.com
Add bash_completion to contrib...
r916 }
# this is "kind of" ugly...
_hg_count_non_option()
{
local i count=0
local filters="$1"
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 for ((i=1; $i<=$COMP_CWORD; i++)); do
mpm@selenic.com
Add bash_completion to contrib...
r916 if [[ "${COMP_WORDS[i]}" != -* ]]; then
Alexis S. L. Carvalho
bash_completion: small cleanup and bugfix...
r1152 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
continue
fi
mpm@selenic.com
Add bash_completion to contrib...
r916 count=$(($count + 1))
fi
done
echo $(($count - 1))
}
_hg()
{
local cur prev cmd opts i
Alexis S. L. Carvalho
teach bash_completion about --cwd
r1151 # global options that receive an argument
local global_args='--cwd|-R|--repository'
Thomas Arendsen Hein
Use user specified path to hg in bash_completion...
r1683 local hg="$1"
mpm@selenic.com
Add bash_completion to contrib...
r916
COMPREPLY=()
cur="$2"
prev="$3"
Thomas Arendsen Hein
Cleanup of tabs and trailing spaces.
r1308 # searching for the command
Alexis S. L. Carvalho
teach bash_completion about --cwd
r1151 # (first non-option argument that doesn't follow a global option that
# receives an argument)
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 for ((i=1; $i<=$COMP_CWORD; i++)); do
Alexis S. L. Carvalho
teach bash_completion about --cwd
r1151 if [[ ${COMP_WORDS[i]} != -* ]]; then
if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
cmd="${COMP_WORDS[i]}"
break
fi
mpm@selenic.com
Add bash_completion to contrib...
r916 fi
done
if [[ "$cur" == -* ]]; then
Alexis S. L. Carvalho
add --options to debugcomplete and change bash_completion to use it...
r2034 opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null)
mpm@selenic.com
Add bash_completion to contrib...
r916
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
mpm@selenic.com
Add bash_completion to contrib...
r916 return
fi
Alexis S. L. Carvalho
teach bash_completion about --cwd
r1151 # global options
case "$prev" in
-R|--repository)
Daniel Kobras
Less annoying directory completion (see http://bugs.debian.org/343458)...
r1587 _hg_repos
Alexis S. L. Carvalho
teach bash_completion about --cwd
r1151 return
;;
--cwd)
Daniel Kobras
Less annoying directory completion (see http://bugs.debian.org/343458)...
r1587 # Stick with default bash completion
Alexis S. L. Carvalho
teach bash_completion about --cwd
r1151 return
;;
esac
mpm@selenic.com
Add bash_completion to contrib...
r916
if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
_hg_commands
return
fi
Alexis S. L. Carvalho
bash_completion: better handling of aliases...
r1150 # canonicalize command name
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 cmd=$("$hg" -q help "$cmd" 2>/dev/null | sed -e 's/^hg //; s/ .*//; 1q')
Alexis S. L. Carvalho
bash_completion: better handling of aliases...
r1150
mpm@selenic.com
Add bash_completion to contrib...
r916 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then
_hg_tags
return
fi
case "$cmd" in
help)
_hg_commands
;;
Alexis S. L. Carvalho
bash_completion: better handling of aliases...
r1150 export|manifest|update)
mpm@selenic.com
Add bash_completion to contrib...
r916 _hg_tags
;;
Alexis S. L. Carvalho
bash_completion: better handling of aliases...
r1150 pull|push|outgoing|incoming)
mpm@selenic.com
Add bash_completion to contrib...
r916 _hg_paths
Daniel Kobras
Less annoying directory completion (see http://bugs.debian.org/343458)...
r1587 _hg_repos
mpm@selenic.com
Add bash_completion to contrib...
r916 ;;
paths)
_hg_paths
;;
mpm@selenic.com
bash: Add smarter completion of add/commit/remove/forget/diff/revert...
r935 add)
_hg_status "u"
;;
Alexis S. L. Carvalho
bash_completion: better handling of aliases...
r1150 commit)
Thomas Arendsen Hein
_hg_status improvements in bash_completion:...
r1639 _hg_status "mar"
mpm@selenic.com
bash: Add smarter completion of add/commit/remove/forget/diff/revert...
r935 ;;
remove)
Thomas Arendsen Hein
_hg_status improvements in bash_completion:...
r1639 _hg_status "d"
mpm@selenic.com
bash: Add smarter completion of add/commit/remove/forget/diff/revert...
r935 ;;
forget)
_hg_status "a"
;;
diff)
Thomas Arendsen Hein
_hg_status improvements in bash_completion:...
r1639 _hg_status "mar"
mpm@selenic.com
bash: Add smarter completion of add/commit/remove/forget/diff/revert...
r935 ;;
revert)
Thomas Arendsen Hein
_hg_status improvements in bash_completion:...
r1639 _hg_status "mard"
mpm@selenic.com
bash: Add smarter completion of add/commit/remove/forget/diff/revert...
r935 ;;
mpm@selenic.com
Add bash_completion to contrib...
r916 clone)
local count=$(_hg_count_non_option)
if [ $count = 1 ]; then
_hg_paths
fi
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 _hg_repos
mpm@selenic.com
Add bash_completion to contrib...
r916 ;;
mpm@selenic.com
bash_completion: add debugindex and debugdata support
r1115 debugindex|debugindexdot)
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
mpm@selenic.com
bash_completion: add debugindex and debugdata support
r1115 ;;
debugdata)
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
mpm@selenic.com
bash_completion: add debugindex and debugdata support
r1115 ;;
mpm@selenic.com
Add bash_completion to contrib...
r916 esac
}
Thomas Arendsen Hein
Cleanup of spacing in bash_completion
r1684 complete -o bashdefault -o default -F _hg hg 2>/dev/null \
Alexis S. L. Carvalho
bash_completion: try to use bash3 features if they're available...
r1153 || complete -o default -F _hg hg