Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: dconf completion
- X-seq: zsh-workers 41711
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: dconf completion
- Date: Fri, 15 Sep 2017 18:50:13 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1505494215; bh=UeQIMQgRApWaqMZ8BjGPVm7Dl3sHcXheqK5HXzeozTU=; h=From:To:Subject:Date:From:Subject; b=Kb6lhfWZjOpr0Nj/vN4ldFB6Kkp2AKNMdQqfHkt76OXbMmgBNlKnkYVGpEcfgzyP5sgxxQplhzsMAXAyAbP1pC8giN3qDg8XhOd+bKcunc6ofxHQ9VyrhDnXvy5Crg9h24AYXVlN5IKppSkAuP+NbeSroknXF9JhGlUzp5ENqwOhed8ZJGazPktCDZjQR5O2BaqZw6J2y7ZJ0Re8S0K4M3GtpfaOkzUDdiTF4QhBT2OR65/UHOE610j5Tm9ikmrGrp0LHRdKxIPLaaYZ9SbTPKQDkUksZXC27PpaMeol0NMS++AaO6tAyKW0COTdzCmnEMMUESMfSRzCEx4O0ImBNw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
dconf has a hidden _complete subcommand for getting completion matches
so this is fairly straightforward. It ends up being separated like a
file/directory hierarchy unlike the gsettings completion which has them
all together with matching control.
Oliver
diff --git a/Completion/Unix/Command/_dconf b/Completion/Unix/Command/_dconf
new file mode 100644
index 000000000..645af3a4f
--- /dev/null
+++ b/Completion/Unix/Command/_dconf
@@ -0,0 +1,71 @@
+#compdef dconf
+
+local curcontext="$curcontext" state line cmds ret=1
+local cmd=$words[1]
+
+cmds=(
+ 'help:display help information'
+ 'read:read the value of a key'
+ 'list:list the contents of a directory'
+ 'write:change the value of a key'
+ 'reset:reset the value of a key or directory'
+ 'compile:compile a binary database from keyfiles'
+ 'update:update the system databases'
+ 'watch:watch a path for changes'
+ 'dump:dump an entire subpath to stdout'
+ 'load:populate a subpath from stdin'
+)
+
+if (( CURRENT == 2 )); then
+ _describe -t commands command cmds
+ return
+fi
+
+curcontext="${curcontext%:*}-$words[2]:"
+shift words
+(( CURRENT-- ))
+
+case $words[1] in
+ dump|list|load) state=dirs ;;
+ watch) state=keys ;;
+ read)
+ _arguments -A "-*" '-d[read default values]' '1:key:->keys' && ret=0
+ ;;
+ write)
+ _arguments '1:key:->keys' '2:value' && ret=0
+ ;;
+ reset)
+ _arguments -A "-*" '-f[reset entire directory]' '1:key:->keys' && ret=0
+ [[ $+opt_args[-f] = 1 && state = keys ]] && state=dirs
+ ;;
+ compile)
+ _arguments '1:file:_files' '2:path:_directories' && ret=0
+ ;;
+ help)
+ _describe -t commands command cmds && ret=0
+ ;;
+ *) _default && ret=0 ;;
+esac
+
+case $state in
+ keys)
+ compset -P '*/'
+ dirs=( ${${${(f)"$(_call_program keys dconf _complete \'\' "${IPREFIX:-/}")"}#$IPREFIX}%% #} )
+ _tags keys
+ while _tags; do
+ if _requested keys; then
+ _description keys expl keu
+ compadd "$expl[@]" -qS ' ' ${dirs:#*/} && ret=0
+ compadd "$expl[@]" -S '' ${(M)dirs:#*/} && ret=0
+ fi
+ (( ret )) || break
+ done
+ ;;
+ dirs)
+ compset -P '*/'
+ _wanted keys expl directory compadd -S '' - \
+ ${${(f)"$(_call_program keys dconf _complete / "${IPREFIX:-/}")"}#$IPREFIX} && ret=0
+ ;;
+esac
+
+return ret
.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author