zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: add xprop and xlsatoms completions
@ 2011-05-31 12:47 Mikael Magnusson
  2016-08-28 16:28 ` PATCH: Use state_descr in _x_utils Mikael Magnusson
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2011-05-31 12:47 UTC (permalink / raw)
  To: zsh-workers

How do I use foo from '*-f:foo:->foo' to describe the argument to the
option in the $state handler? I lightly perused the _arguments docs but
nothing jumped out, I'll admit I didn't check too closely though. Ie,
the "atoms" I pass to _wanted overrides the 'atom' for -name. For xprop
I want to say 'property' instead of 'atom' too.

I'm also not sure if my creative return code handling is the best way
to handle this.

Do I need to add any other locals because of the -> things?

---
 Completion/X/Command/_x_utils |   33 ++++++++++++++++++++++++++++++++-
 Completion/X/Type/_x_font     |    2 +-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/Completion/X/Command/_x_utils b/Completion/X/Command/_x_utils
index 2e672fd..807e9a4 100644
--- a/Completion/X/Command/_x_utils
+++ b/Completion/X/Command/_x_utils
@@ -1,4 +1,6 @@
-#compdef xdpyinfo xwininfo xkill xfontsel xfd xev xhost xon xsetroot xwd xwud xrdb
+#compdef xdpyinfo xwininfo xkill xfontsel xfd xev xhost xon xsetroot xwd xwud xrdb xprop xlsatoms
+
+local ret=1 oret expl
 
 case "$service" in
 xdpyinfo)
@@ -13,6 +15,27 @@ xwininfo)
     '(-id -root)-name:name: _x_window -n' \
     '(-name -root)-id:id: _x_window'
   ;;
+xprop)
+  _x_arguments \
+    -{help,frame,notype,spy} \
+    '-grammar[show grammar for command line options]' \
+    '(-id -name)-root[use the root window as the target window]' \
+    '(-id -root)-name[specify target window by name]:name: _x_window -n' \
+    '(-name -root)-id[specify target window by window id]:id: _x_window' \
+    '-font[display the properties of a font]:font: _x_font' \
+    '-len[show at most n bytes of any property]:n' \
+    '*-fs[read more property formats from file]:file: _files' \
+    '*-remove[specify an atom to remove from the target window]:atoms:->atoms' \
+    '*-set[specify an atom and a value to set on the target window]:atoms:->atoms:value' \
+    '*-f:atoms:->atoms:format: ::dformat' \
+    '*:atoms:->atoms' && ret=0
+  ;;
+xlsatoms)
+  _x_arguments \
+    '*-format[printf-style format to use]:format' \
+    '*-range[atom values to list]:[num]-[num]' \
+    '*-name[name of single atom to print]:atom:->atoms'
+  ;;
 xkill)
   _x_arguments \
     -frame \
@@ -163,3 +186,11 @@ xrdb)
     '*:defaults file:_files'
   ;;
 esac
+
+oret=$?
+if [[ $state == atoms ]]; then
+  _wanted atoms expl atoms compadd ${${(f)"$(_call_program atoms xlsatoms 2> /dev/null)"}#*$'\t'} && ret=0
+else
+  ret=$oret
+fi
+return ret
diff --git a/Completion/X/Type/_x_font b/Completion/X/Type/_x_font
index 134cfdf..a363b27 100644
--- a/Completion/X/Type/_x_font
+++ b/Completion/X/Type/_x_font
@@ -9,7 +9,7 @@ _tags fonts || return 1
 if (( ! $+_font_cache )); then
   typeset -gU _font_cache
 
- _font_cache=( "${(@)^${(@f)$(_call_program fonts xlsfonts)}%%--*}--" )
+ _font_cache=( "${(@)^${(@f)$(_call_program fonts xlsfonts 2> /dev/null)}%%--*}--" )
 fi
 
 _wanted fonts expl font \
-- 
1.7.4-rc1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH: Use state_descr in _x_utils
  2011-05-31 12:47 PATCH: add xprop and xlsatoms completions Mikael Magnusson
@ 2016-08-28 16:28 ` Mikael Magnusson
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2016-08-28 16:28 UTC (permalink / raw)
  To: zsh-workers

I've had a reminder in my Drafts folder to look into state_descr since
2011, finally got around to doing so now. Thanks for adding that :).

---
 Completion/X/Command/_x_utils | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Completion/X/Command/_x_utils b/Completion/X/Command/_x_utils
index 9364235..ebc6aac 100644
--- a/Completion/X/Command/_x_utils
+++ b/Completion/X/Command/_x_utils
@@ -1,6 +1,6 @@
 #compdef xdpyinfo xwininfo xkill xfontsel xfd xev xhost xon xsetroot xwd xwud xrdb xprop xlsatoms xlsclients
 
-local curcontext="$curcontext" state line expl ret=1
+local curcontext="$curcontext" state state_descr line expl ret=1
 
 case "$service" in
 xdpyinfo)
@@ -26,10 +26,10 @@ xprop)
     '-font[display the properties of a font]:font: _x_font' \
     '-len[show at most n bytes of any property]:n' \
     '*-fs[read more property formats from file]:file: _files' \
-    '*-remove[specify an atom to remove from the target window]:atoms:->atoms' \
-    '*-set[specify an atom and a value to set on the target window]:atoms:->atoms:value' \
-    '*-f:atoms:->atoms:format: ::dformat' \
-    '*:atoms:->atoms'
+    '*-remove[specify an atom to remove from the target window]:property atom:->atoms' \
+    '*-set[specify an atom and a value to set on the target window]:property atom:->atoms:value' \
+    '*-f:property atom:->atoms:format: ::dformat' \
+    '*:property atoms:->atoms'
   ;;
 xlsatoms)
   _x_arguments -C \
@@ -199,7 +199,7 @@ xrdb)
 esac && ret=0
 
 if [[ $state == atoms ]]; then
-  _wanted atoms expl atoms compadd ${${(f)"$(_call_program atoms xlsatoms 2> /dev/null)"}#*$'\t'} && ret=0
+  _wanted atoms expl "$state_descr" compadd ${${(f)"$(_call_program atoms xlsatoms 2> /dev/null)"}#*$'\t'} && ret=0
 fi
 
 return ret
-- 
2.8.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-28 16:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-31 12:47 PATCH: add xprop and xlsatoms completions Mikael Magnusson
2016-08-28 16:28 ` PATCH: Use state_descr in _x_utils Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).