[PYTHON] CLI file manager ranger basic settings

I wrote an entry Linux --Setting the file manager ranger that runs on the command line --Qiita before, but I would like more detailed explanation of how to use it at a later date. Now that I have received the words, I would like to summarize the basic setting method. For basic usage of ranger, please read the link above or install and read the help.

** My environment: **

$ ranger --version
ranger-master 1.7.2

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2]

What is a ranger?

screen_001.png

It is a one-screen file manager that has various functions such as moving, copying, renaming, and previewing files, specifying a program, and opening it in the terminal. You can also operate it with the mouse, but the feature of this file manager is the high-speed operation with the keyboard that takes advantage of operating from the command line. In addition, while running on the terminal, it also supports functions such as image preview, making it easy to operate files that are difficult to understand from the file name alone.

** Reference link: **

  1. hut/ranger
  2. [Google image search "ranger + cli"](https://www.google.co.jp/search?hl=ja&> site=imghp&tbm=isch&source=hp&q=ranger+cli&oq=ranger+cli)
  3. How to use the CLI + Vi key binding file manager Ranger
  4. Install the file manager "ranger" that runs on CUI | Memorandum --Daily memorandum by Linux beginners-

Also, at the end of the article in 3, it is stated that thumbnails of videos cannot be displayed, but it is necessary from version 1.7. If you install an external program, you can also display thumbnails of videos. If you install it with apt or homebrew, it is often not the latest version, so please use pip or clone the source from GitHub and install it.

Preparation of configuration file

As for how to install, even if you refer to the above entry I wrote earlier, just installing it will not show the original power of this application. The first thing to do is to prepare a configuration file.


$ ranger --copy-config=all

And run. By doing this, the template of the configuration file with the default settings is copied to ~ / .config / ranger, and you can customize it to your liking by changing the configuration file in this directory. I will. Once you know that these files have been created, you can read the contents and see what you can set.

file name Settings
rc.conf Options and command settings set when ranger starts
rifle.conf Application settings to use when starting a file
scope.sh File preview display settings

Set up rc.conf

The contents of this file are read when ranger is started. You can display a preview, set options such as showing / hiding hidden files and file information, specifying a color scheme, and specify key bindings. For details on detailed setting items

man ranger

Please refer to the ** SETTINGS ** section as. With ranger running, you can enter : to enter command mode and execute various commands.

:set draw_borders true

By doing this, you can try the settings without having to write them in the configuration file and reload them (the TAB key also completes them). So, if you open the man page, the configuration file, and the ranger, and change the configuration file only where you are interested, you will have an environment that is easy to use.

Image preview display

screen_002.png

To preview the image

set preview_images true

Please. You need to have w3m, a web browser that can display images in your device, installed and ready to execute the command w3mimgpreview.

Also, if you are using iTerm2 on your Mac

set preview_images_method w3m

In the section, change the w3m part to iterm2. The image preview function of iTerm2 must be supported. ITerm2 that can be entered with homebrew etc. is ver2.1.1, but the inline image display function needs to use Nightly Builds ver., That is, the development version on GitHub.

Also, since ranger is compatible with iTerm2 from ver1.7, you need to clone it from GitHub and build it yourself. However, it is easy to install,

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

You can install it with.

For the time being, I will post a link to my rc.conf, so please refer to it. However, since my ranger is often up to date now, I have added options that I did not have before, and I may get an error message when I try to run it on an earlier version.

Set rifle.conf to set the application to open the file

This will definitely need to be done. In rifle.conf, you can set which application preferentially opens when selecting and opening a file of a certain file type. Normally, when you open a file with the Enter or l key, the file is opened with the highest priority application, and when you press the r key, all possible opening methods are displayed, and you can enter the number. You can specify the program to open by pressing the Enter key.

screen_002.png (You can open the pdf file in your favorite application)

As you can see in the comments at the beginning of rifle.conf, all the lines are

<condition1>, <condition2>, ... = command

It is written in the format of, and when this <condition> is met, the command on the right side is executed. To find out what the conditions are, have them read the comments in the config file or look at the other settings that are actually written in the config file.

For example, in the section "Misc" in rifle.conf

#-------------------------------------------
# Misc
#-------------------------------------------
# Define the "editor" for text files as first action
mime ^text,  label editor = $EDITOR -- "$@"
mime ^text,  label pager  = "$PAGER" -- "$@"

It is written as. The condition is specified by $ EDITOR-"$ @ ", that is, the environment variable $ EDITOR, in this case mine ^ text, that is, when the condition that the mine type matches the regular expression ^ text is met. Execute the command to open with the editor. $ @ Means that all selected files will be assigned to the arguments.

In addition to the number, if you specify label, you can select the application with this label when you press the r key in the ranger. Also, by specifying flag, instead of executing it as a command directly on the current terminal, execute it in the background (flag f) or open another terminal (flag t) Or you can run it with root privileges (flag r).

Also, the priority of file execution is higher in order from the top in this configuration file, so if you just want to change the application to be started by default and the setting for that start is already written , All you have to do is sort it so that it is located above the file than other settings. In particular, the way to open html is set to open with a minor browser, so be careful.

In reference

Preview display settings in scope.sh

If you want to preview by the method specified in scope.sh, use rc.conf

set use_preview_script true

Please.

By the way, since the preview function is realized by using an external command, the preview cannot be displayed unless these packages are included.

In scope.sh

try <command> && { dump | ... }

There are many parts written in the form like, but if you check and install the package that provides this <command>, you will be able to preview it. The package name in apt was written in 4 earlier, so please refer to it.

This is a thumbnail display of videos that can be used in version 1.7 or later, but a command called ffmpegthumbnailer is required.

sudo apt-get install ffmpegthumbnailer

Enter with.

screen_003.png

To prevent preview display for some file types, just comment out the relevant part of the configuration file. I think it's cool to make ASCII art with img2txt, but I don't use it personally because it will be heavy.

I think the ability to preview html and pdf, and use highlighting to display the contents of a text file with syntax highlighting is the most useful. As I said many times, since version 1.7, you can preview the video (and the image is cached so it's light), so it's even easier to use. By the way, you can use the full screen to display by pressing the ʻikey, and you can toggle the preview display / non-display with thezp` key.

Precautions regarding image preview display

As mentioned in the relevant part of rc.conf, image preview is guaranteed only when tmux is not used with xterm and urxvt, so be careful when using it with tmux (sometimes it is not displayed or it is not displayed). The image remains in another window, or it erodes another pane ...)

In my case, if I had only one ranger in one window of tmux, this problem wouldn't bother me. It seems that the image is not displayed when multiple rangers are running in the same session. This is an investigation required, and I hope it will be displayed well in tmux as soon as possible.

Also, if you are using urxvt etc. and the image is not displayed well, comment out the item ʻURxvt * .depthin~ / .Xdefaults`.

! For showing img in ranger with w3mimgdisplay, disable this
! URxvt*.depth:               32

reference:

w3m/ranger images don't work on urxvt / Applications & Desktop Environments / Arch Linux Forums

Also, it seems that problems often occur when the frame is hidden, so when the image is not arranged well,

set draw_borders true

please try.

reference:

Artifacts in image preview / ranger - ArchWiki

Writer's scope.sh (not changed)

Summary

Well, I think that this is the end of the basic settings. After that, as mentioned in the previous article, write a setting to prevent nesting of subshells, a setting to autocd to the directory exited by q, and register the command yourself in rifle.conf. If you do, I think you can make it even easier to use. I hope this will be an opportunity to convey the goodness of the command line to various people.

Recommended Posts

CLI file manager ranger basic settings
CentOS 7 basic settings after network settings
Basic commands for file operations