Skip to content

dabesl/reckless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Reckless File Explorer

The whole project consists of one bash script named explore. It tries to do a subset of what midnight commander does, but with a different philosophy:

  • Users should have a vim-like experience.
  • Be almighty without a hassle; always act with root's power locally or remote.
  • Work with software that is already there, since it mostly does quite a good job (at least). To have it all installed might be a little challenging, but after that, happiness should be default.
  • Don't require an installation with further dependencies on libraries. All is contained in one big bash script.

This project is named reckless because it depends on the user's personality having an evident trait of recklessness. Read at least the section Why not, to get a chance to not ruin your day.

Installation

Copy the bash script explore somewhere and call it once /path/to/explore -r. This will output a little function to copy into your .bashrc. Without this, you have to provide passwords all the time and fun gets lost. So do it right away; after that you just have to type r and provide passwords only once.

There are lots of dependencies, which hopefully are not heavy, because you probably like them and have them already on your system.

  • fzf
  • kitty terminal, especially the icat kitten for preview
  • batcat
  • eza (optional)
  • neovim
  • well-known linux programs: awk, bash, cat, chmod, flock, getopts, grep, head, ls, mktemp, nc, printf, realpath, rm, sed, setpriv, sort, ssh, sudo

For remote file editing to work, neovim must also be installed on remote machines.

Why

