cvs: Improve CVS controlled file completions.

This commit is contained in:
Ville Skyttä 2011-05-24 23:08:45 +03:00
parent b6794fe66d
commit af3f67f2e5
5 changed files with 41 additions and 34 deletions

View File

@ -2,17 +2,15 @@
have cvs || return have cvs || return
set_prefix()
{
[ -z ${prefix:-} ] && prefix=${cur%/*}/
[ -r ${prefix:-}CVS/Entries ] || prefix=""
}
get_entries() get_entries()
{ {
local IFS=$'\n' local prefix=${cur%/*}/ IFS=$'\n'
[ -r ${prefix:-}CVS/Entries ] && \ [[ -e ${prefix:-}CVS/Entries ]] || prefix=""
entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries) entries=( $( cut -d/ -f2 -s ${prefix:-}CVS/Entries 2>/dev/null ) )
if [[ $entries ]]; then
entries=( "${entries[@]/#/${prefix:-}}" )
compopt -o filenames
fi
} }
get_modules() get_modules()
@ -55,7 +53,7 @@ _cvs()
local cur prev words cword local cur prev words cword
_init_completion -n : || return _init_completion -n : || return
local count mode i cvsroot cvsroots pwd prefix local count mode i cvsroot cvsroots pwd
local -a flags miss files entries changed newremoved local -a flags miss files entries changed newremoved
count=0 count=0
@ -149,17 +147,24 @@ _cvs()
esac esac
if [[ "$cur" != -* ]]; then if [[ "$cur" != -* ]]; then
set_prefix
if [[ $cword -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
get_entries get_entries
[ -z "$cur" ] && \ [ -z "$cur" ] && files=( !(CVS) ) || \
files=$( command ls -Ad !(CVS) ) || \ files=( $( command ls -d ${cur}* 2>/dev/null ) )
files=$( command ls -d ${cur}* 2>/dev/null ) local f
for i in "${entries[@]}"; do for i in ${!files[@]}; do
files=( ${files[@]/#$i//} ) if [[ ${files[i]} == ?(*/)CVS ]]; then
done unset files[i]
COMPREPLY=( $( compgen -X '*~' -W '${files[@]}' -- $cur ) ) else
for f in "${entries[@]}"; do
if [[ ${files[i]} == $f && ! -d $f ]]; then
unset files[i]
break
fi fi
done
fi
done
COMPREPLY=( $( compgen -X "$_backup_glob" -W '${files[@]}' \
-- "$cur" ) )
else else
_cvs_command_options "$1" $mode _cvs_command_options "$1" $mode
fi fi
@ -228,9 +233,7 @@ _cvs()
;; ;;
esac esac
set_prefix if [[ "$cur" != -* ]]; then
if [[ "$cur" != -* && -r ${prefix:-}CVS/Entries ]]; then
# if $COMP_CVS_REMOTE is not null, 'cvs commit' will # if $COMP_CVS_REMOTE is not null, 'cvs commit' will
# complete on remotely checked-out files (requires # complete on remotely checked-out files (requires
# passwordless access to the remote repository # passwordless access to the remote repository
@ -289,15 +292,12 @@ _cvs()
;; ;;
remove) remove)
if [[ "$cur" != -* ]]; then if [[ "$cur" != -* ]]; then
set_prefix
if [[ $cword -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
get_entries get_entries
# find out what files are missing # find out what files are missing
for i in "${entries[@]}"; do for i in "${entries[@]}"; do
[ ! -r "$i" ] && miss+=( $i ) [ ! -r "$i" ] && miss+=( $i )
done done
COMPREPLY=( $(compgen -W '${miss[@]:-}' -- "$cur") ) COMPREPLY=( $( compgen -W '${miss[@]:-}' -- "$cur" ) )
fi
else else
_cvs_command_options "$1" $mode _cvs_command_options "$1" $mode
fi fi
@ -316,7 +316,7 @@ _cvs()
if [[ "$cur" != -* ]]; then if [[ "$cur" != -* ]]; then
# starts with same algorithm as checkout # starts with same algorithm as checkout
[ -z "$cvsroot" ] && cvsroot=$CVSROOT [ -z "$cvsroot" ] && cvsroot=$CVSROOT
prefix=${cur%/*} local prefix=${cur%/*}
if [ -r ${cvsroot}/${prefix} ]; then if [ -r ${cvsroot}/${prefix} ]; then
get_modules get_modules
COMPREPLY=( ${COMPREPLY[@]#$cvsroot} ) COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )

2
test/fixtures/cvs/foo/CVS/Entries vendored Normal file
View File

@ -0,0 +1,2 @@
/bar/1.1/Tue Jan 29 05:52:29 2008//
D

0
test/fixtures/cvs/foo/bar vendored Normal file
View File

0
test/fixtures/cvs/foo/quux vendored Normal file
View File

View File

@ -8,6 +8,7 @@ proc teardown {} {
assert_bash_exec {HOME=$OLDHOME} assert_bash_exec {HOME=$OLDHOME}
assert_env_unmodified { assert_env_unmodified {
/OLDHOME=/d /OLDHOME=/d
/OLDPWD=/d
} }
} }
@ -33,4 +34,8 @@ expect {
sync_after_int sync_after_int
assert_complete_dir "foo/bar" "cvs diff foo/" $::srcdir/fixtures/cvs
sync_after_int
teardown teardown