Here is a function that I use to edit various conf files. It works and is simple, but I was wondering if it could be extended to use the cursor keys to select the required file. I believe that the command select
can do some quite fancy extensions, maybe that's an option? Or better might be just to have the output same as below but selectable without full screen (but maybe that's impossible due to the nature of the console?). If I do info grep
for example, I'd like the options to be selectable like the underlined menu items in there (i.e. much simpler than select
menus, but would be curious also to see simple select
options).
viconf ()
{
COLUMNS=12;
printf -v PS3 '\n%s ' 'Select option: ';
printf "Edit config file:\n\n";
select x in ~/.bashrc ~/.bash_profile ~/.bash_login ~/.profile ~/.custom ~/.inputrc ~/.vimrc;
do
vim $x;
break;
done
}
CodePudding user response:
No, select command do not have selections. You need to write your own function to work with menu.
Also it is not a trivia question how to get keypresses in bash
But you can try to use existing projects for this, for example dialog: https://linux.die.net/man/1/dialog
If you want write your things in pure shell, you can check my jks-manager in github. I wrote some procedure to detect keypress and do some king of navigation in pure posix shell My tool need only sed, grep and keytool from jdk to work with java keystores: https://github.com/sfkulyk/jks-manager