Re: Extending fluxbox menu with a script.
On Thursday, November 21, 2013 01:15:34 PM Sharon Kimble wrote:
> I am trying to write a bash script which has this line in it -
>
> mv ~/.fluxbox/menu ~/.fluxbox/menu-$(/bin/date +%Y%m%d-%R); mmaker
> fluxbox -f;;
>
> This line is creating a fluxbox menu which ends with these lines -
> ' [restart] (Restart)
> [separator]
> [exit] (Exit)
> [end]
> [end]'
>
> What I want to do is to add this script onto the end of the first
> command, and it is -
> #!/bin/bash
> # title - submenu
>
> echo [submenu] (My Menu)
> echo [include] (~/.fluxbox/usermenu)
> echo [end]
> echo [separator]
>
> So the final running command will look like this -
> 'mv ~/.fluxbox/menu ~/.fluxbox/menu-$(/bin/date +%Y%m%d-%R); mmaker
> fluxbox -f; submenu;;'
>
> and the main menu will look like this at the end -
> [restart] (Restart)
> [separator]
> [exit] (Exit)
> [end]
> [submenu] (My Menu)
> [include] (~/.fluxbox/usermenu)
> [end]
> [separator]
>
> But how do I do it please?
sed is your friend. If I've followed your message (you want menu-`date` to
contain the submenu), this should do the trick--*provided* the last [end] is
the last line in the file:
mv ~/.fluxbox/menu ~/.fluxbox/menu-$(/bin/date +%Y%m%d-%R); \
sed -i -e '$ i \
\t\t\[submenu] (My Menu)\
\t\t\[include] (~/.fluxbox/usermenu)\
\t\t\[end]\
\t\t\[separator] ~/.fluxbox/menu-$(/bin/date +%Y%m%d-%R); \
mmakerfluxbox -f; submenu;;
If the last [end] is the only one in the file at the beginning of the line,
change the first line of the sed chant to:
sed -e '/^\[end]/ i \
(Instead of addressing the last line of the file, address the line with [end]
at B.o.L.)
N
Reply to: