Ranger: Difference between revisions

From ArchWiki
(→‎Usage: adding important keycontrols)
(update interlanguage links)
 
(55 intermediate revisions by 22 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:ranger}}
{{Lowercase title}}
[[Category:File managers]]
[[Category:File managers]]
[[Category:Console applications]]
[[Category:Console applications]]
[[ar:Ranger]]
[[de:Ranger]]
[[es:Ranger]]
[[es:Ranger]]
[[fa:ranger]]
[[fr:ranger]]
[[ja:Ranger]]
[[ja:Ranger]]
[[zh-hans:Ranger]]
[[zh-hans:Ranger]]
{{Related articles start}}
{{Related articles start}}
{{Related|lf}}
{{Related|Midnight Commander}}
{{Related|Midnight Commander}}
{{Related|nnn}}
{{Related|nnn}}
{{Related|vifm}}
{{Related|vifm}}
{{Related articles end}}
{{Related articles end}}
[http://ranger.github.io/ ranger] is a text-based file manager written in [[Python]]. Directories are displayed in one pane with three columns. Moving between them is accomplished with keystrokes, bookmarks, the mouse or the command history. File previews and directory contents show automatically for the current selection.


Features include: [[vi]]-style key bindings, bookmarks, selections, tagging, tabs, command history, the ability to make symbolic links, several console modes, and a task view.  ''ranger'' has customizable commands and key bindings, including bindings to external scripts. Ranger also comes with its own [[file opener]], {{man|1|rifle}}. The closest competitors are [[Vifm]] and [https://github.com/gokcehan/lf lf].
[https://ranger.github.io/ ranger] is a text-based file manager written in [[Python]]. Directories are displayed in one pane with three columns. Moving between them is accomplished with keystrokes, bookmarks, the mouse or the command history. File previews and directory contents show automatically for the current selection.
 
Features include: [[vi]]-style key bindings, bookmarks, selections, tagging, tabs, command history, the ability to make symbolic links, several console modes, and a task view.  ''ranger'' has customizable commands and key bindings, including bindings to external scripts. Ranger also comes with its own [[file opener]], {{man|1|rifle}}. The closest competitors are [[Vifm]] and [[lf]].


== Installation ==
== Installation ==
[[Install]] the {{Pkg|ranger}} package, or {{AUR|ranger-git}} for the development version.
[[Install]] the {{Pkg|ranger}} package, or {{AUR|ranger-git}} for the development version.


== Usage ==
== Usage ==


To start ranger, launch a [[List of applications#Terminal emulators|terminal]] and run {{ic|ranger}}.
To start ranger, launch a [[List of applications/Utilities#Terminal emulators|terminal]] and run {{ic|ranger}}.


{| class="wikitable"
{| class="wikitable"
Line 42: Line 43:


  $ ranger --copy-config=all
  $ ranger --copy-config=all
Afterwards, set {{ic|1=RANGER_LOAD_DEFAULT_RC=false}} as an [[environment variable]] to avoid loading the global configuration in addition to the local.


* {{ic|rc.conf}} - startup commands and key bindings
* {{ic|rc.conf}} - startup commands and key bindings
Line 55: Line 58:
=== Move to trash ===
=== Move to trash ===


To add a keybind that moves files to your trash directory {{ic|~/.local/share/Trash/files/}} with {{ic|DD}}, add to {{ic|~/.config/ranger/rc.conf}}:
To add a keybind that moves files to your trash directory {{ic|~/.local/share/Trash/files/}} with {{ic|DD}}, amend the configuration file as follows:
 
{{hc|~/.config/ranger/rc.conf|<nowiki>
map DD shell mv %s /home/${USER}/.local/share/Trash/files/
...
map DD shell mv %s /home/${USER}/.local/share/Trash/files/
...
</nowiki>}}


Alternatively, use GIO commandline tool provided by {{Pkg|glib2}} package:
Alternatively, use GIO commandline tool provided by {{Pkg|glib2}} package:
Line 67: Line 73:
=== Defining commands ===
=== Defining commands ===


Continuing the above example, add the following entry to {{ic|~/.config/ranger/commands.py}} to empty the trash directory {{ic|~/.Trash}}.
Continuing the above example, add the following entry to empty the trash directory {{ic|~/.Trash}}.
 
{{hc|~/.config/ranger/commands.py|<nowiki>
...


{{bc|<nowiki>
class empty(Command):
class empty(Command):
     """:empty
     """:empty
Line 77: Line 85:


     def execute(self):
     def execute(self):
         self.fm.run("rm -rf /home/myname/.Trash/{*,.[^.]*}")
         self.fm.run("rm -rf /home/myname/.Trash/")
</nowiki>}}
</nowiki>}}


To use it, type {{ic|:empty}} and {{ic|Enter}} with tab completion as desired.
To use it, type {{ic|:empty}} and {{ic|Enter}} with tab completion as desired.
{{Warning|{{ic|[^.]}} is an essential part of the above command.  Without it, all files and directories of the form {{ic|..*}} will be deleted, wiping out everything in your home directory.}}


=== Color schemes ===
=== Color schemes ===
Line 92: Line 98:


Custom color schemes can be placed in {{ic|~/.config/ranger/colorschemes}}.
Custom color schemes can be placed in {{ic|~/.config/ranger/colorschemes}}.
=== Color highlight in file previews ===
Install the {{Pkg|python-pygments}} package, then copy {{ic|/usr/share/doc/ranger/config/scope.sh}} to {{ic|~/.config/ranger/scope.sh}} and edit the variable {{ic|PYGMENTIZE_STYLE}} in the configuration file of ranger to your liking. The complete list of supported themes can be obtained via {{ic|pygmentize -L style}}.


=== File association ===
=== File association ===


Ranger uses its own file opener called {{ic|rifle}}.
Ranger uses its own file opener called {{ic|rifle}}.
It's configured in {{ic|~/.config/ranger/rifle.conf}}. Run {{ic|1=ranger --copy-config=rifle}} if it does not exist. For example, the following line  
It is configured in {{ic|~/.config/ranger/rifle.conf}}. Run {{ic|1=ranger --copy-config=rifle}} if it does not exist. For example, the following line makes {{Pkg|kile}} the default program for tex files:
makes {{Pkg|kile}} the default program for tex files:


  ext tex = kile "$@"
  ext tex = kile "$@"
Line 117: Line 126:
==== Archive extraction ====
==== Archive extraction ====


The following command implements archive extraction by copying (yy) one or more archive files and then executing {{ic|:extracthere}} on the desired directory.
The following command implements archive extraction of the selected items to the current directory.


{{bc|<nowiki>
{{bc|<nowiki>
Line 123: Line 132:
from ranger.core.loader import CommandLoader
from ranger.core.loader import CommandLoader


class extracthere(Command):
class extract_here(Command):
     def execute(self):
     def execute(self):
         """ Extract copied files to current directory """
         """ extract selected files to current directory."""
         copied_files = tuple(self.fm.copy_buffer)
         cwd = self.fm.thisdir
 
         marked_files = tuple(cwd.get_selection())
         if not copied_files:
            return


         def refresh(_):
         def refresh(_):
Line 135: Line 142:
             cwd.load_content()
             cwd.load_content()


         one_file = copied_files[0]
         one_file = marked_files[0]
         cwd = self.fm.thisdir
         cwd = self.fm.thisdir
         original_path = cwd.path
         original_path = cwd.path
         au_flags = ['-X', cwd.path]
         au_flags = ['-x', cwd.path]
         au_flags += self.line.split()[1:]
         au_flags += self.line.split()[1:]
         au_flags += ['-e']
         au_flags += ['-e']
Line 144: Line 151:
         self.fm.copy_buffer.clear()
         self.fm.copy_buffer.clear()
         self.fm.cut_buffer = False
         self.fm.cut_buffer = False
         if len(copied_files) == 1:
         if len(marked_files) == 1:
             descr = "extracting: " + os.path.basename(one_file.path)
             descr = "extracting: " + os.path.basename(one_file.path)
         else:
         else:
             descr = "extracting files from: " + os.path.basename(one_file.dirname)
             descr = "extracting files from: " + os.path.basename(
         obj = CommandLoader(args=['aunpack'] + au_flags \
                one_file.dirname)
                + [f.path for f in copied_files], descr=descr, read=True)
         obj = CommandLoader(args=['aunpack'] + au_flags
                            + [f.path for f in marked_files], descr=descr,
                            read=True)


         obj.signal_bind('after', refresh)
         obj.signal_bind('after', refresh)
Line 157: Line 166:
==== Compression ====
==== Compression ====


The following command allows users to compress several files on the current directory by marking them and then calling {{ic|:compress ''package name''}}. It supports name suggestions by getting the basename of the current directory and appending several possibilities for the extension. You need to have {{pkg|atool}} installed, otherwise you will see an error message when you create the archive.
The following command allows users to compress several files on the current directory by marking them and then calling {{ic|:compress ''package name''}}. It supports name suggestions by getting the basename of the current directory and appending several possibilities for the extension. You need to have {{Pkg|atool}} installed, otherwise you will see an error message when you create the archive.


{{bc|<nowiki>
{{bc|<nowiki>
Line 196: Line 205:
=== External drives ===
=== External drives ===


External drives can be automatically mounted with [[udev]] or [[udisks]]. Drives mounted under {{ic|/media}} can be easily accessed by pressing {{ic|gm}} (go, media).
External drives can be automatically mounted with [[udev]] or [[udisks]]. The default key mappings to go to common mount points {{ic|/media}} and {{ic|/run/media/$USER}} are  {{ic|gm}} and {{ic|gi}} respectively.


=== Hidden files ===
=== Hidden files ===
Line 255: Line 264:
         self.fm.execute_command("cdemu -b system load 0 " + \
         self.fm.execute_command("cdemu -b system load 0 " + \
                 space.join([shell_escape(f.path) for f in selected_files]))
                 space.join([shell_escape(f.path) for f in selected_files]))
 
         mountpath = "/media/virtualrom/"
         mountpath = "/media/virtualrom/"


Line 267: Line 276:
         self.fm.loader.add(obj)
         self.fm.loader.add(obj)
</nowiki>}}
</nowiki>}}


=== New tab in current folder ===
=== New tab in current folder ===
Line 277: Line 285:


=== PDF file preview ===
=== PDF file preview ===
By default, ranger will preview PDF files as text. However, you can preview PDF files as an image in ranger by first converting the PDF file to an image. Ranger stores the image previews in {{ic|~/.cache/ranger/}}. You either need to create this directory manually or set {{ic|preview_images}} to {{ic|true}} in {{ic|~/.config/ranger/rc.conf}} to tell {{ic|ranger}} to create it automatically at the next start.  However, note that {{ic|preview_images}} does not need to be set to {{ic|true}} the whole time to preview PDF file as images, only {{ic|~/.cache/ranger}} directory is needed.
By default, ranger will preview PDF files as text. However, you can preview PDF files as an image in ranger by first converting the PDF file to an image. Ranger stores the image previews in {{ic|~/.cache/ranger/}}. You either need to create this directory manually or set {{ic|preview_images}} to {{ic|true}} in {{ic|~/.config/ranger/rc.conf}} to tell {{ic|ranger}} to create it automatically at the next start.  However, note that {{ic|preview_images}} does not need to be set to {{ic|true}} the whole time to preview PDF file as images, only {{ic|~/.cache/ranger}} directory is needed.


Line 285: Line 294:
==== Synchronize path ====
==== Synchronize path ====


Ranger provides a shell [[Bash/Functions|function]] {{ic|/usr/share/doc/ranger/examples/bash_automatic_cd.sh}}. Running {{ic|ranger-cd}} instead of {{ic|ranger}} will automatically ''cd'' to the last browsed folder.
Ranger provides a shell [[Bash/Functions|function]] {{ic|/usr/share/doc/ranger/examples/shell_automatic_cd.sh}}. Running {{ic|ranger_cd}} instead of {{ic|ranger}} will automatically ''cd'' to the last browsed folder.


If you launch ranger from a graphical launcher (such as {{ic|$TERMCMD -e ranger}}, where TERMCMD is an X terminal), you cannot use {{ic|ranger-cd}}. Instead, create an executable script:
If you launch ranger from a graphical launcher (such as {{ic|$TERMCMD -e ranger}}, where TERMCMD is an X terminal), you cannot use {{ic|ranger_cd}}. Instead, create an executable script:


{{hc|ranger-launcher.sh|<nowiki>
{{hc|ranger-launcher.sh|<nowiki>
Line 298: Line 307:


{{hc|.''shell''rc|<nowiki>
{{hc|.''shell''rc|<nowiki>
$RANGERCD && unset RANGERCD && ranger-cd
$RANGERCD && unset RANGERCD && ranger_cd
</nowiki>}}
 
This will launch {{ic|ranger-cd}} only if the {{ic|RANGERCD}} variable is set. It is important to unset this variable again, otherwise launching a subshell from this terminal will automatically relaunch {{ic|ranger}}.
 
==== Start a shell from ranger ====
 
With the previous method you can switch to a shell in last browsed path simply by leaving ranger. However you may not want to quit ranger for several reasons (numerous opened tabs, copy in progress, etc.).
You can start a shell from ranger ({{ic|S}} by default) without losing your ranger session. Unfortunately, the shell will not switch to the current folder automatically. Again, this can be solved with an executable script:
 
{{hc|shellcd|<nowiki>
#!/bin/sh
export AUTOCD="$(realpath "$1")"
 
$SHELL
</nowiki>}}
 
and - as before - add this to at the very end of your shell configuration:
 
{{hc|shellrc|<nowiki>
cd "$AUTOCD"
</nowiki>}}
 
Now you can change your shell binding for ranger:
 
{{hc|rc.conf|
map S shell shellcd %d
}}
 
Alternatively, you can make use of your shell history file if it has one. For instance, you could do this for [[zsh#Dirstack|zsh]]:
 
{{hc|shellcd|<nowiki>
## Prepend argument to zsh dirstack.
BUF="$(realpath "$1")
$(grep -v "$(realpath "$1")" "$ZDIRS")"
echo "$BUF" > "$ZDIRS"
 
zsh
</nowiki>}}
</nowiki>}}


Change ZDIRS for your dirstack.
This will launch {{ic|ranger_cd}} only if the {{ic|RANGERCD}} variable is set. It is important to unset this variable again, otherwise launching a subshell from this terminal will automatically relaunch {{ic|ranger}}.
 
===== A simpler solution =====
 
{{hc|rc.conf|<nowiki>
map S shell bash -c "cd %d; bash"
</nowiki>}}
This could probably be adapted to other shells as well.
Instead of just running a shell (like the default config), this will run {{ic|cd}} in a shell, then execute a interactive shell which will not immediately exit so that you can continue with what you wanted.


==== Preventing nested ranger instances ====
==== Preventing nested ranger instances ====
Line 354: Line 318:
When you however forget that you already are in a ranger shell and start ranger again you end up with ranger running a shell running ranger.
When you however forget that you already are in a ranger shell and start ranger again you end up with ranger running a shell running ranger.


To prevent this you can create the following function in your [[Autostarting#On_shell_login_.2F_logout|shell's startup file]]:
To prevent this you can create the following function in your [[Autostarting#On shell login / logout|shell's startup file]]:


  ranger() {
  ranger() {
Line 368: Line 332:
=== Artifacts in image preview ===
=== Artifacts in image preview ===


Borderless columns may cause stripes in image previews. [https://bbs.linuxdistrocommunity.com/showthread.php?tid=1051] In {{ic|~/.config/ranger/rc.conf}} set:
Borderless columns may cause stripes in image previews. [https://bbs.linuxdistrocommunity.com/showthread.php?tid=1051]{{Dead link|2023|05|07|status=domain name not resolved}} In {{ic|~/.config/ranger/rc.conf}} set:


  set draw_borders true
  set draw_borders true
Line 380: Line 344:
* [https://www.digitalocean.com/community/tutorials/installing-and-using-ranger-a-terminal-file-manager-on-a-ubuntu-vps Installing and using ranger]
* [https://www.digitalocean.com/community/tutorials/installing-and-using-ranger-a-terminal-file-manager-on-a-ubuntu-vps Installing and using ranger]
* [https://lists.nongnu.org/mailman/listinfo/ranger-users Mailing list]
* [https://lists.nongnu.org/mailman/listinfo/ranger-users Mailing list]
* [https://bloerg.net/2012/10/17/ranger-file-manager.html Ranger tutorial]
* [https://bloerg.net/posts/ranger-file-manager/ Ranger tutorial]

Latest revision as of 18:08, 1 February 2024

ranger is a text-based file manager written in Python. Directories are displayed in one pane with three columns. Moving between them is accomplished with keystrokes, bookmarks, the mouse or the command history. File previews and directory contents show automatically for the current selection.

Features include: vi-style key bindings, bookmarks, selections, tagging, tabs, command history, the ability to make symbolic links, several console modes, and a task view. ranger has customizable commands and key bindings, including bindings to external scripts. Ranger also comes with its own file opener, rifle(1). The closest competitors are Vifm and lf.

Installation

Install the ranger package, or ranger-gitAUR for the development version.

Usage

To start ranger, launch a terminal and run ranger.

Key Command
? Open the manual or list keybindings, commands and settings
l, Enter Launch files
j, k Select file in the current directory
h, l Travel up and down in the directory tree

Configuration

After startup, ranger creates a directory ~/.config/ranger. To copy the default configuration to this directory issue the following command:

$ ranger --copy-config=all

Afterwards, set RANGER_LOAD_DEFAULT_RC=false as an environment variable to avoid loading the global configuration in addition to the local.

  • rc.conf - startup commands and key bindings
  • commands.py - commands which are launched with :
  • rifle.conf - applications used when a given type of file is launched.

rc.conf only needs to include changes from the default file as both are loaded. For commands.py, if you do not include the whole file, put this line at the top:

from ranger.api.commands import *

See ranger(1) for general configuration.

Move to trash

To add a keybind that moves files to your trash directory ~/.local/share/Trash/files/ with DD, amend the configuration file as follows:

~/.config/ranger/rc.conf
...
map DD shell mv %s /home/${USER}/.local/share/Trash/files/
...

Alternatively, use GIO commandline tool provided by glib2 package:

map DD shell gio trash %s

Inspecting and emptying the "trash" is normally supported by graphical file managers such as nautilus, but you can also see the trash with the command gio list trash://, and empty it with: gio trash --empty.

Defining commands

Continuing the above example, add the following entry to empty the trash directory ~/.Trash.

~/.config/ranger/commands.py
...

class empty(Command):
    """:empty

    Empties the trash directory ~/.Trash
    """

    def execute(self):
        self.fm.run("rm -rf /home/myname/.Trash/")

To use it, type :empty and Enter with tab completion as desired.

Color schemes

Ranger comes with four color schemes: default, jungle, snow and solarized. You can change your color scheme using:

set colorscheme scheme

Custom color schemes can be placed in ~/.config/ranger/colorschemes.

Color highlight in file previews

Install the python-pygments package, then copy /usr/share/doc/ranger/config/scope.sh to ~/.config/ranger/scope.sh and edit the variable PYGMENTIZE_STYLE in the configuration file of ranger to your liking. The complete list of supported themes can be obtained via pygmentize -L style.

File association

Ranger uses its own file opener called rifle. It is configured in ~/.config/ranger/rifle.conf. Run ranger --copy-config=rifle if it does not exist. For example, the following line makes kile the default program for tex files:

ext tex = kile "$@"

To open all files with xdg-utils, make sure your $EDITOR and $PAGER are set and add:

else = xdg-open "$1"
label editor = "$EDITOR" -- "$@"
label pager  = "$PAGER" -- "$@"

Tips and tricks

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: bad style (Discuss in Talk:Ranger)

Archives

These commands use atool to perform archive operations.

Archive extraction

The following command implements archive extraction of the selected items to the current directory.

import os
from ranger.core.loader import CommandLoader

class extract_here(Command):
    def execute(self):
        """ extract selected files to current directory."""
        cwd = self.fm.thisdir
        marked_files = tuple(cwd.get_selection())

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = marked_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        au_flags = ['-x', cwd.path]
        au_flags += self.line.split()[1:]
        au_flags += ['-e']

        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False
        if len(marked_files) == 1:
            descr = "extracting: " + os.path.basename(one_file.path)
        else:
            descr = "extracting files from: " + os.path.basename(
                one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags
                            + [f.path for f in marked_files], descr=descr,
                            read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)

Compression

The following command allows users to compress several files on the current directory by marking them and then calling :compress package name. It supports name suggestions by getting the basename of the current directory and appending several possibilities for the extension. You need to have atool installed, otherwise you will see an error message when you create the archive.

import os
from ranger.core.loader import CommandLoader

class compress(Command):
    def execute(self):
        """ Compress marked files to current directory """
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:]

        descr = "compressing files in: " + os.path.basename(parts[1])
        obj = CommandLoader(args=['apack'] + au_flags + \
                [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr, read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)

    def tab(self, tabnum):
        """ Complete with current folder name """

        extension = ['.zip', '.tar.gz', '.rar', '.7z']
        return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension]

External drives

External drives can be automatically mounted with udev or udisks. The default key mappings to go to common mount points /media and /run/media/$USER are gm and gi respectively.

Hidden files

You can toggle the visibility of hidden files with the following command: :set show_hidden!, or use :set show_hidden true to make hidden files visible.

To make this permanent, add the setting to your configuration file:

rc.conf
set show_hidden true

Alternatively, hidden files can be toggled by pressing zh.

Image mounting

The following command assumes you are using CDemu as your image mounter and some kind of system like autofs which mounts the virtual drive to a specified location ('/media/virtualrom' in this case). Do not forget to change mountpath to reflect your system settings.

To mount an image (or images) to a cdemud virtual drive from ranger you select the image files and then type ':mount' on the console. The mounting may actually take some time depending on your setup (in mine it may take as long as one minute) so the command uses a custom loader that waits until the mount directory is mounted and then opens it on the background in tab 9.

import os, time
from ranger.core.loader import Loadable
from ranger.ext.signals import SignalDispatcher
from ranger.ext.shell_escape import *

class MountLoader(Loadable, SignalDispatcher):
    """
    Wait until a directory is mounted
    """
    def __init__(self, path):
        SignalDispatcher.__init__(self)
        descr = "Waiting for dir '" + path + "' to be mounted"
        Loadable.__init__(self, self.generate(), descr)
        self.path = path

    def generate(self):
        available = False
        while not available:
            try:
                if os.path.ismount(self.path):
                    available = True
            except:
                pass
            yield
            time.sleep(0.03)
        self.signal_emit('after')

class mount(Command):
    def execute(self):
        selected_files = self.fm.thisdir.get_selection()

        if not selected_files:
            return

        space = ' '
        self.fm.execute_command("cdemu -b system unload 0")
        self.fm.execute_command("cdemu -b system load 0 " + \
                space.join([shell_escape(f.path) for f in selected_files]))

        mountpath = "/media/virtualrom/"

        def mount_finished(path):
            currenttab = self.fm.current_tab
            self.fm.tab_open(9, mountpath)
            self.fm.tab_open(currenttab)

        obj = MountLoader(mountpath)
        obj.signal_bind('after', mount_finished)
        self.fm.loader.add(obj)

New tab in current folder

You may have noticed there are two shortcuts for opening a new tab in home (gn and Ctrl+n). Let us rebind Ctrl+n:

rc.conf
map <c-n>  eval fm.tab_new('%d')

PDF file preview

By default, ranger will preview PDF files as text. However, you can preview PDF files as an image in ranger by first converting the PDF file to an image. Ranger stores the image previews in ~/.cache/ranger/. You either need to create this directory manually or set preview_images to true in ~/.config/ranger/rc.conf to tell ranger to create it automatically at the next start. However, note that preview_images does not need to be set to true the whole time to preview PDF file as images, only ~/.cache/ranger directory is needed.

To enable this feature, uncomment the appropriate lines in /usr/share/doc/ranger/config/scope.sh, or add/uncomment these lines in your local file ~/.config/ranger/scope.sh.

Shell tips

Synchronize path

Ranger provides a shell function /usr/share/doc/ranger/examples/shell_automatic_cd.sh. Running ranger_cd instead of ranger will automatically cd to the last browsed folder.

If you launch ranger from a graphical launcher (such as $TERMCMD -e ranger, where TERMCMD is an X terminal), you cannot use ranger_cd. Instead, create an executable script:

ranger-launcher.sh
#!/bin/sh
export RANGERCD=true
$TERMCMD

And add the following at the end of your shell configuration:

.shellrc
$RANGERCD && unset RANGERCD && ranger_cd

This will launch ranger_cd only if the RANGERCD variable is set. It is important to unset this variable again, otherwise launching a subshell from this terminal will automatically relaunch ranger.

Preventing nested ranger instances

You can start a shell in the current directory with S, when you exit the shell you get back to your ranger instance.

When you however forget that you already are in a ranger shell and start ranger again you end up with ranger running a shell running ranger.

To prevent this you can create the following function in your shell's startup file:

ranger() {
    if [ -z "$RANGER_LEVEL" ]; then
        /usr/bin/ranger "$@"
    else
        exit
    fi
}

Troubleshooting

Artifacts in image preview

Borderless columns may cause stripes in image previews. [1][dead link 2023-05-07 ⓘ] In ~/.config/ranger/rc.conf set:

set draw_borders true

See also