Adding tab completion to a bash script
I am creating a script which does some processing on a file. For the file, Ι will select any file from the current directory or will give path to a file.
Problem is the file name can be huge, so typing it all will be a pain.
echo "Enter file name"
The above code demonstrate what I am trying to do. When running this script, I have to put the file name character by character, which will be a huge pain. I want to get suggestions like in any terminal application by pressing Tab.
You can read the input filename like this:
read -e -p "Enter filename: " f
printf "filename: %sn" "$f"
read -e uses
readline which has already tab-completion for paths.
read --help and
man readline for details about them.