Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Changes to xrandr completion
- X-seq: zsh-workers 30987
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Changes to xrandr completion
- Date: Fri, 18 Jan 2013 12:26:57 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1358508418; bh=i4upS08RQD6GSSiH24mU2XWQ8iKk5BpNLIjWiy+vbC0=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Received:In-reply-to:From:References:To:Subject:Date:Message-ID; b=AbaVHuQWQXyyvVQZSqnV9iIitEMj3LB93Zx7J43iz7Vfr5eKWve3uZ2h8XixppHMVn8PEhtCkJnpuEScE7Z0AKMNnKMche6kvcKwS5OznaVfDyujdcFtlUvQw3jM1ucGjJvXlOA2rJEobMrnRrykPD1/GzaE7fIs5u2SXkJThHc=
- In-reply-to: <20130115185001.GM26369@andrew.cmu.edu>
- 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
- References: <20130105191445.6e9bff3d@KR2-ARCH> <20130115185001.GM26369@andrew.cmu.edu>
On 15 Jan, gi1242+zsh@xxxxxxxxx wrote:
> I'd recommend against this! On some (buggy) systems running xrandr polls
> the displays / checks for connected displays, and sometimes blanks the
> screen. (It sometimes takes time too).
>
> On nVidia hardware I'm not sure what will happen.
>
> Any chance you would consider an opt-in version by which xrandr is not
> invoked, unless the user has an zstyle option set?
It doesn't seem to matter on my nVidia hardware. At the very least the
function should use _call_program which does make it possible to disable
it. It's also better to only run the command when it actually is needed.
The patch below does this and also takes Christian Neukirchen's nested
zsh expansions instead of the mix of sed, sort and uniq.
Oliver
Index: Completion/X/Command/_xrandr
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Command/_xrandr,v
retrieving revision 1.4
diff -u -r1.4 _xrandr
--- Completion/X/Command/_xrandr 5 Jan 2013 20:46:46 -0000 1.4
+++ Completion/X/Command/_xrandr 18 Jan 2013 11:19:05 -0000
@@ -1,13 +1,9 @@
#compdef xrandr
-local context state line
-typeset -A opt_args
-local outputs modes expl
-# User configurable. TODO -- styles?
-outputs=($(xrandr|sed -ne 's/^\([^[[:space:]]\+]*\) connected .*$/\1/p'))
-modes=($(xrandr|sed -ne 's/^[[:space:]]\+\([[:digit:]]\+x[[:digit:]]\+\).*$/\1/p'|sort -nr|uniq))
+local curcontext="$curcontext" state line expl
+typeset -A opt_args
-_arguments \
+_arguments -C \
'(-d -display)'{-d,-display}':X display:_x_display' \
'-help[display help]' \
'(-o --orientation)'{-o,--orientation}':rotation:(normal inverted left right 0 1 2 3)' \
@@ -25,18 +21,18 @@
'--fb:size:' \
'--fbmm:size:' \
'--dpi:dpi:' \
- "*--output:output to reconfigure:($outputs)" \
+ "*--output:output to reconfigure:->outputs" \
'*--auto' \
- "*--mode:mode:($modes)" \
+ "*--mode:mode:->modes" \
'*--preferred' \
'*--pos:position:' \
'*--reflect:axes:(normal x y xy)' \
'*--rotate:rotation:(normal inverted left right)' \
- "*--left-of:relative position to:($outputs)" \
- "*--right-of:relative position to:($outputs)" \
- "*--above:relative position to:($outputs)" \
- "*--below:relative position to:($outputs)" \
- "*--same-as:relative position to:($outputs)" \
+ "*--left-of:relative position to:->outputs" \
+ "*--right-of:relative position to:->outputs" \
+ "*--above:relative position to:->outputs" \
+ "*--below:relative position to:->outputs" \
+ "*--same-as:relative position to:->outputs" \
'*--set:property:(Backlight scaling\ mode):value:->value' \
'*--scale:output scaling:' \
'*--transform:transformation matrix:' \
@@ -48,15 +44,25 @@
'--noprimary' \
'*--newmode:name: :clock MHz: :hdisp: :hsync-start: :hsync-end: :htotal: :vdisp: :vsync-start: :vsync-end: :vtotal:' \
'*--rmmode:Mode name:' \
- "*--addmode:output:($outputs):name:" \
- "*--delmode:output:($outputs):name:" \
+ "*--addmode:output:->outputs:name" \
+ "*--delmode:output:->outputs:name" \
&& return 0
-if [[ $state == value ]]; then
+case $state in
+ value)
case $words[CURRENT-1] in
- (scaling* mode)
- _description value expl "output property 'scaling mode'"
- compadd "$@" "$expl[@]" None Full Center Full\ aspect && return 0
- ;;
+ (scaling* mode)
+ _description value expl "output property 'scaling mode'"
+ compadd "$@" "$expl[@]" None Full Center Full\ aspect && return 0
+ ;;
esac
-fi
+ ;;
+ outputs)
+ _wanted outputs expl output compadd \
+ ${(uo)${(M)${(f)"$(_call_program outputs xrandr)"}:#* connected*}%% *} && return 0
+ ;;
+ modes)
+ _wanted modes expl mode compadd \
+ ${(Mun)$(_call_program modes xrandr):#[0-9]##x[0-9]##} && return 0
+ ;;
+esac
Messages sorted by:
Reverse Date,
Date,
Thread,
Author