This post was moved from http://rawtext.club where it was originally
posted.
Mon Nov 8 10:52:13 PM CET 2021
Hello. Netwr
is an awesome addition to Vim
functionality. I like firing up Vim with just vim .
so a
file selector can allow me to pick a file and open it in Vim. I thought
it would be awesome to have something like Netwr but for just any BASH command, not just
Vim. So I implemented it. In a way, and for a simple file picker, it is
“better” than Netwr, since this implementation allows for the user to
pick more than one file and use them as arguments to whatever command
they’re typing at the BASH command line.
Unfortunatelly, it uses dialog
and its annoying blue
paraphernalia, but I’ll show here how to change that to black.
Edit your .bashrc
file and add:
selectafile()
{
FILE=$(dialog --stdout --title "Please choose a file" --fselect $PWD/ 14 48)
READLINE_LINE=$READLINE_LINE$FILE
READLINE_POINT=${#READLINE_LINE}
}
bind -x '"\e[24~":selectafile'
Source it with source .bashrc
and then, each time you
press the F12 key, a file selector will pop up, you select the file, hit
OK, and you’re back typing the command you were just typing. The process
can be repeated multiple times while typing one and the same line at the
BASH command prompt.
This BASH function and key-binding uses dialog
. Install
it like so: $ sudo apt-get install dialog
. I use Debian. Check dialog’s web site to see how to
install it on your machine.
Create a .dialogrc
file like so:
$ dialog --create-rc ~/.dialogrc
. Then edit the file and
change the settings for use_colors
and for
screen_color
, like so:
use_colors = ON
screen_color = (CYAN,BLACK,ON)
Ok, this is my exmas present for rawtext and its users, and also for all the users of tilde club, sdf and grex in 2019.
You can go back to my home page at rawtext, but you can also visit my other personal pages: my home page at polarhome on an AIX7 machine, my other page at polarhome (on an Ubuntu machine), my home page at sdf, my home page at grex or its alias, my web page at tilde club, and also my personal web site. Email me at gasconheart@tilde.club to provide some feedback.