Subject: FVWM: Function to set dynamic menu title

From: Ryan Daly <[email-masked]>
Date: Tue, 17 Feb 2004 19:33:26 -0500

Is there an easy way to dynamically set the title of the StartMenu?

I'm trying to come up with a function to do this, but am having a bit of
trouble.  Would something like the following work at all?

AddToFunc "CreateStartMenu"
  + "I" DestroyMenu StartMenu
  + "I" PipeRead 'echo `/bin/hostname -s` > $HOME/.fvwm/.hostname
  + "I" AddToMenu StartMenu `/bin/cat $HOME/.fvwm/.hostname` Title
  + "I" PipeRead `/bin/cat $HOME/.fvwm/.startmenu'
  + "I" /bin/rm $HOME/.fvwm/.hostname

.startmenu would contain the rest of my StartMenu, just so that I don't
have to type the rest of it out in the function.

This gives me a title of "/bin/cat $HOME/.fvwm/.hostname" instead of my
actual hostname.  Am I using PipeRead correctly here?

Thanks.
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Thomas Adam <[email-masked]>
Date: Wed, 18 Feb 2004 00:44:04 +0000 (GMT)

>   + "I" PipeRead 'echo `/bin/hostname -s` > $HOME/.fvwm/.hostname
                                                                   ^^^^
You didn't end it with a '. You must add a ' at the end.

> actual hostname.  Am I using PipeRead correctly here?

(see above)

-- Thomas Adam

=====
"The Linux Weekend Mechanic" -- http://linuxgazette.net
"TAG Editor"                 -- http://linuxgazette.net

"<shrug> We'll just save up your sins, Thomas, and punish 
you for all of them at once when you get better. The 
experience will probably kill you. :)"

 -- Benjamin A. Okopnik (Linux Gazette Technical Editor)

___________________________________________________________
BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: "Ryan Daly" <[email-masked]>
Date: Tue, 17 Feb 2004 19:51:27 -0500 (EST)

> You didn't end it with a '. You must add a ' at the end.

  + "I" PipeRead 'echo `/bin/hostname -s` > $HOME/.fvwm/.hostname'

I still get the same results with the ' at the end...

Any other suggestions?

---

From: Thomas Adam <[email-masked]>
Date: Wed, 18 Feb 2004 01:01:01 +0000 (GMT)

> I still get the same results with the ' at the end...

Try:

+ "I" PipeRead 'echo `/bin/hostname -s` > $[HOME]/.fvwm/.hostname'

Works for me.

-- Thomas Adam

=====

---

From: "Ryan Daly" <[email-masked]>
Date: Tue, 17 Feb 2004 20:20:14 -0500 (EST)

> + "I" PipeRead 'echo `/bin/hostname -s` > $[HOME]/.fvwm/.hostname'

Yep.  That part works for me, too.  The trouble line for me is:

  + "I" AddToMenu StartMenu `/bin/cat $[HOME]/.fvwm/.hostname` Title

Do I need a PipeRead here, too?  I'm not certain that I totally
understand what the PipeRead means to a function...
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Thomas Adam <[email-masked]>
Date: Wed, 18 Feb 2004 01:27:59 +0000 (GMT)

> understand what the PipeRead means to a function... 

PipeRead allows you to use external process to interpolate (usually) for
Fvwm commands. What you probably want is something like:

+ "I" PipeRead "AddToMenu StartMenu 'echo `/bin/hostname -s`' Title

-- Thomas Adam

=====

---

From: "Ryan Daly" <[email-masked]>
Date: Tue, 17 Feb 2004 20:43:08 -0500 (EST)

> + "I" PipeRead "AddToMenu StartMenu 'echo `/bin/hostname -s`' Title

OK, that put me on the right track.  The entire function that I'm using is:

AddToFunc "CreateStartMenu"
  + "I" DestroyMenu JizzBoneMenu
  + "I" PipeRead 'echo `/bin/hostname -s` > $HOME/.fvwm/.hostname'
  + "I" PipeRead 'echo "AddToMenu JizzBoneMenu `/bin/cat
