Hi,
new version. This patch are my current changes for "svn ls" only. I need some
feedback concerning:
-> how to deal with svn error messages written to stderr, for example:
svn ls svn+ssh://svn.something.com/<tab><tab>u...@svn.something.com's password:
this happens when you forget to do ssh-add
-> in bash >= 4 they changed COMP_WORDS. The Line will be split at : as well,
so "file:/something" are 3 array items. Nobody would use subversion 1.9 with
bash 3 ... probably. I will drop bash 3 statements, for example:
if [[ $cur == file:* ]]
ok?
> Please can URL completion work on full URLs as well as on relative URLs?
for SVN LS this is done:
1. svn ls tabtab -> ^/ file:/// http:// https://
svn:// svn+ssh://
2. svn ls svn+ssh://tabtab -> will look at the ~/.ssh/known_hosts
3. svn ls http[s]://tabtab -> lookup in ~/.subversion/simple-auth -
should still be working
4. svn ls proto://server/tabtab or ^/tabtab -> autocomplete via "svn ls"
cheers,
Chris
Index: bash_completion
===================================================================
--- bash_completion (Revision 1696324)
+++ bash_completion (Arbeitskopie)
@@ -204,7 +204,7 @@
propCmds="$psCmds|propget|pget|pg|propedit|pedit|pe|propdel|pdel|pd"
# possible URL schemas to access a subversion server
- local urlSchemas='file:/// http:// https:// svn:// svn+ssh://'
+ local urlSchemas='^/ file:/// http:// https:// svn:// svn+ssh://'
# Parse arguments and set various variables about what was found.
#
@@ -392,16 +392,37 @@
if [[ $cmd == @(co|checkout|ls|list) && $stat = 'arg' && \
$SVN_BASH_COMPL_EXT == *urls* ]]
then
+ # echo "daaa [$cur] [$1] [$2] [$3] [$4] | [${COMP_WORDS[@]}] [$COMP_WORDBREAKS]"
+ local prefix=${COMP_WORDS[COMP_CWORD-2]}
# see about COMP_WORDBREAKS workaround in prop completion
- if [[ $cur == file:* ]]
+ if [[ $prefix == "file" && "$3" == ":" ]]
then
# file completion for file:// urls
- local where=${cur/file:/}
+ local where=$cur
COMPREPLY=( $(compgen -d -S '/' -X '*/.*' -- $where ) )
return
- elif [[ $cur == *:* ]]
+ elif [[ ( $cmd == @(ls|list) && $cur == ^/* ) || ( "$3" == ":" && $cur == //*/* ) ]]
+ then # autocomplete for svn ls ^/bla | svn ls remote_url | svn checkout remote_url
+ local p
+ if [ "$3" == ":" ] ; then
+ p="$prefix$3"
+ fi
+ if [[ $cur =~ ((.*/)([^/]*)) ]] # url = everything up to the last /
+ then
+ local url="${BASH_REMATCH[2]}"
+ local path="${BASH_REMATCH[3]}"
+ local remote_files="$(svn ls "$p$url")"
+ # echo "$remote_files"
+ COMPREPLY=( $(compgen -P "$url" -W "$remote_files" -- "$path" ) )
+ compopt -o nospace
+ return 0
+ fi
+ # bash 3: elif [[ $cur == *:* ]]
+ # bash 4:
+ elif [[ "$3" == ":" ]]
then
- # get known urls
+ # echo "search known urls"
+ # get known server - urls
local urls= file=
for file in ~/.subversion/auth/svn.simple/* ; do
if [ -r $file ] ; then
@@ -413,12 +434,23 @@
done
# only suggest/show possible suffixes
- local prefix=${cur%:*} suffix=${cur#*:} c= choices=
+ local suffix=$cur c= choices=
+ #echo "####$prefix####"
for c in $urls ; do
[[ $c == $prefix:* ]] && choices="$choices ${c#*:}"
done
-
- COMPREPLY=( $(compgen -W "$choices" -- $suffix ) )
+ #echo "----$choices----"
+
+ # svn+ssh://
+ if [[ $prefix == "svn+ssh" && $cur =~ (^//(.*)) ]] ; then
+ local server_start=${BASH_REMATCH[2]}
+ # debian & suse: /usr/share/bash-completion/bash_completion
+ _known_hosts_real -p // "$server_start"
+ # echo "~$server_start~~~~~${COMPREPLY[@]}"
+ else
+ COMPREPLY=( $(compgen -W "$choices" -- $suffix ) )
+ fi
+ compopt -o nospace
return
else
# show schemas
@@ -426,6 +458,7 @@
compopt -o nospace
return
fi
+ #echo "nothing found"
fi
if [[ $cmd = 'merge' || $cmd = 'mergeinfo' ]]
@@ -454,6 +487,16 @@
# force --reintegrate only if the current word is empty
COMPREPLY=( $(compgen -W '--reintegrate' -- $cur ) )
return 0
+ elif [[ $URL == ^/* ]] ; then
+ # autocomplete for svn merge ^/bla
+ if [[ $cur =~ ((.*/)([^/]*)) ]] ; then
+ local url="${BASH_REMATCH[2]}"
+ local path="${BASH_REMATCH[3]}"
+ local remote_files="$(svn ls "$url")"
+ COMPREPLY=( $(compgen -P "$url" -W "$remote_files" -- "$path" ) )
+ compopt -o nospace
+ return 0
+ fi
fi
fi