Vieb
Vieb copied to clipboard
Custom external file selector
Checklist
- [x] I searched the
:help
documentation using/
for helpful information - [x] I have read the frequently asked questions
- [x] I did not find any similar issues in the issue tracker
Addition or change Vieb currently selects files using the system's default file browser. Qutebrowser has settings to change the command that is run for selecting files. With this it is possible to use a terminal file manager.
- fileselect.handler toggles using the default or an external file selector.
- fileselect.single_file.command sets the command that will be run for selecting a single file and fileselect.multiple_files.command does this for selecting multiple files at once.
In the config.py
file, you can set something like this:
c.fileselect.handler = 'external'
c.fileselect.single_file_command = ['xterm', '-e', 'ranger', '--choosefile={}']
to make the file command open a terminal that runs the terminal file manager ranger and returns the chosen file. This is essentially running xterm -e ranger --choosefile={}
, where qutebrowser substitutes {}
with a target file that it reads to know which file to choose.
From the manpage for ranger:
--choosefile=targetfile
Allows you to pick a file with ranger.
This changes the behavior so that when you open a file, ranger will exit and write the absolute path of that file into targetfile.
From the manpage for xterm:
-e program [ arguments ... ]
This option specifies the program (and its command line arguments) to be run in the xterm window.
It also sets the window title and icon name to be the basename of the program being executed if
neither -T nor -n are given on the command line.
NOTE: This must be the last option on the command line.
I would settings for this in Vieb. Something like filecommand=[default, external]
and externalfilecommand=<command_string=%s>
. Let me know if any of this doesn't make sense or if you have other ideas.
Alternatives considered
You could try setting the default file manager to a terminal-based file manager, but I think similar to externalcommand
, my suggestion gives users more flexibility.
This looks like a nice new option, but I wonder if it would really require a separate command for multiple vs single file selection? Is there a case I need to keep in mind when working on this I personally overlooked?
Most people use the same file selector for single and multiple files. One reason for a separate command would be if you always perform an action on collections of files like compressing them. Then you would have a wrapper script for multiple selection like (in pseudocode):
# multicompress.script
# get the list of files
execute('ranger --choosefiles={first_argument}')
files = lines_in(first_argument)
zip(files, 'files.zip')
# choosefile should now only contain the name of the zip file
write_to(first_argument, 'files.zip')
Then the qutebrowser syntax would be:
c.fileselect.handler = 'external'
c.fileselect.single_file_command = ['xterm', '-e', 'ranger', '--choosefile={}']
c.fileselect.multiple_files_command = ['xterm', '-e', 'multicompress.script', '{}']
This kind of wrapper script can be written to check for the number of files it is given, so it's up to you whether you want Vieb to make this distinction explicit.
I think the reason ranger does this is choosefiles
selects files with the selection key (space
) and you press enter
when you are done, but choosefile
ignores any space
-selected files and takes the file that your cursor is on when you press enter
. Those two selection modes are different enough that they have separate arguments.
Would it also make sense to indeed give Vieb two separate settings, but make the multiple file selector command by default redirect to the single file command setting? So that a user is not required to change two settings if they don't use this functionality, but still have the option to have a separate filechooser for multiple files if they wanted to?
Yes, that would make sense.
I briefly looked into implementing this, but apparently it's not possible at this time, see:
- https://github.com/electron/electron/issues/749
- https://github.com/electron/electron/issues/32671