$HOME/.fvwm/.hostname` Title"'
  + "I" PipeRead '/bin/cat $HOME/.fvwm/.startmenu'
  + "I" /bin/rm $HOME/.fvwm/.hostname

I just needed to put "PipeRead 'echo ..." in front of the entire line.

Thanks for the help!

---

From: Frank Gruellich <[email-masked]>
Date: Wed, 18 Feb 2004 08:38:49 +0100

Hello,

>   + "I" PipeRead 'echo `/bin/hostname -s` > $HOME/.fvwm/.hostname'

Why are you saving the hostname in ~/.fvwm/.hostname?

>   + "I" PipeRead 'echo "AddToMenu JizzBoneMenu `/bin/cat $HOME/.fvwm/.hostname` Title"'

And delete it immediately? What about

 + I PipeRead 'echo AddToMenu JizzBoneMenu `/bin/hostname -s` Title'

?

HTH,
 regards, Frank.
-- 
Sigmentation fault

---

From: Rainer Koehler <[email-masked]>
Date: Wed, 18 Feb 2004 10:49:41 +0100 (CET)

>   + "I" /bin/rm $HOME/.fvwm/.hostname

This is such a big mess that I can't keep my mouth shut...
No offense, but I think someone should explain to you what you're
actually doing here.

Let's look at this line:
      echo `/bin/hostname -s` > $HOME/.fvwm/.hostname

Hostname print's the host's name to stdout.  The backticks around it
tell the shell to take hostname's stdout and substitute it where the
quoted command was.  So, in the next step there's echo with one
argument, the name of the host.  Echo takes it's arguments and prints
them to stdout.  So, in your case, echo prints the host's name, which
is exactly the same as what /bin/hostname did in the first place.
This gets redirected into a temporary file, which is fine for the
moment.  And the PipeRead makes sure that fvwm waits for the file to
be created.

Next line:
     echo "AddToMenu JizzBoneMenu `/bin/cat $HOME/.fvwm/.hostname` Title"

Here you use cat to print the content of your temporary file to
stdout, which is then substituted into the echo ... line.  The
temporary file contains nothing but the hostname, so this is now the
third time the hostname is printed to stdout.  You can forget about
the temporary file completely if you just use /bin/hostname here.

By the way, on all systems I know (I just checked on SuSE, Redhat, and
Solaris), the hostname is in the environment variable HOST.

Next line:

As far as I can tell, you simply want to read in the file
"$HOME/.fvwm/.startmenu".  That's usually done with fvwm's Read
command, without invoking cat.  There might be some other reason to
use PipeRead that I'm not aware of (e.g. $HOME).

So, I would try this:

AddToFunc "CreateStartMenu"
   + "I" DestroyMenu JizzBoneMenu
   + "I" PipeRead 'echo "AddToMenu JizzBoneMenu $HOST Title"'
   + "I" Read $HOME/.fvwm/.startmenu

That's two lines and 5 calls to external commands shorter.

Note that I didn't actually try it, since I don't want to mess around
with my fvwm-config right now...

Rainer

---

From: "Ryan Daly" <[email-masked]>
Date: Wed, 18 Feb 2004 08:56:56 -0500 (EST)

> No offense, but I think someone should explain to you what you're

Sorry for not posting my completed function.  That function was obviously
just for debugging purposes so I could see that things were working.

My completed function is as follows:

AddToFunc "CreateStartMenu"
  + "I" DestroyMenu StartMenu
  + "I" PipeRead 'echo "AddToMenu StartMenu `/bin/hostname -s` Title"'
  + "I" PipeRead '/bin/cat $HOME/.fvwm/.startmenu'

Again, sorry for not posting this and clearing up any confusion.

Thanks to all for the help.

---

From: Rainer Koehler <[email-masked]>
Date: Wed, 18 Feb 2004 15:42:13 +0100 (CET)

> just for debugging purposes so I could see that things were working.

No problem, and thanks for posting the final (?) function.  There are
other users here who should see it, and not just some intermediate
version.

>   + "I" PipeRead '/bin/cat $HOME/.fvwm/.startmenu'

Ok, so why don't you use $HOST instead of calling hostname, and why
don't you use Read instead of PipeRead to read .startmenu?  There
might very well be good reasons to do it your way, I just want to
know...

Rainer

---

From: "Ryan Daly" <[email-masked]>
Date: Wed, 18 Feb 2004 10:09:15 -0500 (EST)

> might very well be good reasons to do it your way, I just want to

Well, I just picked using hostname instead.  I could save a system call
by using the env variable.  I'll probably switch that.

I use PipeRead because Read doens't produce the menu for me.  Not sure
why, but PipeRead gives me my menu and Read doesn't.
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 18 Feb 2004 15:20:35 +0000

> why, but PipeRead gives me my menu and Read doesn't.

It does not work because $HOME is interpreted by shell, but not fvwm
commands. Use either $[HOME], or $[FVWM_USERDIR], or better yet just:

  Pipe .startmenu

It must work.

Regards,
Mikhael.

---

From: "Ryan Daly" <[email-masked]>
Date: Wed, 18 Feb 2004 10:27:19 -0500 (EST)

> commands. Use either $[HOME], or $[FVWM_USERDIR], or better yet just:

It does.  I just changed it.  That's the newness of it all for me...

Thanks for the help.

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 18 Feb 2004 15:26:39 +0000

>   Pipe .startmenu

Of course it is:

  Read .startmenu

Regards,
Mikhael.

---

From: Dominik Vogt <[email-masked]>
Date: Wed, 18 Feb 2004 16:30:41 +0100

> might very well be good reasons to do it your way, I just want to

Come to think of it, this is much simpler:

  + I "$[HOSTNAME]" Title

Ciao

Dominik ^_^  ^_^