Results 1 to 3 of 3
I am trying to have tab completion in user entry in my bash script. I got the basic tab completion, but I only want to to work for text files. ...
- 08-04-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
Tab Complete in Bash Script
I am trying to have tab completion in user entry in my bash script. I got the basic tab completion, but I only want to to work for text files. I figured out that if I run it in the current shell (i.e. run it with ". script"), it works perfectly. My only problem with this is that the variables need to auto-clear and I don't want the end user to have to type that (this is commissioned for a friend). My current code is:
Some of it is a little weird, such as the custom history file, but ignore this. This is only a part of a larger script.Code:#!/bin/bash echo 'Input name of file' bind 'TAB:dynamic-complete-history' rm .bash_history2 2>/dev/null PotentialFiles=$(ls -tr *.txt) for i in $PotentialFiles ; do echo "$i" >> .bash_history2 done history -c history -r .bash_history2 compgen -W "$PotentialFiles" FileChosen read -e FileChosen
Thank you in advance!
- 08-05-2011 #2Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
It seems that you need to add one of this commands that sets key binding before doing the "bind" command:
so if you have the code:Code:set -o vi set -o emacs
Code:#!/bin/bash set -o vi echo -n 'Input name of file: ' bind 'TAB:dynamic-complete-history' rm .bash_history2 2>/dev/null PotentialFiles="$(ls -tr *.txt)" for i in $PotentialFiles ; do echo "$i" >> .bash_history2 done ls -1tr *.txt > .bash_history2 history -c history -r .bash_history2 compgen -W "$PotentialFiles" FileChosen read -e FileChosen
- 08-05-2011 #3Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
It works! Thank you.


Reply With Quote
