From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43490-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id ec31b591 for ; Tue, 18 Sep 2018 19:05:38 +0000 (UTC) Received: (qmail 13988 invoked by alias); 18 Sep 2018 19:05:26 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43490 Received: (qmail 17285 invoked by uid 1010); 18 Sep 2018 19:05:26 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr1-f68.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.221.68):SA:0(-1.2/5.0):. Processed in 2.385144 secs); 18 Sep 2018 19:05:26 -0000 X-Envelope-From: maximilian.bosch.27@gmail.com X-Qmail-Scanner-Mime-Attachments: |signature.asc| X-Qmail-Scanner-Zip-Files: | X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=deYpp3AFTR75moi5ivO8GiUVrmnK5dnNhdJq4HX4rVY=; b=XUD4fXFfRTk9Dc+W8cSuEMfbd/HG15MryVPSzVNnrzjC1QfTvk6COOO+Fj7Lch8TUE LFa82pC8rdeHDkeWnHYwMUGlw6v63rr9GvuZvwMAthIdot0I4HQx134LS5TzQ2Wz/2dz 0LFSCDB9+LD7DdUXgzSHOGxRx7SOhEEaR6yHT+XBsRZm3hKHMMcydAyX5vvYa7RJrE9j EXY1LNdV64LWyQO9tFwe4zD2Z94XFCnuju8dIjYYNhBeNN/FBqHSJrG2BtSWnH9BmIcI i92EjNWwsdsQySda1J9gdB5ChAyflVhvkbRjoOoLG+yFGXULHQcWMR2p8wFbnsdYfT5x Ajag== X-Gm-Message-State: APzg51DFd3ZNSHAaWoNgyGZiVsYqEdgqM+jL6xQPI+NHaWBPaI4O0i0N XeVQ0bSIGFeQMBocL4Q9Qs6jD+Wa X-Google-Smtp-Source: ANB0VdarnWFnuJ5YwPH3UfQQ2X+p3DryQNzUDod7kGc0G2DXQbtscgEbZxzZLzU5u/TUe6B1sGVmzw== X-Received: by 2002:adf:ff0b:: with SMTP id k11-v6mr26563180wrr.15.1537297519349; Tue, 18 Sep 2018 12:05:19 -0700 (PDT) Date: Tue, 18 Sep 2018 21:05:16 +0200 From: Maximilian Bosch To: zsh-workers@zsh.org Subject: Re: PATCH: search XDG_DATA_DIRS in _setxkbmap completion Message-ID: <20180918190516.2w3tyiugdmx6wzqw@hauptschuhle> References: <20180918124951.4nbyjhbuqnkioqrt@hauptschuhle> <1537287030.1158541.1512325000.0C43F9DE@webmail.messagingengine.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eagz4u67f7uicfkd" Content-Disposition: inline In-Reply-To: <1537287030.1158541.1512325000.0C43F9DE@webmail.messagingengine.com> User-Agent: NeoMutt/20180716 --eagz4u67f7uicfkd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 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=3D/foo:/bar::/baz ? Isn't this handled by `[ -d $fullname ]`? With best regards, Maximilian diff --git a/Completion/X/Command/_setxkbmap b/Completion/X/Command/_setxkb= map index f7310ecdd..a98a07a7b 100644 --- a/Completion/X/Command/_setxkbmap +++ b/Completion/X/Command/_setxkbmap @@ -9,10 +9,12 @@ _setxkbmap() { setopt extendedglob =20 # 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=3D$dir + local dir sourcedir fullname + local searchdirs=3D"${XDG_DATA_DIRS:-/usr/lib:/usr/share:/usr/local/li= b:/usr/local/share}:${XDG_DATA_HOME:-~/.local/share}" + for dir in ${(s.:.)searchdirs}; do + fullname=3D"$dir/X11/xkb" + if [ -d $fullname ] ; then + sourcedir=3D$fullname break fi done On Tue, Sep 18, 2018 at 04:10:30PM +0000, Daniel Shahaf wrote: > Maximilian Bosch wrote on Tue, 18 Sep 2018 14:49 +0200: > > this patch searches in $XDG_DATA_DIRS for `/share/X11/xkb` > > rather than using `/usr/lib` and `/usr/share`. > >=20 > > This is helpful on distros such as NixOS which don't adopt the FHS[1][2= ]. > >=20 > > [1] https://github.com/NixOS/nixpkgs/pull/46152#issuecomment-421755892 > > [2] https://github.com/NixOS/nixpkgs/issues/46025 > >=20 > > diff --git a/Completion/X/Command/_setxkbmap b/Completion/X/Command/_se= txkbmap > > index f7310ecdd..b3f8b1a46 100644 > > --- a/Completion/X/Command/_setxkbmap > > +++ b/Completion/X/Command/_setxkbmap > > @@ -10,12 +10,18 @@ _setxkbmap() { > > =20 > > # 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=3D$dir > > + setopt sh_word_split > > + local IFS=3D: > > + for dir in $XDG_DATA_DIRS; do > > + fullName=3D"$dir/X11/xkb" > > + if [ -d $fullName ] ; then > > + sourcedir=3D$fullName > > break > > fi > > done > > + unset IFS > > + unsetopt sh_word_split > > + >=20 > Thanks for the patch. It's short, but there's a lot to say about it. >=20 > 1. Shouldn't there be a fallback when $XDG_DATA_DIRS is unset? Such as > the two hardcoded paths the patch is removing? Maybe also /usr/local > equivalents of them. >=20 > 2. Instead of setting + unsetting wordsplit and IFS it will be more > idiomatic and more robust to do 'for dir in ${(s.:.)XDG_DATA_DIRS}'. >=20 > 3. fullName should be made local (and not named in CamelCase). >=20 > 4. ${XDG_DATA_HOME:-~/.local/share} should be examined too. >=20 > How should empty array elements in XDG_DATA_DIRS be handled? E.g., > XDG_DATA_DIRS=3D/foo:/bar::/baz ? >=20 > It might be good to add a helper function that does the XDG_DATA_{DIRS,HO= ME} > dance. It would be reusable and allow for extensibility. >=20 > Cheers, >=20 > Daniel >=20 > > [ -d $sourcedir ] || return 1 > > =20 > > local -a arguments > > Email had 1 attachment: > > + signature.asc > > 1k (application/pgp-signature) --eagz4u67f7uicfkd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEPg3TILK+tBEQDaTVCR2/TR/Ea44FAluhTGkACgkQCR2/TR/E a46YPQf/ak4GGkZAlLEhSSJqCNFtdyKLg8ipxsbnhvRqaAqjtS9LlnA7K375i2vS VcbJK74jpCk/39O6ES0yp2if9W3dJxyt55OD+bbsS7RocM1mI7QbwCtbqWGrCh/r 3HVEFvZRh2Cq31XYRihfV/OR99pf342uYu1N6mc4/PuizbFImz7VawI0XlMIKzA7 YhFTI5Wrc9onQ1Ao6E3bZgVmnxg4dxVsAqWuYkUb4GEnyL59nFWJ0wMtcjAIp6X6 B/YQbNegjxNf/EpLZ4dF886UU+Ysv61KmGU8Riidb98K3Wn4G/VX7A6jsGFeg4n0 xWY/2TAUnC1C3UxB//suvF8zTc89/Q== =MrO7 -----END PGP SIGNATURE----- --eagz4u67f7uicfkd--