I show a simple way to make a useful menu with bash. When we did the look utility, I used this bash' select command. I didn't however explain it at the time, thinking I'll do it later. Now is later.
In chapter 77 we installed 'links' and set the variable PAGER.
By now, I hope you have some documentation in our 'doc' directory /root/doc, because this script is for perusing the /root/doc directory.
I called this script doks, but as you know you can give it another name.
Code: Select all
#!/bin/bash
main() {
vars
menu
}
vars() {
# $clr
dir=/root/doc
[ ! -d $dir ] && echo "$dir doesn't exist, exiting" && exit
PS3='Please select : '
# branch example, use different mode for the pager if X is running
xrun=`pidof X`
[ x$xrun != x ] && graphics="-g"
}
menu() {
cd $dir
clear ; echo -e \\n\\n\\n\\n\\n
echo "Scripting And Linux Documentation" ; echo
select fname in * ;
do
$PAGER $graphics ${dir}/${fname}
break;
done
exec $0
}
main
# 2009-08-02
What I'd like for an assignment is to have you modify this file some, give it colors, change the color of PS3. Change and color the title, so on and so forth.
You can setup these simple little menu systems throughout your system as needs be. For example, I have scripts to run wine supported files. I type in 'winem', short for 'wine menu' and then select the number of the application I want to run.
The wine scripts have their own place in the PATH so I can run them directly also with command line arguments. And while on the subject, you can add lots of paths to grow your system and keep it organized.
A little change of subject, but while I'm thinking about it, when we installed mrxvt it didn't come with a complete rc file. I made a complete file, not all the values are entered, nor should they be, but the options are. With the rc file, it's easy to change the way mrxvt looks and behaves. And of course see the options available which the other file didn't show.
I'll attach it as mrxvtrc and you can download it to /root and use
swapf mrxvtrc .mrxvtrc
Would you like a utility for swapping directories? If so, you can use swapf as the template. Copy it to the name swapd and change it internally, accordingly.
~
78 - select menu