Here are some reasons why you might like reckless:

  • Built on the shoulders of giants (bash, kitty, fzf, neovim)
  • Minimalistic but beautiful
  • You are not in it like mc; it is at your fingertips; use often but briefly
  • No long-lived connections to remote machines
  • Remote machines feel like local, even with file transfer
  • Edit files in place; don't copy them beforehand
  • Never have issues with reading or writing files; always act with root's power. But
  • don't be root with it's brute configuration, be yourself with augmented power!
  • Vim-like user experience, neovim integration (doesn't work with classic vim)

Why not

When you call explore or its abbreviation-function r, you provide sudo-passwords for all machines you want to access. The abbreviation r keeps these in your shell's memory in clear text. This is only inches away from serious security problems. If you leave your terminal, anybody can harvest all those passwords within seconds! This might not only be reckless, but stupid! So please, close your terminal, before leaving your computer!

And the whole thing is a bash script with tricky code optimized for speed (AKA bad style). So start out small! Every unexpected behaviour could indicate some code problem.

How it works

Locally

The script explore is meant to be run in a kitty terminal, because this provides the extended graphics protocol to display images inside the terminal.

The frontend is done by fzf which is configured to show files and directories as displayed by ls or eza in full color mode and a preview in the right half of the window. Text files are previewed with batcat, images with the icat kitten (coming with kitty).

Every time you move the cursor, another file needs to be previewed. If you display a remote machine, this means that every time a new ssh connection is made up and the file is downloaded and thrown into the mouth of the preview programm! Also, every time your sudo-password is piped into that super-short-lived ssh-connection in order to have the permission to really see every file. (The password is transferred securely, since it is piped and so never shows up in any process list.) It may seem improbable that all this work at a reasonable speed, but fortunately it does (thanks to ssh master connections).

Anywhere

This was from the perspective of working locally with access to remote machines. But explore could also be copied to some remote machine and be run from there. When all dependencies are met remotely too, one would expect, that everything should continue to work.

In fact it will, if you ssh into the machines from a kitty terminal (as you probably do anyway, since you use reckless already). But there is a little issue with image preview which still has to be done by the terminal from which you ssh'ed into the remote machine, which is your local kitty. But kitty's developer has provided helper software for that. If you install it remotely, even preview will work. Read about remote kittens if you want to go this way.

But even without fullfillment of all dependencies, some of reckless will work. Try out if your requirements are met.

What it does

The explore script (which is all there is) has no built-in documentation at all. Documentation is right here and nowhere else!

Standard movement

Running explore directly is fully functional but no fun, because sudo-passwords need to be provided at every start. Therefore normally you do this:

r . # display the current directory in slot 1
r   # display the current directory in slot 1
r ~ # display home in slot 1
r /usr/local /etc .  # display three directories in slots 1, 2, 3
r remote:/etc /etc   # display remote and local /etc in slots 1 and 2

Switch between slots by pressing the number keys. If a slot is empty, switching is silently ignored. Press j/k to go down/up, l to enter a directory, h to leave it, g/G to scroll to the top/bottom, ctrl-f/ctrl-b to scroll one page down/up. Quit with q.

The preview can be toggled by ? and scrolled with shift-up/shift-down.

There is also a search mode provided by /. Enter some characters to filter the displayed files. While in that mode, use ctrl-j/ctrl-k to scroll down/up. Enter leaves the mode but keeps the filter, esc empties the filter. After leaving the search mode, every further action empties the filter.

Status line

⬤/◯ means that dotfiles (name starting with a '.') are displayed or not. Press . to toggle this. (This is also a useful workaround if a screen refresh is needed.)

sel=3/4 means that you have selected 4 files, 3 of which in the current slot and the remaining one in some other slot. Press a to silently add a file or directory to the selection and r to silently remove one. Use tab to mark multiple files before pressing a or r. And most important: press s to display all selected files in neovim. There you can add and remove whatever you want. (Read further down, what can be done with selected files.)

dir=7/3 means that 3 slots are occupied in total, one of which is the current slot with number 7.

Quit

To quit explore, type q or :q or c. The latter will cd into the direcory that was current when you quit (for this the program had to be started as bash function r).

Slots

Most of the time r is called with only few slots to be filled (which always are numbered from 1 upwards). But while exploring, you can make copies to keep interesting places to be reused later. The following is possible:

:to 7     # copy the current slot to slot 7
:from 7   # copy slot 7 to the current slot and forget what was in it before
:3 to 7   # copy slot 3 to slot 7 (if current slot is not 3)
:3 to     # copy slot 3 to current slot (missing numbers default to current)
:3 swap 7 # swap slots 3 and 7
:3 rot 5  # rotate 3 into 5, 5 to 4, 4 to 3 (rotate mostly left)
:5 rot 3  # rotate 5 into 3, 3 to 4, 4 to 5 (rotate mostly right)
:rot 7    # rotate current slot to 7
:4 new some:/var  # fill slot 4 with remote `some`'s directory `/var`
:q        # quit program; that is not a slot command but you expected this!

In all slot commands only the first character is immportant. Instead of from you can write f or freesoftwarefoundation.

Edit

You can call neovim on any file by pressing e. This is primitive and in many cases not sufficient. But reckless is meant to be used for tasks near the system level which is a world of plain text and therefore neovim.

When you marked multiple files with tab, all of them are opened in one window with multiple buffers.

Delete

Files and directories can be deleted by first marking them with tab and then pressing d. A neovim-instance displays chosen files and gives you a last chance to not delete or change the files in the list by hand.

Deletion only works inside the current directory. If you made elaborated selections with a before, these don't get lost but neither are applied for deletion.

Shell

Often one is at the place of interest but wants to do something that reckless doesn't provide a command for. In this case press ! and get a shell in place, where you can do whatever needs to be done. You already have root permissions, but some commands need to be run as root; in this case use sudo. When finished, type exit or press ctrl-d to return to reckless.

Use the command selcat to list all files that you selected before on that machine. If you need them separated by NUL-Bytes call selcat -0. (Yes, this is one of the scenarios, where selections are used.)

File transfer

Files can be copied (not moved) from any place to any other with the following steps:

  • Choose the files into a common selection (with a and r)
  • You can even choose from multiple places on multiple machines
  • Change to the slot that shows the destination directory on the destination machine. (Sources and destination may be local or remote.)
  • Press t to copy every chosen file into the current directory, overwriting existing files with colliding names.

This is brutal action without question for mercy, so be careful! The whole process is based on tar collecting the files in the sources and another tar unpacking them into the destination. Since everything is done with root force, metadata like owner, group, timestamps are kept, which is a great feature. Progress indicator is the verbous mode of destination-tar listing filenames.

You have already taken into account, that a file in the destination directory can be overwritten by a chosen source file. But keep in mind, that files from different sources might have the same name and these will overwrite the destination multiple times, because there is no file name mangling in the destination directory.

Important detail: When the files /usr/bin/zip and /usr/sbin/parted are copied into the destination /home/user, you get their final paths to be /home/user/zip and /home/user/parted. This is what you expect in most cases. But what, if you wanted to distinguish the different source folders in order to get /home/user/bin/zip and/home/user/sbin/parted? How can you tell the transfer mechanism to keep more of the source path than just the file name?

Well, this is why in the selection list you are told about < and >. Press them to get /usr//bin/zip and /usr//sbin/parted. When there are // in the path, everything left of it will be dropped and right of it will be used in the destination folder. If for some reason those two keys don't work, you can insert slashes by hand.

Directory comparison

This feature is still experimental. When you press = the current directory is compared with the one before. So it is important that you jump to the two slots that you want to compare and only when you are in the second one press =. To return to normal slot display, press = once more.

In compare mode the status line only shows the second slot (this has to be fixed). Commands h and l change directories as usual but only synchronously, i.e. if you chose a directory that is present in both slots. Use H/L to change the directory only in slot 1 and ctrl-h/ctrl-l for slot 2.

Since this feature will still go through some changes, let's consider this as undocumented. If you want to try it out, use two fairly equal directories like in r /etc remote:/etc and make up your mind, what all those colours might mean. They try to highlight differences meaningfully and be reticent about matches.

About

bash filemanager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages