Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Bash-completion on shell script Post 302925342 by sea on Sunday 16th of November 2014 04:10:51 PM
Old 11-16-2014
You either want a select menu or read: An Introduction to Programmable Completion

As in:
Code:
select ITEM in $(ls);do
    echo "do your stuff"
    break
done

Hope this helps

---------- Post updated at 22:10 ---------- Previous update was at 19:33 ----------

I wanted to implement this as well for some of my scripts, but me didnt feel confident enough to try.
Now i tried, and YEAH !!! *dance*

This is what i've achieved in about an hour from knowing nothing about it.
Its dirty, its bugy, but when it agrees to work, heck - i love that it lists my prj dir Smilie
Code:
# bash completition for dev-scripts
# 2014.11.16 by sea
#
#	Dynamic attempt
#
	_ds_base_dir()
	{
		# NOT USED YET
		echo /usr/share/dev-scripts/menu
	}
	_ds_list_prjs()
	{
	    COMPREPLY=( $( compgen -W "$(cd $HOME/.config/dev-scripts/prjs;ls)" -- "$2" ) )
	    return 0
	}
#
#	Fixed lists
#
	_ds_mod_git()
	{
		COMPREPLY=( $( compgen -W "add commit edit status upl" -- "$2" ) )
	}
	_ds_mod_ks()
	{
		COMPREPLY=( $( compgen -W "add edit make" -- "$2" ) )
	}
	_ds_mod_rpm()
	{
		COMPREPLY=( $( compgen -W "add changelog edit list make" -- "$2" ) )
	}
	_ds_mod_prj()
	{
		COMPREPLY=( $( compgen -W "git ks rpm edit list" -- "$2" ) )
	}
	_ds_mod_ssh()
	{
		COMPREPLY=( $( compgen -W "info make setup" -- "$2" ) )
	}
	_ds_mod_new()
	{
		COMPREPLY=( $( compgen -W "manpage" -- "$2" ) )
	}
	_ds_mod_menu()
	{
		COMPREPLY=( $( compgen -W "new prj ssh add make review setup" -- "$2" ) )
	}
	_dev_scripts()
	{
		COMPREPLY=()
		case $3 in
		add|make|list|edit|review)
			complete -F _ds_list_prjs -o filenames ds	;;
		setup)	return 0						;;
		new)	complete -F _ds_mod_new -o filenames ds			;;
		prj)	complete -F _ds_mod_prj -o filenames ds			;;
		ks)	complete -F _ds_mod_ks -o filenames ds			;;
		rpm)	complete -F _ds_mod_rpm -o filenames ds			;;
		git)	complete -F _ds_mod_git -o filenames ds			;;
		ssh)	complete -F _ds_mod_ssh -o filenames ds			;;
		esac
	}
	complete -F _dev_scripts -W 'add make review setup new prj ssh' ds

@ thailand: Hope this helps

@ others:
One question remains, anyone knows how i can 'fix' the read/shown values?
I assume i need to implement another 'layer' of case statement within functions?

Thank you in advance
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[tcsh2bash] Tab completion - 'enhanced' equivalent in bash?

I really like tcsh's: set completion='enhanced' because it treats underscores and dash signs the same. I don't have to reach for the shift key when trying to complete files that have underscores. As far as I know, there is nothing like this in bash. Does such a thing exist in bash? If... (2 Replies)
Discussion started by: sarnobat
2 Replies

2. Shell Programming and Scripting

bash completion

hello, I have been trying for a couple days to figure this out to no avail. I am converting some csh code to bash. I have converted everything except the completion code. #bashrc (I set this alias in my bashrc) alias test='source ${PATH}/test.sh' #${PATH}/test.sh (returns some aliases and... (0 Replies)
Discussion started by: platypuus
0 Replies

3. Shell Programming and Scripting

configure bash completion for multiple possibilities

Hello, Bash completion is great, but there are some features I'd like to change. One thing is the behaviour when there are lots of very similar possibilities. E.g., my directory contains 133 files, from pubmed_result1.txt to pubmed_result133.txt $ ls Lyonprim/p Display all 133... (2 Replies)
Discussion started by: jossojjos
2 Replies

4. Shell Programming and Scripting

Programmable completion for two arguments in bash

Hi there! I have this script which handles bookmarks. Bookmarks are basically a string that point to a certain path, e.g., project -> ~/code/projects/project. Currently I have working completion for the bookmarks: ~ $ m p<Tab> ~ $ m project What I want to implement now is the cd... (0 Replies)
Discussion started by: KevinSjoberg
0 Replies

5. UNIX for Dummies Questions & Answers

Bash Tab Completion Hanging

Hi, I'm having a problem with tab completion at the bash command line. For some reason, whenever I type g<tab>, the terminal will freeze up for 5-10 seconds before asking me if I want to display all 325 possibilities. I thought that maybe it's because of the high number of commands, but I have... (4 Replies)
Discussion started by: Raz716
4 Replies

6. Shell Programming and Scripting

Bash-Completion, an example

Hello I've followed several bash-completion threads, usualy none were answered, because of obvious reasons. (of which i'm just aware since a day or a few) Non-the-less, because i was writing scripts, i never considered it to be possible to add this functionality. Also, because i though that... (0 Replies)
Discussion started by: sea
0 Replies

7. UNIX for Advanced & Expert Users

Bash-Completion, one list shown, the other not.

Heyas I'm trying to read out a file which contains a variable and use that list to complete a bash command. Difficult part on this is, that 2 (actualy 3) different lists are to be used, but the 'dynamic' ones from the external file dont work properly. It only seems to work with the list... (2 Replies)
Discussion started by: sea
2 Replies

8. UNIX for Advanced & Expert Users

Bash-Completion, installed but not applied

Heyas For my project TUI i had prepared bash completion. Bash-completion works, at least if i source that file manualy. However, when i'm installing it, it wont apply, not even for new opened terminals. Allthough i had it working once, i dont get why it doesnt work now. <...> + '' +... (0 Replies)
Discussion started by: sea
0 Replies

9. Shell Programming and Scripting

Ssh bash script exits without remote command completion

Hi, My goal is to connect from unix server A to windows server B and call a bat file on windows. I am able to succeed in remoting to windows and executing a command, the issue i am facing is the shell scrip is exiting without making sure of bat file success. Can you please help me in... (4 Replies)
Discussion started by: pxp018
4 Replies
Tcl_AllowExceptions(3tcl)				      Tcl Library Procedures					 Tcl_AllowExceptions(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_AllowExceptions - allow all exceptions in next script evaluation SYNOPSIS
#include <tcl.h> Tcl_AllowExceptions(interp) ARGUMENTS
Tcl_Interp *interp (in) Interpreter in which script will be evaluated. _________________________________________________________________ DESCRIPTION
If a script is evaluated at top-level (i.e. no other scripts are pending evaluation when the script is invoked), and if the script termi- nates with a completion code other than TCL_OK, TCL_ERROR or TCL_RETURN, then Tcl normally converts this into a TCL_ERROR return with an appropriate message. The particular script evaluation procedures of Tcl that act in the manner are Tcl_EvalObjEx, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx, Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval and Tcl_VarEvalVA. However, if Tcl_AllowExceptions is invoked immediately before calling one of those a procedures, then arbitrary completion codes are per- mitted from the script, and they are returned without modification. This is useful in cases where the caller can deal with exceptions such as TCL_BREAK or TCL_CONTINUE in a meaningful way. KEYWORDS
continue, break, exception, interpreter Tcl 7.4 Tcl_AllowExceptions(3tcl)
All times are GMT -4. The time now is 05:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy