Life in the console – ranger

Exploring the secrets of the GNU / Linux system, it is not uncommon to come to a simple conclusion – most of the steps can be performed from the console level most often in a more effective, rarely more effective way. A simple continuation of this course of thinking will be the conclusion that the […]

Exploring the secrets of the GNU / Linux system, it is not uncommon to come to a simple conclusion – most of the steps can be performed from the console level most often in a more effective, rarely more effective way. A simple continuation of this course of thinking will be the conclusion that the command line is so powerful that leaving it can simply be uncomfortable (or inefficient). When the balance of time spent in the terminal begins to outweigh the time we use when clicking on icons, there is a need to find alternatives to tools available only in the graphical environment.

Today’s text is mainly addressed to administrators, whose command line naturally becomes the primary work tool. However, people who are not administrators can also find interesting information here and learn a different approach to the activity performed many times during the work day – file browsing. I invite you to present the file manager ranger.

editors

On the command line, we repeat commands like a mantra pwdls and cd (be a more interesting combination pushd + popd). These commands meet the principle underlying Unix systems KISS. However, they are associated with a certain mental overhead. Visual representations of the files we view will help us. It is worth mentioning the so-called here orthodox file managersand in particular the most popular among them – Midnight Commander. Conceptually, these managers boiled down to the principle of dividing the screen into three parts: two symmetrically distributed lists of currently opened directories and command lines. One of the windows is active, and from the command line we can perform operations on the currently selected object in the active window, for example, copy the selected file to the location from the second passive window. However, it is not these relics from the past era that will be the subject of today’s article for one simple reason – the author was born too late to soak up this popular style of work with files when the DOS system reigns.

Ranger

The file manager that today’s text treats takes a lot of the previously mentioned „orthodoxy ”, where the main interface for interacting with the program is the keyboard. In case of rangerand we get keyboard shortcuts well known to users Vima. The main difference, however, is the implemented way of previewing files inside the program itself. The manager’s window is divided into three columns:

  • the first column displays the contents of the parent directory of the current location
  • the second allows you to move in the currently selected directory
  • the third column gives us a preview of the currently selected file (or in the case of the – directory a list of files contained in it).

ranger

 

Installation

Installation on Enterprise Linux systems is easiest to use git:

$ git clone https://github.com/ranger/ranger.git
$ cd ranger
$ sudo make install

The above installation will place the program by default in the location /usr/local/bin/ranger available to all system users. However, it requires administrative powers. We can also install the program locally, but remember to add the location of the installation to the variable PATH.

Configuration

After the first start ranger creates a path where the local configuration will be stored. By default, this is a directory ranger in the location defined in the environment variable $XDG_CONFIG_HOME. If this variable is not set, it will be: ~/.config/ranger.

Copying the default configuration, which also includes widely documented options, can be done using the following command:

 ranger --copy-config = all
creating: / home / cmd / .config / ranger / rifle.conf
creating: / home / cmd / .config / ranger / commands.py
creating: / home / cmd / .config / ranger / commands_full.py
creating: / home / cmd / .config / ranger / rc.conf
creating: / home / cmd / .config / ranger / scope.sh

> Please note that configuration files may change as ranger evolves.
  It's completely up to you to keep them up to date.

> To stop ranger from loading both the default and your custom rc.conf,
  please set the environment variable RANGER_LOAD_DEFAULT_RC to FALSE.

Documentation rangerand it is very precise and for this reason we will not dwell on the configuration in this text and instead we encourage you to use the manual man 1 ranger. Worth explaining are the two basic concepts behind this file manager:

  1. In the script scope.sh there are mechanisms used to display previews of various files. creators rangerand here they rely on many external applications so as not to reinvent the wheel. By default, only text preview is supported, but support for additional file types only involves installing additional software. Again, we refer to documentation in which all use cases have been described in detail.
  2. Configuration File rifle.conf contains links between file types and programs in which they should be run. ranger has a built-in „launcher ” application that recognizes using MIME and file extensions, what type of file we are trying to run. When the file is identified, it consults the above configuration and runs the file in the program with the highest priority (first looking from above).

Service

Moving in the directory structure can be done using the arrows and enter (starting selection / opening the directory). Full power rangerand, however, only the Vima user will appreciate it, because action mapping was created with them in mind.

ranger-selection

We can move using the well-known hjkl. Selection takes place using the – space, the selected items will be highlighted and they will be subject to all subsequent actions. Below are some of the most commonly used actions along with their keyboard shortcuts.

Shortcut Action
yy copy
dd cut
pp paste
zh show hidden files

The second way to interact with rangerem is the command line to which we will gain access (as in Vim) after entering the character :. Most useful for a person starting an adventure with rangerem will be the command :help ;)

Bonus! Integration with Vim

The last thing will appeal to people who do not leave the home government ( Homers) on the keyboard. There is very neat Vim plugin allowing use rangerand as the default file manager inside Vim. After completing the installation instructions, available at the link provided above, we can run rangerand inside Vima using the command RangerOpenCurrentDir or RangerOpenProjectRootDir (opens ranger in the root directory of the guitar project we are in today). These commands are most convenient to assign to a keyboard shortcut. The author of the plugin recommends the following abbreviations:

$ tail -2 ~ / .vimrc
nnoremap c: RangerOpenCurrentDir
nnoremap f: RangerOpenProjectRootDir

I encourage everyone console warriors to test rangera – modern, fast and extensive console file manager. Thanks to its numerous functions, it will meet our expectations both in TTY and in the terminal emulator. What’s more, after configuring and installing additional programs supporting its operation, it will delight with functionality compared to graphic managers.

blank Authors

The blog articles are written by people from the EuroLinux team. We owe 80% of the content to our developers, the rest is prepared by the sales or marketing department. We make every effort to ensure that the content is the best in terms of content and language, but we are not infallible. If you see anything that needs to be corrected or clarified, we'd love to hear from you.