zsh-workers
 help / color / mirror / code / Atom feed
* [patch] Completion for _deborphan and _xrandr
@ 2017-10-15 18:59 gi1242+zsh
  2017-10-15 21:00 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: gi1242+zsh @ 2017-10-15 18:59 UTC (permalink / raw)
  To: zsh-workers

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

Hi There,

I wrote a rudimentary completion script for deborphan (which probably
belongs with the Debian completion commands).

I also fixed the xrandr completion to separate outputs into two groups
(connected and disconnected). Patch, and whole file attached. If there
is a preferred way to submit this (e.g. by forking a git repository) let
me know and I would be happy to do so.

Best,

Gautam

-- 
Microsoft broke Volkswagen's world record: Volkswagen only made 22
million bugs!

[-- Attachment #2: _xrandr.patch --]
[-- Type: text/x-diff, Size: 726 bytes --]

diff --git a/Completion/X/Command/_xrandr b/Completion/X/Command/_xrandr
index b0851569e..26d8cd082 100644
--- a/Completion/X/Command/_xrandr
+++ b/Completion/X/Command/_xrandr
@@ -58,8 +58,11 @@ case $state in
     esac
   ;;
   outputs)
-    _wanted outputs expl output compadd \
-        ${(uo)${(M)${(f)"$(_call_program outputs xrandr)"}:#* connected*}%% *} && return 0
+    local -a xrandr_output=(${(f)"$(_call_program outputs xrandr)"})
+    _alternative \
+	'connected:connected outputs:('${(j: :)${(uo)${(M)xrandr_output:#* connected*}%% *}}')' \
+	'disconnected:disconnected outputs:('${(j: :)${(uo)${(M)xrandr_output:#* disconnected*}%% *}}')' \
+	&& return 0
   ;;
   modes)
     _wanted modes expl mode compadd \

[-- Attachment #3: _deborphan --]
[-- Type: text/plain, Size: 2298 bytes --]

#compdef deborphan

local keep=/var/lib/deborphan/keep
_arguments : \
  {--help,-h}'[help]' \
  {--status-file,-f}'[statusfile]:file:_files' \
  {--version,-v}'[version]' \
  {--show-deps,-d}'[show dependencies for packages that have them]' \
  {--show-priority,-P}'[show priority of packages found]' \
  {--show-section,-s}'[show the sections the packages are in]' \
  --no-show-section'[do not show sections]' \
  {--show-size,-z}'[show installed size of packages found]' \
  {--all-packages,-a}'[compare all packages, not just libs]' \
  {--exclude,-e}'[work as if packages in LIST were not installed]:LIST:' \
  {--force-hold,-H}'[Ignore hold flags.]' \
  {--nice-mode,-n}'[Disable checks for "recommends" and "suggests".]' \
  --ignore-recommends'[Disable checks for recommends.]' \
  --ignore-suggests'[Disable checks for "suggests".]' \
  {--priority,-p}'[PRIOR  Select only packages with priority >= PRIOR.]:PRIOR:' \
  --find-config'[Find "orphaned" configuration files.]' \
  --libdevel'[Search in libdevel in addition to libs and oldlibs.]' \
  {--add-keep,-A}'[PKGS.. Never report PKGS.]:*:package:_deb_packages installed' \
  {--keep-file,-k}'[Use FILE to get/store info about kept packages.]:file:_files' \
  {--list-keep,-L}'[List the packages that are never reported.]' \
  {--del-keep,-R}"[PKGS.. Remove PKGS from the 'keep' file.]:*:package:_values package $(< $keep)" \
  {--zero-keep,-Z}'[Remove all packages from the "keep" file.]' \
  --guess-common'[Try to report common packages.]' \
  --guess-data'[Try to report data packages.]' \
  --guess-debug'[Try to report debugging libraries.]' \
  --guess-dev'[Try to report development packages.]' \
  --guess-doc'[Try to report documentation packages.]' \
  --guess-dummy'[Try to report dummy packages.]' \
  --guess-kernel'[Try to report kernel modules.]' \
  --guess-interpreters'[Try to report interpreter libraries.]' \
  --guess-mono'[Try to report mono libraries.]' \
  --guess-perl'[Try to report perl libraries.]' \
  --guess-pike'[Try to report pike libraries.]' \
  --guess-python'[Try to report python libraries.]' \
  --guess-ruby'[Try to report ruby libraries.]' \
  --guess-section'[Try to report libraries in wrong sections.]' \
  --guess-all'[Try all of the above.]' \
  --guess-only'[Use --guess options only.]'

[-- Attachment #4: _xrandr --]
[-- Type: text/plain, Size: 2464 bytes --]

#compdef xrandr

local curcontext="$curcontext" state line expl
typeset -A opt_args

_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)' \
  '(-q --query)'{-q,--query}'[display current state]' \
  '(-s --size)'{-s,--size}':size:' \
  '(-r --rate --refresh)'{*-r,*--rate,*--refresh}':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' \
  '--nograb' \
  '(--prop --properties)'{--prop,--properties}'[display the contents of properties for each output]' \
  '--fb:size:' \
  '--fbmm:size:' \
  '--dpi:dpi:' \
  "*--output:output to reconfigure:->outputs" \
  '*--auto' \
  "*--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" \
  '*--set:property:(Backlight scaling\ mode):value:->value' \
  '*--scale:output scaling:' \
  '*--transform:transformation matrix:' \
  '*--off[disable the output]' \
  '*--crtc:crtc to use:' \
  '*--panning:panning:' \
  '*--gamma:r\:g\:b:' \
  '*--primary' \
  '--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" \
  && return 0

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
	    ;;
    esac
  ;;
  outputs)
    local -a xrandr_output=(${(f)"$(_call_program outputs xrandr)"})
    _alternative \
	'connected:connected outputs:('${(j: :)${(uo)${(M)xrandr_output:#* connected*}%% *}}')' \
	'disconnected:disconnected outputs:('${(j: :)${(uo)${(M)xrandr_output:#* disconnected*}%% *}}')' \
	&& return 0
  ;;
  modes)
    _wanted modes expl mode compadd \
        ${(Mun)$(_call_program modes xrandr):#[0-9]##x[0-9]##} && return 0
  ;;
esac

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

* Re: [patch] Completion for _deborphan and _xrandr
  2017-10-15 18:59 [patch] Completion for _deborphan and _xrandr gi1242+zsh
@ 2017-10-15 21:00 ` Oliver Kiddle
  2017-10-16  0:53   ` gi1242+zsh
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2017-10-15 21:00 UTC (permalink / raw)
  To: gi1242+zsh, zsh-workers

gi1242+zsh@gmail.com wrote:
>
> I wrote a rudimentary completion script for deborphan (which probably
> belongs with the Debian completion commands).

Thanks for this.

> I also fixed the xrandr completion to separate outputs into two groups
> (connected and disconnected). Patch, and whole file attached. If there

Is it useful to complete a disconnected output then? If it's only
relevant with some options then we could have separate states for
completing all vs. only connected outputs.

> is a preferred way to submit this (e.g. by forking a git repository) let
> me know and I would be happy to do so.

The preferred way to submit this is by posting a patch, exactly as you
have done.

I've got a couple of minor comments and suggestions on the function:

> +    _alternative \
> +	'connected:connected outputs:('${(j: :)${(uo)${(M)xrandr_output:#* connected*}%% *}}')' \
> +	'disconnected:disconnected outputs:('${(j: :)${(uo)${(M)xrandr_output:#* disconnected*}%% *}}')' \
> +	&& return 0

The normal convention is for the group descriptions to be singular: they
describe what comes on the command line rather than the matches
collectively. So, "connected output" rather than "connected outputs".

> local keep=/var/lib/deborphan/keep
> _arguments : \
>   {--help,-h}'[help]' \
>   {--status-file,-f}'[statusfile]:file:_files' \

The description here is rather terse.

>   {--exclude,-e}'[work as if packages in LIST were not installed]:LIST:' \

I'm guessing that LIST here has come from the --help output. The
description's inclusion of "LIST" makes less sense without corresponding
text saying something like [ --exclude LIST ]. The word "specify" is
often used when rewording these. Also, is it not perhaps valid to
complete a list of installed packages here. So:

  {--exclude,-e}'[work as if specified packages were not installed]:package:_sequence _deb_packages - installed' \

That is assuming a comma-separated list. If deborphan allows you to pass
  -e pkg1 -e pkg2
Then you need to prefix the _arguments spec with a *:
  \*{--exclude,-e}'[....

>   {--force-hold,-H}'[Ignore hold flags.]' \

This description is inconsistent with the earlier ones. Our normal
convention is to neither capitalise the first word nor finish with a
full stop.

>   {--priority,-p}'[PRIOR  Select only packages with priority >= PRIOR.]:PRIOR:' \

The same comment I made about LIST applies here and in some later
places. Is there a default priority. It can be good to provide hints,
perhaps:
   :priority (1-100) [50]'
I'm assuming the priorities are just numbers.

>   {--del-keep,-R}"[PKGS.. Remove PKGS from the 'keep' file.]:*:package:_values package $(< $keep)" \

Is _values really needed here or would compadd do the job?

I'd also be inclined to try to avoid it dumping error messages to the
terminal if the $keep file doesn't exist. Perhaps:
  keep=( /var/lib/deborphan/keep(N) /dev/null)
  ..
  compadd $(<$keep[1]})

Thanks again.

Oliver


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

* Re: [patch] Completion for _deborphan and _xrandr
  2017-10-15 21:00 ` Oliver Kiddle
@ 2017-10-16  0:53   ` gi1242+zsh
  0 siblings, 0 replies; 3+ messages in thread
From: gi1242+zsh @ 2017-10-16  0:53 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

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

On Sun, Oct 15, 2017 at 11:00:24PM +0200, Oliver Kiddle wrote:

>> I also fixed the xrandr completion to separate outputs into two groups
>> (connected and disconnected). Patch, and whole file attached. If there
> 
> Is it useful to complete a disconnected output then? If it's only
> relevant with some options then we could have separate states for
> completing all vs. only connected outputs.

I use it :). Often, when I disconnect an output, but then haven't told
X about it, I need to do

    xrandr --output blah --auto (or --off)

I didn't think it was worth the added complexity to have it done
differently for --left-of etc.

Thanks for your suggestions about deborphan! I think I got them all and
am a new version with everything incorporated.

Best,

Gautam

-- 
A Windows user spends 1/3 of his life sleeping, 1/3 working, 1/3
waiting.

[-- Attachment #2: _deborphan --]
[-- Type: text/plain, Size: 2346 bytes --]

#compdef deborphan

local keep=(/var/lib/deborphan/keep(N) /dev/null)
_arguments : \
  {--help,-h}'[help]' \
  {--status-file,-f}'[specify status file]:file:_files' \
  {--version,-v}'[version]' \
  {--show-deps,-d}'[show dependencies for packages that have them]' \
  {--show-priority,-P}'[show priority of packages found]' \
  {--show-section,-s}'[show the sections the packages are in]' \
  --no-show-section'[do not show sections]' \
  {--show-size,-z}'[show installed size of packages found]' \
  {--all-packages,-a}'[compare all packages, not just libs]' \
  {--exclude,-e}'[work as if specified packages were not installed]:packages:_sequence _deb_packages - avail' \
  {--force-hold,-H}'[ignore hold flags]' \
  {--nice-mode,-n}'[disable checks for "recommends" and "suggests"]' \
  --ignore-recommends'[disable checks for recommends]' \
  --ignore-suggests'[disable checks for "suggests"]' \
  {--priority,-p}'[select only packages with at least specified priority]:priority:' \
  --find-config'[find "orphaned" configuration files]' \
  --libdevel'[search in libdevel in addition to libs and oldlibs]' \
  {--add-keep,-A}'[packages to never report]:*:package:_deb_packages installed' \
  {--keep-file,-k}'[file to get/store info about kept packages]:file:_files' \
  {--list-keep,-L}'[list the packages that are never reported]' \
  {--del-keep,-R}"[packages to remove from the 'keep' file]:*:package:compadd -X 'kept package' $(< $keep[1])" \
  {--zero-keep,-Z}'[remove all packages from the "keep" file]' \
  --guess-common'[try to report common packages]' \
  --guess-data'[try to report data packages]' \
  --guess-debug'[try to report debugging libraries]' \
  --guess-dev'[try to report development packages]' \
  --guess-doc'[try to report documentation packages]' \
  --guess-dummy'[try to report dummy packages]' \
  --guess-kernel'[try to report kernel modules]' \
  --guess-interpreters'[try to report interpreter libraries]' \
  --guess-mono'[try to report mono libraries]' \
  --guess-perl'[try to report perl libraries]' \
  --guess-pike'[try to report pike libraries]' \
  --guess-python'[try to report python libraries]' \
  --guess-ruby'[try to report ruby libraries]' \
  --guess-section'[try to report libraries in wrong sections]' \
  --guess-all'[try all of the above]' \
  --guess-only'[use --guess options only]'

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

end of thread, other threads:[~2017-10-16  0:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-15 18:59 [patch] Completion for _deborphan and _xrandr gi1242+zsh
2017-10-15 21:00 ` Oliver Kiddle
2017-10-16  0:53   ` gi1242+zsh

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).