Am 10.12.2013 07:54, schrieb lee:> Thomas Funk <t.funk...@googlemail.com> 
writes:
> 
>> 2013/12/5 James Griffin <j...@kontrol.kode5.net>:
>>> I've got a load of functions defined in my configuration file using
>>> DestroyFunc/AddToFunc. What I would like to know, is how can use
>>> these functions to test if the application in question is already
>>> running? In particular, I have an FvwmButtons instance that starts a
>>> panel - I wouldn't want more than one instance of this panel
>>> running.
>>>
>>> Any help would be appreciated.
>>>
>>> Cheers, Jamie.
>>>
>>
>> Try this:
>>
>> DestroyFunc StartOnce
>> AddToFunc   StartOnce
>> + I PipeRead 'if [ `ps -ef |grep -v grep |grep -c "$0"` -lt 1 ]; then \
>>                 echo Exec $0; \
>>               fi'
>>
>> The only thing is that you've got to set the command in quotes:
>> StartOnce "xterm -fg black -bg snow2 -g 80x40 -fn 7x14"
> 
> Since I recently ran into issues with quotes which resulted in reading
> /bin/ls instead of a configuration file:
> 
> I notice that you are using three different types of quotes here.  Is
> there some documentation about when to use what kind of quotes?

No, not really. It depends what programming language you're using with 
PipeRead. In this example I use shell commands. The backticks (`) are 
for executing commands. To substitute a variable in shell you have to 
use double quotes ("). Single quotes (') won't work because it tells 
the shell to use it as is:
$> bla=`ls`
$> echo '$bla'
prints only $bla. But
$> echo "$bla"
prints the content of ls

With PipeRead you can use all of the 3 types of quotes to enframe the
code you're using:
PipeRead `code`
PipeRead 'code'
PipeRead "code"

But, if you want to use variables (from FVWM or from within your code)
you need double quotes for substitution. In my example I use backticks,
too. Therefore I have taken single quotes to enframe because all others
were used.

If you need inside your code the same quotes as for the enframing then 
you have to escape them with one backslash (\) or sometime more then 
one:

DestroyFunc UpdateWindowOpacity
AddToFunc   UpdateWindowOpacity
+ I PipeRead "echo SendToModule \
    FvwmTransSet opac `perl -e 'printf \"%.1f\",(100-$0/100)'`"

In this example the function gets a percent value but the FvwmTransSet
module wants a float - 0.7 instead of 70. With the Perl code I convert
it. Unfortunately I need the backticks for execution and Perl wants
the command in single quotes and the printf wants %.1f in double quotes
because of the substitution. So I have to escape the double quotes.

> How do you test something like this StartOnce function in a save way?

First I test it part for part in a terminal without variables. Or if it
is a longer code in a script.
If it works I create the function in a file e.g. testem in FVMW_USERDIR.
Mostly with echo commands like

DestroyFunc StartOnce
AddToFunc   StartOnce
+ I PipeRead 'if [ `ps -ef |grep -v grep |grep -c "$0"` -lt 1 ]; then \
                echo "works!"; \
              fi'

Next I open a terminal and run tail on ~/.xsession-errors to see errors:
$> tail -f ~/.xsession-errors

Then I start FvwmConsole and read the file:
FvwmConsole version 2.6.5
Read testem <enter>

If something is wrong you'll see it in your tail terminal. If nothing 
happens FVWM has accepted the syntax. Call the function in FvwmConsole:
StartOnce "xterm -fg black -bg snow2 -g 80x40 -fn 7x14"

That's it. Hope this helps a little.

- Thomas -

Btw. In this example you can use single quotes, too instead of double 
quotes. It doesn't matter.

Reply via email to