LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2012, 01:06 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Rep: Reputation: 110Reputation: 110
Shell based menu of options


I have been testing the Fish shell for a few days, enjoying it so far to an extent. It has bugs and lacks features, but behaves pretty well in the command line, and I like it for scripts too, because the syntax is a lot simpler and cleaner.

Like I said, it lacks features. I like the 'select' command in other shells, it creates a nice menu of options. For example:

Code:
navigate ()  	{
	PS3="Where do you want to go today? "
	select TARGET in google microsoft yahoo quit
	do
		case $TARGET in
			google	)
				local url=http://www.google.com 
				break ;;
			microsoft	)
				local url=http://www.microsoft.com 
				break ;;
			yahoo	)
				local url=http://www.yahoo.com 
				break ;;
			quit)	exit;;
			*)	exit ;;
		esac
	done
	lynx $url
}
Fish has no such feature so I guess I will have to use some external program. What do you recommend? I suppose things like zenity or dialog would be overkill?
 
Old 01-02-2012, 03:25 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
One of the major benefits of open source is that you can modify it to suit your preference and send those modifications back upstream to possibly benefit other users, why not have a go at extending it ?
 
Old 01-02-2012, 03:34 PM   #3
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Original Poster
Rep: Reputation: 110Reputation: 110
Programming in shell, any shell, is hard enough for me. I am absolutely incapable of modifying the shell itself. I am in fact considering migrating 100% (scripting and command line use) to Fish because I find the other shells too complicated.
 
Old 01-02-2012, 03:44 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Programming in shell is basically an extension of working in a shell, automating common tasks etc. If you work in a shell long enough then your shell scripting skills will evolve.
 
Old 01-02-2012, 06:09 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
While I'm not familiar with fish syntax, the select command is really just a specialized while true loop. You're example function could be rewritten like this in bash, for example:

Code:
navigate (){

	echo "1) google" >&2
	echo "2) microsoft" >&2
	echo "3) yahoo" >&2
	echo "4) quit" >&2
	
	while true; do

		read -n 1 -p "Where do you want to go today (1-4)? " target

		case $TARGET in
			1)	local url=http://www.google.com 
				break ;;

			2)	local url=http://www.microsoft.com 
				break ;;

			3)	local url=http://www.yahoo.com 
				break ;;

			4)	exit ;;

			*)	echo "Where's that?" ;;
		esac
	done

	lynx "$url"
}
I'm sure the basic idea can be adapted to almost any shell.
 
1 members found this post helpful.
Old 01-02-2012, 07:31 PM   #6
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by kbp View Post
Programming in shell is basically an extension of working in a shell, automating common tasks etc. If you work in a shell long enough then your shell scripting skills will evolve.
Sure, I have years of experience in shell programming, but I always have to make and correct at least ten mistakes until a new script runs as expected, because there are so many quirks and gotchas in Bash/sh/ksh/tcsh syntax. I am sick of (not) memorizing those. I will therefore not even touch zsh with a ten-foot pole. I remember I tried it for a few days many years ago and I got tired of it because it was too complex.

If you ever feel like reading about it, the author of the Fish shell points out exactly how Fish tries to be simpler and cleaner:

http://lwn.net/Articles/136232/

I have ported (rewritten) some 20 or 30 of my most used scripts, and they definitely look a lot more readable now. Everyday use of the command line is better, too. I make fewer mistakes.

Last edited by lucmove; 01-02-2012 at 07:32 PM.
 
Old 01-02-2012, 07:35 PM   #7
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Original Poster
Rep: Reputation: 110Reputation: 110
Smile

Quote:
Originally Posted by David the H. View Post
While I'm not familiar with fish syntax, the select command is really just a specialized while true loop. You're example function could be rewritten like this in bash, for example:
(...)
That was a very helpful reply. Thank you!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu bashed shell script for users shell 0.o Linux - Server 6 02-14-2013 06:00 AM
LXer: Webian Shell: Prototype Web-Based Shell LXer Syndicated Linux News 0 07-05-2011 10:00 AM
Right-click menu options yogomix Red Hat 1 07-13-2010 06:20 AM
menu for some options kopper27 Linux - Newbie 6 04-07-2010 03:35 AM
Boot menu options carlindenver Linux - Newbie 1 10-23-2005 01:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration