Re: [dev] [dmenu] dmenu_run improvements

From: lolilolicon <lolilolicon_AT_gmail.com>
Date: Sun, 24 Jul 2011 18:41:30 +0800

On Sun, Jul 24, 2011 at 5:06 PM, Anselm R Garbe <garbeam_AT_gmail.com> wrote:
> Nevertheless, I can see that script should be improved (not using the
> ls -dt invocation), but I prefer the back ticks (even if $(..) is
> POSIX, there were a couple of issues in the past that I barely
> remember) and I want explicit test calls, I don't like the [ ... ]
> syntax sugar.
>
> Thanks,
> Anselm
>
>

Fine, as long as it doesn't break anything, I can live with these two
backticks.
Since I'm the thread starter, may I conclude this with the following?

#!/bin/sh
CACHE=${XDG_CACHE_HOME:-$HOME/.cache}/dmenu_run
(
        IFS=:
        gen_cache() {
                lsx $PATH | LC_COLLATE=C sort -u > "$CACHE"
        }
        if test -e "$CACHE"; then
                for path in $PATH; do
                        if test "$path" -nt "$CACHE"; then
                                gen_cache
                                break
                        fi
                done
        else
                mkdir -p "${CACHE%/*}"
                gen_cache
        fi
)
cmd=`dmenu "$@" < "$CACHE"` && eval exec "$cmd"

NOTE:
The (subshell) is used so the declarations won't get inherented, but
the user still has access to the $CACHE and $cmd environments.
Received on Sun Jul 24 2011 - 12:41:30 CEST

This archive was generated by hypermail 2.2.0 : Sun Jul 24 2011 - 12:48:03 CEST