Results 1 to 9 of 9
Hi,
I'm trying to get a dropdown selection menu in a bash script, like the one GRUB presents you with, allowing the user to peruse a playlist and select a ...
- 03-24-2008 #1
Dropdown menu (GRUB-style) in BASH script
Hi,
I'm trying to get a dropdown selection menu in a bash script, like the one GRUB presents you with, allowing the user to peruse a playlist and select a specific track. I've tried mucking about with a while loop that prints the whole list and a read -p -n 1 that watches the arrow keys for input but since I have to clear the screen and reprint the whole thing each time there's user input, it only works well for small lists. the 'dialog' utility seems like it might be an option but I can'get it to accept a dynamically created list (by a while loop). Isn't there some built-in bash selector I can use?
- 03-24-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I will better shot myself in one foot before using bash for this. If you really want to use bash for any reason, I would just print a number in front of each track, match them using an array or something, and use read to read the track number and play it.
What you are trying to do in bash is a real overkill. I'd suggest using dialog or ncurses, but not under bash. If you don't want to compile, maybe python would be ok for you.
- 03-24-2008 #3
Well, that's a tad drastic
Well, you may be right, but given what I'm still learning about bash I'm pretty sure that I've only scraped the surface and I like the 'works anywhere, anytime' part.
At any rate, learning ncurses and python would seem to require a bit too much investment for such a humble task. And even if I could get dialog to work, it's so ******* ugly....
- 03-24-2008 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Don't misunderstand me: bash is an awesome shell, but it has not been designed with that kind of purposes in mind. I really haven't dealt with the dialog userland tools, they might be any good or not, I don't really know, but that's not bash really. The same that mangling strings on awk is not bash either... That's shell independant.
If dialog worked for you, then that's fine. But if you are really worried about portability, nor even bash would be good enough. In that case, you would be bound to sh, which is much more limited even.
- 03-24-2008 #5Just Joined!
- Join Date
- Dec 2006
- Posts
- 52
How about select/case combination. That presents a numbered list to choose from.
select i in `ls` Exit
do
case ${i} in
${i})
Do something here
;;
Exit)
break
;;
*)
Unnecessary error
;;
esac
done
- 03-25-2008 #6
- 03-25-2008 #7Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Have you looked at zenity? I didn't notice a drop-down list option, but there are a lot of features, and perhaps one of them would be suitable ... cheers, drl
Originally Posted by chochem Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 03-26-2008 #8
I think I have come across it but it's GTK and I'm looking at a pure text interface solution. But thanks, anyway.
- 03-26-2008 #9Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
There is the non-trivial twin, with 10-20 external clients, apparently callable from the shell:
Best wishes ... cheers, drlTwin is a text-mode windowing environment: it draws and manages text windows on a text-mode display, like X11 does for graphical windows. It has a built-in window manager and terminal emulator, and can be used as server for remote clients in the same style as X11. It can display on Linux console, on X11 and inside itself.
...
a. Each window has an associated menu. Many windows can share
the same menu, and twin always show the menu associated
to the currently focused window.
d. Twin implements virtual screens. Each virtual screen has very big
sizes in both directions (something like 64K character cells),
and you can scroll them by holding LEFT or MIDDLE mouse buttons
and moving the mouse to one of the screen borders. Also, you can
switch to the next virtual screen by clicking on the arrows
at the top-right of its menu bar.
-- Twin - textmode window environment for LinuxWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote
