2009-06-05 08:41:27 +02:00
|
|
|
# cvs(1) completion
|
2009-10-01 20:54:51 +03:00
|
|
|
|
2011-04-05 00:35:51 +03:00
|
|
|
have cvs || return
|
|
|
|
|
2009-06-05 08:41:27 +02:00
|
|
|
set_prefix()
|
|
|
|
{
|
2009-10-04 19:42:50 +02:00
|
|
|
[ -z ${prefix:-} ] || prefix=${cur%/*}/
|
|
|
|
[ -r ${prefix:-}CVS/Entries ] || prefix=""
|
2009-06-05 08:41:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get_entries()
|
|
|
|
{
|
2009-10-04 19:42:50 +02:00
|
|
|
local IFS=$'\n'
|
|
|
|
[ -r ${prefix:-}CVS/Entries ] && \
|
|
|
|
entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries)
|
2009-06-05 08:41:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get_modules()
|
|
|
|
{
|
2009-10-04 19:42:50 +02:00
|
|
|
if [ -n "$prefix" ]; then
|
|
|
|
COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) )
|
|
|
|
else
|
|
|
|
COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) )
|
|
|
|
fi
|
2009-06-05 08:41:27 +02:00
|
|
|
}
|
|
|
|
|
2009-10-20 09:29:36 +03:00
|
|
|
_cvs_commands()
|
|
|
|
{
|
2009-10-20 20:57:18 +03:00
|
|
|
cvs --help-commands 2>&1 | awk '/^( *|\t)/ { print $1 }'
|
2009-10-20 09:29:36 +03:00
|
|
|
}
|
|
|
|
|
2009-10-20 21:17:28 +03:00
|
|
|
_cvs_command_options()
|
|
|
|
{
|
2011-04-28 21:21:31 +03:00
|
|
|
COMPREPLY=( $( compgen -W '$( _parse_help "$1" "--help $2" )' -- "$cur" ) )
|
2009-10-20 21:17:28 +03:00
|
|
|
}
|
|
|
|
|
2009-10-20 21:50:21 +03:00
|
|
|
_cvs_kflags()
|
|
|
|
{
|
|
|
|
COMPREPLY=( $( compgen -W 'kv kvl k o b v' -- "$cur" ) )
|
|
|
|
}
|
|
|
|
|
2009-12-28 22:56:13 +02:00
|
|
|
_cvs_roots()
|
|
|
|
{
|
2009-12-28 23:03:24 +02:00
|
|
|
local -a cvsroots
|
|
|
|
cvsroots=( $CVSROOT )
|
|
|
|
[ -r ~/.cvspass ] && \
|
2011-04-06 20:39:21 +03:00
|
|
|
cvsroots+=( $( awk '{ print $2 }' ~/.cvspass ) )
|
2011-04-26 00:21:55 +03:00
|
|
|
[ -r CVS/Root ] && mapfile -tO ${#cvsroots[@]} cvsroots < CVS/Root
|
2009-12-28 23:03:24 +02:00
|
|
|
COMPREPLY=( $( compgen -W '${cvsroots[@]}' -- "$cur" ) )
|
|
|
|
__ltrim_colon_completions "$cur"
|
2009-12-28 22:56:13 +02:00
|
|
|
}
|
|
|
|
|
2009-06-05 08:41:27 +02:00
|
|
|
_cvs()
|
|
|
|
{
|
2011-04-20 14:42:30 +03:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion -n : || return
|
2009-06-05 08:41:27 +02:00
|
|
|
|
2011-04-20 14:42:30 +03:00
|
|
|
local count mode i cvsroot cvsroots pwd
|
|
|
|
local -a flags miss files entries changed newremoved
|
2009-06-05 08:41:27 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
count=0
|
2011-04-20 14:42:30 +03:00
|
|
|
for i in "${words[@]}"; do
|
|
|
|
[ $count -eq $cword ] && break
|
2009-10-04 19:42:50 +02:00
|
|
|
# Last parameter was the CVSROOT, now go back to mode selection
|
2011-04-20 14:42:30 +03:00
|
|
|
if [[ "${words[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
mode=""
|
|
|
|
fi
|
|
|
|
if [ -z "$mode" ]; then
|
|
|
|
case $i in
|
2009-10-20 21:51:47 +03:00
|
|
|
-H|--help)
|
|
|
|
COMPREPLY=( $( compgen -W "$( _cvs_commands )" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
mode=cvsroot
|
2011-04-20 14:42:30 +03:00
|
|
|
cvsroot=${words[((count+1))]}
|
2009-10-20 21:51:47 +03:00
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
ad|add|new)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=add
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
adm|admin|rcs)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=admin
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
ann|annotate)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=annotate
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
checkout|co|get)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=checkout
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
com|commit|ci)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=commit
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
di|dif|diff)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=diff
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
ex|exp|export)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=export
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
edit|unedit)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=$i
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
hi|his|history)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=history
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
im|imp|import)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=import
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
re|rel|release)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=release
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
log|rlog)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=log
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
rdiff|patch)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=rdiff
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
remove|rm|delete)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=remove
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
rtag|rfreeze)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=rtag
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
st|stat|status)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=status
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
tag|freeze)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=tag
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
up|upd|update)
|
2009-10-20 21:51:47 +03:00
|
|
|
mode=update
|
|
|
|
;;
|
2009-10-04 19:42:50 +02:00
|
|
|
esac
|
|
|
|
elif [[ "$i" = -* ]]; then
|
2011-04-06 20:39:21 +03:00
|
|
|
flags+=( $i )
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
count=$((++count))
|
|
|
|
done
|
2009-06-05 08:41:27 +02:00
|
|
|
|
2009-12-30 00:39:59 +01:00
|
|
|
case $mode in
|
2009-10-04 19:42:50 +02:00
|
|
|
add)
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 21:50:21 +03:00
|
|
|
-m)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
_cvs_kflags
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" != -* ]]; then
|
|
|
|
set_prefix
|
2011-04-20 14:42:30 +03:00
|
|
|
if [[ $cword -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
get_entries
|
|
|
|
[ -z "$cur" ] && \
|
|
|
|
files=$( command ls -Ad !(CVS) ) || \
|
|
|
|
files=$( command ls -d ${cur}* 2>/dev/null )
|
|
|
|
for i in "${entries[@]}"; do
|
|
|
|
files=( ${files[@]/#$i//} )
|
|
|
|
done
|
|
|
|
COMPREPLY=( $( compgen -X '*~' -W '${files[@]}' -- $cur ) )
|
|
|
|
fi
|
|
|
|
else
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
admin)
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 21:50:21 +03:00
|
|
|
-a|-A|-b|-c|-e|-l|-m|-n|-N|-o|-s|-t-|-u)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-t)
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
_cvs_kflags
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" = -* ]]; then
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
annotate)
|
2009-10-20 21:50:21 +03:00
|
|
|
[[ "$prev" == -@(r|D) ]] && return 0
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" = -* ]]; then
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
else
|
|
|
|
get_entries
|
|
|
|
COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) )
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
checkout)
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 21:50:21 +03:00
|
|
|
-r|-D|j)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
_cvs_kflags
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" != -* ]]; then
|
|
|
|
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
|
|
|
|
COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \
|
|
|
|
awk '{print $1}' ) )
|
|
|
|
COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
|
|
|
|
else
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
commit)
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 21:50:21 +03:00
|
|
|
-m|-r)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-F)
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
set_prefix
|
2009-06-05 08:41:27 +02:00
|
|
|
|
2010-07-01 20:21:35 +03:00
|
|
|
if [[ "$cur" != -* && -r ${prefix:-}CVS/Entries ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
# if $COMP_CVS_REMOTE is not null, 'cvs commit' will
|
|
|
|
# complete on remotely checked-out files (requires
|
|
|
|
# passwordless access to the remote repository
|
|
|
|
if [ -n "${COMP_CVS_REMOTE:-}" ]; then
|
|
|
|
# this is the least computationally intensive
|
|
|
|
# way found so far, but other changes
|
|
|
|
# (something other than changed/removed/new)
|
|
|
|
# may be missing
|
|
|
|
changed=( $( cvs -q diff --brief 2>&1 | \
|
|
|
|
sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) )
|
|
|
|
newremoved=( $( cvs -q diff --brief 2>&1 | \
|
|
|
|
sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) )
|
|
|
|
COMPREPLY=( $( compgen -W '${changed[@]:-} \
|
|
|
|
${newremoved[@]:-}' -- "$cur" ) )
|
|
|
|
else
|
2009-10-22 12:04:29 +03:00
|
|
|
COMPREPLY=( $(compgen -o default -- "$cur") )
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
else
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
cvsroot)
|
2009-12-28 23:03:24 +02:00
|
|
|
# TODO: works poorly because of the colons and -o default,
|
|
|
|
# could we drop -o default? works ok without it in cvsps
|
2009-12-28 22:56:13 +02:00
|
|
|
_cvs_roots
|
2009-10-04 19:42:50 +02:00
|
|
|
;;
|
|
|
|
export)
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 21:50:21 +03:00
|
|
|
-r|-D)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
_cvs_kflags
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" != -* ]]; then
|
|
|
|
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
|
|
|
|
COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) )
|
|
|
|
COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
|
|
|
|
else
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
diff)
|
|
|
|
if [[ "$cur" == -* ]]; then
|
2011-04-29 12:42:39 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2011-05-02 11:41:52 +03:00
|
|
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
2009-10-04 19:42:50 +02:00
|
|
|
else
|
|
|
|
get_entries
|
|
|
|
COMPREPLY=( $( compgen -W '${entries[@]:-}' -- "$cur" ) )
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
if [[ "$cur" != -* ]]; then
|
|
|
|
set_prefix
|
2011-04-20 14:42:30 +03:00
|
|
|
if [[ $cword -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
get_entries
|
|
|
|
# find out what files are missing
|
|
|
|
for i in "${entries[@]}"; do
|
2011-04-06 20:39:21 +03:00
|
|
|
[ ! -r "$i" ] && miss+=( $i )
|
2009-10-04 19:42:50 +02:00
|
|
|
done
|
|
|
|
COMPREPLY=( $(compgen -W '${miss[@]:-}' -- "$cur") )
|
|
|
|
fi
|
|
|
|
else
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
import)
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 21:50:21 +03:00
|
|
|
-I|-b|-m|-W)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
_cvs_kflags
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" != -* ]]; then
|
|
|
|
# starts with same algorithm as checkout
|
|
|
|
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
|
|
|
|
prefix=${cur%/*}
|
|
|
|
if [ -r ${cvsroot}/${prefix} ]; then
|
|
|
|
get_modules
|
|
|
|
COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )
|
|
|
|
COMPREPLY=( ${COMPREPLY[@]#\/} )
|
|
|
|
fi
|
|
|
|
pwd=$( pwd )
|
|
|
|
pwd=${pwd##*/}
|
|
|
|
COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- $cur ) )
|
|
|
|
else
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
update)
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 21:50:21 +03:00
|
|
|
-r|-D|-j|-I|-W)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
_cvs_kflags
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" = -* ]]; then
|
2011-04-28 21:21:31 +03:00
|
|
|
_cvs_command_options "$1" $mode
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"")
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-20 22:08:18 +03:00
|
|
|
-T)
|
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-e|-s)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-z)
|
2011-04-25 23:44:08 +03:00
|
|
|
COMPREPLY=( $( compgen -W '{1..9}' -- "$cur" ) )
|
2009-10-20 22:08:18 +03:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2011-04-28 21:21:31 +03:00
|
|
|
COMPREPLY=( $( compgen -W '$( _cvs_commands ) \
|
|
|
|
$( _parse_help "$1" --help-options ) \
|
2009-10-20 09:29:36 +03:00
|
|
|
--help --help-commands --help-options --version' -- "$cur" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
;;
|
|
|
|
esac
|
2009-06-05 08:41:27 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
return 0
|
2011-04-04 22:14:39 +03:00
|
|
|
} &&
|
2009-10-22 12:04:29 +03:00
|
|
|
complete -F _cvs -o default cvs
|
2009-10-01 20:54:51 +03:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
2009-10-04 19:42:50 +02:00
|
|
|
# sh-basic-offset: 4
|
2009-10-01 20:54:51 +03:00
|
|
|
# sh-indent-comment: t
|
2009-10-04 19:42:50 +02:00
|
|
|
# indent-tabs-mode: nil
|
2009-10-01 20:54:51 +03:00
|
|
|
# End:
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|