Re: [dev] [dmenu] dmenu_run improvements

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

On Sun, Jul 24, 2011 at 4:39 PM, Anselm R Garbe <garbeam_AT_gmail.com> wrote:
> On 24 July 2011 06:34, Dave Reisner <d_AT_falconindy.com> wrote:
>> On Sun, Jul 24, 2011 at 12:35:19PM +0800, lolilolicon wrote:
>>> dmenu_run doesn't really run the user input as a shell command line.
>>> For instance, run dmenu_run from a terminal, then in the menu type:
>>>
>>>   echo hello\ world
>>>
>>> The terminal output is "hello\ world" instead of "hello world".
>>>
>>> `eval' solves the problem, but when it comes to eval, I can't really
>>> be sure, so please point out the possible errors/risks.
>>
>> Assuredly the least of the evils in this script -- the eval is
>> necessary. More noteworthy is the parsing of ls here, which can easily
>> be refactored out and still be /bin/sh compat. It also explodes on first
>> run, and then there's the needless invocation of mkdir every time the
>> cache is regenerated. suckless could suck a lot less at shell scripting.
>> dmenu_run has gone through several iterations of bad and worse.
>>
>> d
>>
>>
>> #!/bin/sh
>>
>> CACHE=${XDG_CACHE_HOME:-"$HOME/.cache"}/dmenu_run
>> IFS=:
>> LC_COLLLATE=C
>>
>> gencache() {
>>  lsx $PATH | sort -u >"$CACHE"
>> }
>>
>> if [ ! -e "$CACHE" ]; then
>>  mkdir -p "${CACHE%/*}"
>>  gencache
>> fi
>>
>> for path in $PATH; do
>>  if [ "$path" -nt "$CACHE" ]; then
>>    gencache
>>    break
>>  fi
>> done
>
> Am I right that the previous loop runs gencache n times, under the
> assumption that each path component contains newer files?
>
> Kind regards,
> Anselm
>
>

No, note the `break'.
Received on Sun Jul 24 2011 - 10:57:41 CEST

This archive was generated by hypermail 2.2.0 : Sun Jul 24 2011 - 11:00:09 CEST