zsh-workers
 help / color / mirror / code / Atom feed
From: Maximilian Bosch <maximilian@mbosch.me>
To: zsh-workers@zsh.org
Subject: Re: PATCH: search XDG_DATA_DIRS in _setxkbmap completion
Date: Wed, 19 Sep 2018 22:36:17 +0200	[thread overview]
Message-ID: <20180919203617.u7qqocenjurq73l3@hauptschuhle> (raw)
In-Reply-To: <1537299172.1213094.1512566000.19322CCD@webmail.messagingengine.com>

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

> Depends on how empty elements should be handled.  In some contexts an
> empty element means "look in the current working directory", and I
> wasn't sure how the XDG spec defines this case.  It's not a blocker but
> it would be nice to get this right while we're here.

I had a look at the XDG specification[1], unfortunately it doesn't
mention the case of empty search path entries. Do you know what's the
preferred default behavior?

Again, thanks a lot for your feedback, I've implemented your
suggestions.

Best regards,

Maximilian

[1] https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

diff --git a/Completion/X/Command/_setxkbmap b/Completion/X/Command/_setxkbmap
index f7310ecdd..486268ed7 100644
--- a/Completion/X/Command/_setxkbmap
+++ b/Completion/X/Command/_setxkbmap
@@ -9,10 +9,12 @@ _setxkbmap() {
     setopt extendedglob
 
     # xkb files may be in different places depending on system
-    local dir sourcedir
-    for dir in /usr/lib/X11/xkb /usr/share/X11/xkb; do
-        if [ -d $dir ] ; then
-           sourcedir=$dir
+    local dir sourcedir fullname
+    local -a searchdirs=(${XDG_DATA_HOME:-~/.local/share} ${(s.:.)XDG_DATA_DIRS:-/usr/lib:/usr/share:/usr/local/lib:/usr/local/share})
+    for dir in $searchdirs; do
+        fullname="$dir/X11/xkb"
+        if [ -d $fullname ] ; then
+           sourcedir=$fullname
            break
         fi
     done

On Tue, Sep 18, 2018 at 07:32:52PM +0000, Daniel Shahaf wrote:
> Maximilian Bosch wrote on Tue, 18 Sep 2018 21:05 +0200:
> > Thanks a lot for your feedback!
> > 
> > I use ZSH as interactive shell quite excessively, but as you might've
> > noticed, I'm not that experienced with ZSH scripting, so thanks for
> > your patience :D
> > 
> 
> You're welcome.
> 
> > I applied your suggestions and re-checked the patch.
> > 
> > > How should empty array elements in XDG_DATA_DIRS be handled?  E.g.,
> > > XDG_DATA_DIRS=/foo:/bar::/baz ?
> > 
> > Isn't this handled by `[ -d $fullname ]`?
> 
> Depends on how empty elements should be handled.  In some contexts an
> empty element means "look in the current working directory", and I
> wasn't sure how the XDG spec defines this case.  It's not a blocker but
> it would be nice to get this right while we're here.
>  
> > +++ b/Completion/X/Command/_setxkbmap
> > @@ -9,10 +9,12 @@ _setxkbmap() {
> >      setopt extendedglob
> >  
> >      # xkb files may be in different places depending on system
> > -    local dir sourcedir
> > -    for dir in /usr/lib/X11/xkb /usr/share/X11/xkb; do
> > -        if [ -d $dir ] ; then
> > -           sourcedir=$dir
> > +    local dir sourcedir fullname
> > +    local searchdirs="${XDG_DATA_DIRS:-/usr/lib:/usr/share:/usr/local/lib:/usr/local/share}:${XDG_DATA_HOME:-~/.local/share}"
> 
> Two tweaks here:
> 
> 1. XDG_DATA_HOME should be listed before XDG_DATA_DIRS, according to
>    the XDG spec.
> 
> 2. I'd use an array, both because it's cleaner and in case
>    $XDG_DATA_HOME contains colons (not likely, but there's no
>    maintenance cost to supporting that).  Thus:
> 
>     local -a searchdirs=( ${XDG_DATA_HOME:-...} ${(s.:.)XDG_DATA_DIRS:-...} )
>     for dir in $searchdirs; do
> 
> > +    for dir in ${(s.:.)searchdirs}; do
> > +        fullname="$dir/X11/xkb"
> > +        if [ -d $fullname ] ; then
> > +           sourcedir=$fullname
> >             break
> >          fi
> >      done
> 
> Cheers,
> 
> Daniel

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2018-09-19 20:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-18 12:49 Maximilian Bosch
2018-09-18 16:10 ` Daniel Shahaf
2018-09-18 19:05   ` Maximilian Bosch
2018-09-18 19:32     ` Daniel Shahaf
2018-09-19 20:36       ` Maximilian Bosch [this message]
2018-09-19 21:30         ` Daniel Shahaf
2018-09-19  4:53 TS
2018-09-19 14:29 ` Daniel Shahaf
2018-09-19 19:53   ` TS

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=20180919203617.u7qqocenjurq73l3@hauptschuhle \
    --to=maximilian@mbosch.me \
    --cc=zsh-workers@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).