Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

RFC: _svk completion



Here it is, a completion for _svk.
Very incomplete and not too accurate. It's a start...

It completes all commands, handles a few aliases and knows completions
for arguments of a handful of commands. Extending it should be fairly
simple for people familiar with svk.

I'm not a heavy user of svk, but I did this, when I was playing with
it. It saved some typing. If there are svk users that want to extend
it, here is the code:


diff --git a/Completion/Unix/Command/_svk b/Completion/Unix/Command/_svk
new file mode 100644
index 0000000..d03646a
--- /dev/null
+++ b/Completion/Unix/Command/_svk
@@ -0,0 +1,191 @@
+#compdef svk
+
+local comm state tmp
+local -a svk_aliases_desc svk_commands svk_main_opts
+local -A svk_aliases
+
+svk_commands=(
+    'add:put files and directories under version control'
+    'admin:administration tools'
+    'annotate:display per-line revision and author info'
+    'cat:output the file from depot'
+    'checkout:checkout the depotpath'
+    'cleanup:remove stalled locks'
+    'cmerge:merge specific changes'
+    'commit:commit changes to depot'
+    'copy:make a versioned copy'
+    'delete:remove versioned item'
+    'depotmap:create or edit the depot mapping configuration'
+    'describe:describe a change'
+    'diff:display diff between revisions or checkout copies'
+    'help:show help'
+    'ignore:ignore files by setting svn:ignore property'
+    'import:import directory into depot'
+    'info:display information about a file or directory'
+    'list:list entries in a directory from depot'
+    'log:show log messages for revisions'
+    'merge:apply differences between two sources'
+    'mirror:initialize a mirrored depotpath'
+    'mkdir:create a versioned directory'
+    'move:move a file or directory'
+    'patch:manage patches'
+    'propdel:delete a property on files or dirs'
+    'propedit:edit a property on path'
+    'propget:display a property on path'
+    'proplist:list all properties on files or dirs'
+    'propset:set a property on path'
+    'pull:bring changes from another repository'
+    'push:move changes into another repository'
+    'resolved:remove conflict mark from checkout items'
+    'revert:revert changes made in checkout copies'
+    'smerge:automatically merge all changes between branches'
+    'status:display the status of items in the checkout copy'
+    'switch:switch to another branch and keep local changes'
+    'sync:synchronize a mirrored depotpath'
+    'update:bring changes from repository to checkout copies'
+    'verify:verify change signatures'
+)
+
+svk_aliases=(
+        '?'         'help'
+        'co'        'checkout'
+        'cp'        'copy'
+        'depot'     'depotmap'
+        'h'         'help'
+        'ls'        'list'
+        'mi'        'mirror'
+        'sy'        'sync'
+)
+
+svk_main_opts=(
+    '--version[display version information]'
+    '--help[display help message]'
+)
+
+svk_aliases_desc=()
+for tmp in ${(k)svk_aliases} ; do
+    svk_aliases_desc+=( "${tmp}:alias for ${svk_aliases[$tmp]}" )
+done
+
+# _svk completion utilities
+(( ${+functions[__svk_depots]} )) ||
+__svk_depots () {
+    local -a ds
+
+    ds=(
+        ${${(M)${(f)"$( _call_program depotmap1 svk depotmap --list )"}:#//*}// */}
+        ${${(M)${(f)"$( _call_program depotmap2 svk mirror --list )"}:#//*}// */}
+    )
+    _describe -t depots 'svk depots' ds
+}
+
+(( ${+functions[__svk_depots_or_path]} )) ||
+__svk_depots_or_path () {
+    __svk_depots
+    _path_files -g '*(/)'
+}
+
+# sub command completions
+(( ${+functions[_svk-checkout]} )) ||
+_svk-checkout () {
+    _arguments \
+        '(--revision -r)'{--revision,-r}'[act on revision REV instead of the head revision]' \
+        '(--non-recursive -N)'{--non-recursive,-N}'[do not descend recursively]' \
+        '(--list -l)'{--list,-l}'[list checkout paths]' \
+        '(--detach -d)'{--detach,-d}'[mark a path as no longer checked out]' \
+        '(--quiet -q)'{--quiet,-q}'[quiet mode]' \
+        '--export[export mode; checkout a detached copy]' \
+        '--floating[create a floating checkout]' \
+        '--relocate[relocate the checkout to another path]' \
+        '--purge[detach checkout directories which no longer exist]' \
+        '*::checkoutarg:__svk_depots_or_path'
+}
+
+(( ${+functions[_svk-copy]} )) ||
+_svk-copy () {
+    _arguments \
+        '(--revision -r)'{--revision,-r}'[act on revision REV instead of the head revision]' \
+        '(--parent -p)'{--parent,-p}'[create intermediate directories as required]' \
+        '(--quiet -q)'{--quiet,-q}'[print as little as possible]' \
+        '(--message -m)'{--message,-m}'[specify commit message]' \
+        '(--file -F)'{--file,-F}'[read commit message from FILENAME]' \
+        '(--patch -P)'{--patch,-P}'[instead of commit, save this change as a patch]' \
+        '(--sign -S)'{--sign,-S}'[sign this change]' \
+        '(--check-only -C)'{--check-only,-C}'[try operation but make no changes]' \
+        '--template[use the specified message as the template to edit]' \
+        '--encoding[treat -m/-F value as being in charset specified encoding]' \
+        '--direct[commit directly even if the path is mirrored]' \
+        '*::copyarg:__svk_depots'
+}
+
+(( ${+functions[_svk-depotmap]} )) ||
+_svk-depotmap () {
+    _arguments \
+        '(--init -i)'{--init,-i}'[initialize a default depot]' \
+        '(--list -l)'{--list,-l}'[list current depot mappings]' \
+        '(--detach -d)'{--detach,-d}'[remove a depot from the mapping]' \
+        '--relocate[relocate the depot to another path]' \
+        '*::depmaparg:__svk_depots_or_path'
+}
+
+(( ${+functions[_svk-help]} )) ||
+_svk-help () {
+    local -a help_subjects
+    help_subjects=(
+        'commands:a list of all available commands'
+        'environment:environment variables that alter svk'\''s behavior'
+        'intro:a little introductory speech'
+        'view:svk view support'
+    )
+    _describe -t subjects 'svk help subjects' help_subjects
+    _describe -t commands 'svk command help'  svk_commands
+}
+
+(( ${+functions[_svk-mirror]} )) ||
+_svk-mirror () {
+    _arguments \
+        '(--list -l)'{--list,-l}'[list mirrored paths]' \
+        '(--detach -d)'{--detach,-d}'[mark a depotpath as no longer mirrored]' \
+        '--relocate[change the upstream URI for the mirrored depotpath]' \
+        '--recover[recover the state of a mirror path]' \
+        '--unlock[forcibly remove stalled locks on a mirror]' \
+        '--upgrade[upgrade mirror state to the latest version]' \
+        '*::mirrorarg:__svk_depots_or_path'
+}
+
+(( ${+functions[_svk-sync]} )) ||
+_svk-sync () {
+    _arguments \
+        '(--all -a)'{--all,-a}'[synchronize all mirrored paths]' \
+        '(--skipto -s)'{--skipto,-s}'[start synchronization at revision REV]:' \
+        '(--torev -t)'{--,-}'[stop synchronization at revision REV]:' \
+        '*::syncarg:__svk_depots'
+}
+
+# main commands completion
+(( ${+functions[_svk-commands]} )) ||
+_svk-commands () {
+    _describe -t commands 'svk commands' svk_commands
+    _describe -t aliases  'svk aliases'  svk_aliases_desc
+}
+
+# _svk()
+_arguments -C \
+    ${svk_main_opts} \
+    '*::arg:->cmd_or_options' && return
+
+case ${state} in
+(cmd_or_options)
+    if (( CURRENT == 1 )); then
+        _svk-commands
+    else
+        if [[ -n ${svk_aliases[$words[1]]} ]] ; then
+            comm=${svk_aliases[$words[1]]}
+        else
+            comm=${words[1]}
+        fi
+        curcontext="${curcontext%:*:*}:svk-${comm}:"
+        (( ${+functions[_svk-${comm}]} )) && _svk-${comm}
+    fi
+    ;;
+esac



Messages sorted by: Reverse Date, Date, Thread, Author