zsh-users
 help / color / mirror / code / Atom feed
From: Jan Eike von Seggern <jan.eike.von.seggern@desy.de>
To: zsh-users@zsh.org
Subject: xrandr completion (was Re: Caching variables during completion)
Date: Mon, 18 Mar 2013 18:34:34 +0100	[thread overview]
Message-ID: <5147502A.70603@desy.de> (raw)
In-Reply-To: <511CA274.4060702@desy.de>

[-- Attachment #1: Type: text/plain, Size: 1193 bytes --]

Hi,

attached is my slightly improved completion for xrandr:

It completes only connected outputs and only the available modes for 
each output.

Best
Eike


On 02/14/2013 09:38 AM, Jan Eike von Seggern wrote:
> Thanks a lot Bart and Peter!
>
> Using HISTNO should be working.
>
> BTW: I played around with _store_cache/_retrieve_cache but I could not
> get it working because I didn't now how to retrieve an associated array
> from the cache (not to mention that it's not fitting my need anyways).
>
> Best
> Eike
>
>
> On 02/14/2013 01:39 AM, Bart Schaefer wrote:
>> On Feb 13,  8:30pm, Peter Stephenson wrote:
>> }
>> } Bart Schaefer <schaefer@brasslantern.com> wrote:
>> } > zstyle ':completion:*' completer _xrcache _oldlist _expand
>> _complete # etc.
>> }
>> } I don't see why you couldn't put that inside the completion function
>> } that needs the cache
>>
>> True, you could put it in the completion function, but what if there's
>> more than one completion function that wants to share the same cache?
>>
>> Which reminds me that I've never really bothered to understand how the
>> _store_cache/_retrieve_cache stuff is supposed to work.  I suspect it
>> would be overkill here.
>>

[-- Attachment #2: _xrandr --]
[-- Type: text/plain, Size: 3544 bytes --]

#compdef xrandr
local context state state_descr line
typeset -A opt_args
local expl
local outputs

# TODO: This creates a global variable to cache the available outputs. 
if [[ $_xr_HISTNO != $HISTNO ]];
then
  _xr_HISTNO=$HISTNO
  typeset -gA _xr_modes 
  _xr_modes=()
  local last_output l
  for l in ${(f)"$(xrandr -q)"}; do
    l=${(z)l}
    if [[ $l[2] == "connected" ]]; then
      last_output=$l[1]
    elif [[ $l[2] == "disconnected" ]]; then
      last_output=""
    elif [[ -n $last_output ]]; then
      _xr_modes[$last_output]="$_xr_modes[$last_output]${_xr_modes[$last_output]+ }$l[1]"
    fi
  done
fi
outputs=${(k)_xr_modes}

_arguments \
  '(-d -display)'{-d,-display}'[X display to use]:X display:_x_display' \
  '-help[display help]' \
  '(-o --orientation)'{-o,--orientation}'[orientation of screen]:rotation:(normal inverted left right 0 1 2 3)' \
  '(-q --query)'{-q,--query}'[display current state]' \
  '(-s --size)'{-s,--size}'[set screen size]:size:' \
  '(-r --rate --refresh)'{*-r,*--rate,*--refresh}'[set refresh rate]:target refresh rate:' \
  '(-v --version)'{-v,--version}'[display version]' \
  '-x[reflect across X axis]' \
  '-y[reflect across Y axis]' \
  '--screen:X screen number' \
  '--verbose[be more verbose]' \
  '--dryrun[make no changes]' \
  "--nograb[don\'t grab screen]" \
  '(--prop --properties)'{--prop,--properties}'[display the contents of properties for each output]' \
  '--fb[configure screen size]:size:' \
  '--fbmm[configure physical screen size]:size:' \
  '--dpi[configure DPI]:dpi:' \
  "*--output[configure output]:output to reconfigure:($outputs)" \
  '*--auto[select preferred mode]' \
  "*--mode[select mode for output]:output mode:->mode" \
  '*--preferred[select preferred mode]' \
  '*--pos[position output]:position:' \
  '*--reflect[reflect across axes]:axes:(normal x y xy)' \
  '*--rotate[rotate output]:rotation:(normal inverted left right)' \
  "*--left-of[position output]:relative position to:($outputs)" \
  "*--right-of[position output]:relative position to:($outputs)" \
  "*--above[position output]:relative position to:($outputs)" \
  "*--below[position output]:relative position to:($outputs)" \
  "*--same-as[position output]:relative position to:($outputs)" \
  '*--set[set property]:property:(Backlight scaling\ mode):value:->value' \
  '*--scale[scale output]:output scaling XxY:' \
  '*--transform[transform output]:transformation matrix:' \
  '*--off[disable the output]' \
  '*--crtc:crtc to use:' \
  '*--panning[enable panning]:panning:' \
  '*--gamma:r\:g\:b:' \
  '*--primary[select output as primary]' \
  '--noprimary' \
  '*--newmode[add new mode line]:name: :clock MHz: :hdisp: :hsync-start: :hsync-end: :htotal: :vdisp: :vsync-start: :vsync-end: :vtotal:' \
  '*--rmmode[remove mode line]:Mode name:' \
  "*--addmode[add new mode to output]:output:($outputs):name:" \
  "*--delmode[remove mode from output]:output:($outputs):name:" \
  && return 0

if [[ $state == value ]]; then
    case $words[CURRENT-1] in
	(scaling* mode)
	    _description value expl "output property 'scaling mode'"
	    compadd "$@" "$expl[@]" None Full Center Full\ aspect && return 0
	    ;;
    esac
elif [[ $state == mode ]]; then
    local i=1 last_output
    while (( CURRENT - i > 2 )); do
        if [[ $words[CURRENT-1-i] == "--output" ]]; then
            last_output=$words[CURRENT-i]
            break
        fi
        (( i += 1 ))
    done
    _description -V mode expl "output mode"
    compadd "$@" "$expl[@]" ${(z)_xr_modes[$last_output]} && return 0
fi

  reply	other threads:[~2013-03-18 17:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-13  9:44 Caching variables during completion Jan Eike von Seggern
2013-02-13 17:39 ` Bart Schaefer
2013-02-13 20:30   ` Peter Stephenson
2013-02-14  0:39     ` Bart Schaefer
2013-02-14  8:38       ` Jan Eike von Seggern
2013-03-18 17:34         ` Jan Eike von Seggern [this message]
2013-03-18 21:14           ` xrandr completion (was Re: Caching variables during completion) Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5147502A.70603@desy.de \
    --to=jan.eike.von.seggern@desy.de \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).