SetEnv timing

Suppose I have the following piece of code:

[code]addtofunc menu-from-dir

  • I piperead ‘for i in $0/*; do
    b=basename $i && \
    if [ “$b” != “main” ]; then
    echo function cap-first-ltr $b t &&
    echo echo $[t] &&
    echo -e addtomenu mnu-$[menuname] $[t] popup mnu-$b;
    fi; done’[/code]

where $[menuname] is defined elsewhere and cap-first-ltr captitalizes the first letter of a string and stores it in a variable, in this case t. The code is supposed to make every filename in a directory an entry in a menu (excluding the file called “main”).

I am curious about the t. Suppose the files in the directory of concern are named “file1” … “filen”. The result of this code is a menu with “Filen” in every entry, which makes me wonder when t is looked at by Fvwm. It appears to be substituted for after the loop finishes. Anyone willing to knock the scales from my eyes?

To my knowledge, Fvwm just gets the output of the shell being executed by PipeRead after it has finished. Ie Fvwm doesn’t look or care or know about “t”, your shell does.

Apologies, I wasn’t clear. The t variable is a variable declared, in cap-first-ltr, using Fvwm’s SetEnv, so Fvwm must know about it. Sheesh, most important point, the hinge point, and I forget to make it explicit. I don’t think I need to post cap-first-ltr, but if more is needed, even this, let me know.

Oh, now I see. I was wondering what the “t” was doing there all alone :slight_smile:

OK, so the way I see it: the function containing the SetEnvs doesn’t get called during the PipeRead. When they’re actually evaluated is during, say, MissingSubmenuAction/DynamicPopupAction or whatever you are using for displaying the menu. About the order or timing of that, I don’t know.

The behavior of this function has some other strange behavior when used in two menus. In addition to the directory full of “fileks” (which for testing purposes is actually full of “file1” through “file6”), I made a directory containing “item1” through “item6”. Each of these directories has in them a file named “main” that calls menu-from-dir with dynamicpopupaction. So for instance, the dir of “files”, called “file” has a “main” that has something like the following:

[code]destroymenu mnu-file
addtomenu mnu-file “File” title top

  • dynamicpopupaction function menu-from-dir $[filedir][/code]

where $[filedir] is just the path to the this directory holding all these “files”.

When I start Fvwm from the console with startx and first pass over one of these faux menu items, a submenu pops up whose entries are all “0”. Say the first one I pass over is “File”. Its items are all “0”. When I pass over “Item”, its items are all “File6”. If I again pass over “File”, the entries are all “Item6”. Bouncing back and forth between the two menus in this way, I see the entries of one as single entries of the other (the single entries that happen to be the last in ascending ascii order within their respecitve directories).

I’m not quite sure what to make of this, though it’s so consistent it must be an intended consequence of the code, at least version 2.5.13 of Fvwm. Explanations?

Well, I dunno about explanations, but why don’t you just use fvwm-menu-directory ? I can try and help you with the thing you are trying to get working, but not without actually seeing all of the relevant code. If you are using PipeRead, then it is your shell outputting the info to fvwm, so what you want to do is first ensure that the output is valid before passing it to fvwm.

I suspect you’re suffering from fvwm->shell expansion problems in that the reason you’re seeing item6 all the time is because the env var is being expanded too early for the conditional command acting upon it. Hence this is why you see:

Current (foo) Next (bar) Echo $$[baz]

If you actually supplied the function in its entirety (the only real bit of information that would be useful), maybe I can help further.

– Thomas Adam

The cap-first-ltr function is just this:

[code]addtofunc cap-first-ltr

  • I piperead 'echo setenv $1
    echo $0 | cut -c1 | tr a-z A-Z``echo $0 | cut -c2-'[/code]