Git Product home page Git Product logo

ranger's Introduction

ranger 1.9.3

Build Status latest packaged version(s)

ranger is a console file manager with VI key bindings. It provides a minimalistic and nice curses interface with a view on the directory hierarchy. It ships with rifle, a file launcher that is good at automatically finding out which program to use for what file type.

screenshot

For mc aficionados there's also the multi-pane viewmode.

two panes multiple panes

This file describes ranger and how to get it to run. For instructions on the usage, please read the man page (man ranger in a terminal). See HACKING.md for development-specific information.

For configuration, check the files in ranger/config/ or copy the default config to ~/.config/ranger with ranger --copy-config (see instructions).

The examples/ directory contains several scripts and plugins that demonstrate how ranger can be extended or combined with other programs. These files can be found in the git repository or in /usr/share/doc/ranger.

A note to packagers: Versions meant for packaging are listed in the changelog on the website.

About

Design Goals

  • An easily maintainable file manager in a high level language
  • A quick way to switch directories and browse the file system
  • Keep it small but useful, do one thing and do it well
  • Console-based, with smooth integration into the unix shell

Features

  • UTF-8 Support (if your Python copy supports it)
  • Multi-column display
  • Preview of the selected file/directory
  • Common file operations (create/chmod/copy/delete/...)
  • Renaming multiple files at once
  • VIM-like console and hotkeys
  • Automatically determine file types and run them with correct programs
  • Change the directory of your shell after exiting ranger
  • Tabs, bookmarks, mouse support...

Dependencies

  • Python (>=2.6 or >=3.1) with the curses module and (optionally) wide-unicode support
  • A pager (less by default)

Optional dependencies

For general usage:

  • file for determining file types
  • chardet (Python package) for improved encoding detection of text files
  • sudo to use the "run as root" feature
  • python-bidi (Python package) to display right-to-left file names correctly (Hebrew, Arabic)

For enhanced file previews (with scope.sh):

  • img2txt (from caca-utils) for ASCII-art image previews
  • w3mimgdisplay, ueberzug, mpv, iTerm2, kitty, terminology or urxvt for image previews
  • convert (from imagemagick) to auto-rotate images and for image previews
  • rsvg-convert (from librsvg) for SVG previews
  • ffmpeg, or ffmpegthumbnailer for video thumbnails
  • highlight, bat or pygmentize for syntax highlighting of code
  • atool, bsdtar, unrar and/or 7z to preview archives
  • bsdtar, tar, unrar, unzip and/or zipinfo (and sed) to preview archives as their first image
  • lynx, w3m or elinks to preview html pages
  • pdftotext or mutool (and fmt) for textual pdf previews, pdftoppm to preview as image
  • djvutxt for textual DjVu previews, ddjvu to preview as image
  • calibre or epub-thumbnailer for image previews of ebooks
  • transmission-show for viewing BitTorrent information
  • mediainfo or exiftool for viewing information about media files
  • odt2txt for OpenDocument text files (odt, ods, odp and sxw)
  • python or jq for JSON files
  • sqlite3 for listing tables in SQLite database (and optionally sqlite-utils for fancier box drawing.)
  • jupyter nbconvert for Jupyter Notebooks
  • fontimage for font previews
  • openscad for 3D model previews (stl, off, dxf, scad, csg)
  • draw.io for draw.io diagram previews (drawio extension)

Installing

Use the package manager of your operating system to install ranger. You can also install ranger through PyPI: pip install ranger-fm. However, it is recommended to use pipx instead (to benefit from isolated environments). Use pipx run --spec ranger-fm ranger to install and run ranger in one step.

Check current version: Packaging status Packaging status

Installing from a clone

Note that you don't have to install ranger; you can simply run ranger.py.

To install ranger manually:

sudo make install

This translates roughly to:

sudo python setup.py install --optimize=1 --record=install_log.txt

This also saves a list of all installed files to install_log.txt, which you can use to uninstall ranger.

Getting Started

After starting ranger, you can use the Arrow Keys or h j k l to navigate, Enter to open a file or q to quit. The third column shows a preview of the current file. The second is the main column and the first shows the parent directory.

Ranger can automatically copy default configuration files to ~/.config/ranger if you run it with the switch --copy-config=( rc | scope | ... | all ). See ranger --help for a description of that switch. Also check ranger/config/ for the default configuration.

Going Further

  • To get the most out of ranger, read the Official User Guide.
  • For frequently asked questions, see the FAQ.
  • For more information on customization, see the wiki.

Community

For help, support, or if you just want to hang out with us, you can find us here:

ranger's People

Contributors

0xjmz avatar ael-code avatar aroig avatar awerebea avatar charignon avatar dmitmel avatar empee584 avatar germainz avatar hut avatar jakanakaevangeli avatar janderland avatar laktak avatar lelobster avatar mark-dawn avatar mrogalski avatar n-r-k avatar nfnty avatar nosuck avatar politas avatar potatoesmaster avatar prosoitos avatar randynobx avatar seebye avatar squigglezworth avatar toonn avatar vifon avatar xuehaipan avatar xunius avatar zaeph avatar zyklotomic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ranger's Issues

Have ranger open new tab in gvim on text file opening

Hey there,

I know a lot of people like to have ranger open new buffers in vim when you "select" a text/script/etc file. I do this by changing my EDITOR env as such:

export EDITOR="vim -g --servername GVIM --remote-silent"

This will open a new buffer in the first gvim instance opened or else open gvim with the file in the current (only) buffer. I'm sure it can be hacked to work with vim instead of gvim...

I just though I'd mention it because I remember reading somewhere (I thought it was in the ranger documentation but I can't find it now) about a common vim function which lets you open ranger from vim. I prefer to have a separate screen for ranger and then open new buffers in vim from ranger and I thought it might be worth including in the documentation...

'OpenStruct' object has no attribute 'update_preview'

test/tc_loader.py was broken by commit a308857 (and hasn't been fixed since):

$ git checkout a30885773f28e93b8bbe716a4ba444e90e3ba4d8
HEAD is now at a308857... fsobject.fsobject: Update previews when file changes
$ make test
................................E
======================================================================
ERROR: test_loader (tc_loader.Test1)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kniht/code/ranger/test/tc_loader.py", line 51, in test_loader
    dir.load_content(schedule=True)
  File "test/../ranger/fsobject/directory.py", line 266, in load_content
    self.load()
  File "test/../ranger/fsobject/fsobject.py", line 184, in load
    self.fm.update_preview(self.path)
AttributeError: 'OpenStruct' object has no attribute 'update_preview'

----------------------------------------------------------------------
Ran 63 tests in 0.133s

FAILED (errors=1)
make: *** [test] Error 1

I'm not familiar enough with the code to be sure, but it appears the correct fix is simply to mock self.fm.update_preview to do nothing:

--- a/test/tc_loader.py
+++ b/test/tc_loader.py
@@ -35,7 +35,7 @@ TESTDIR = realpath(join(dirname(__file__), 'testdir'))
 class Test1(unittest.TestCase):
        def test_loader(self):
                loader = Loader()
-               fm = OpenStruct(loader=loader)
+               fm = OpenStruct(loader=loader, update_preview=lambda path: None)
                SettingsAware.settings = Fake()
                FileManagerAware.fm = fm

ranger in tmux: weird behaviour

Hello,

I notice this weird behaviour when using ranger 1.5.5 with tmux.

This is the screenshot that explains the issue: http://imgur.com/xSS5wnq

On the left is ranger in tmux and in the middle is ranger opened in a terminal (rxvt-unicode).

Please let me know if you need more details.

Thanks
Joe

Add chromium opener to rifle.conf

I'm using Chromium browser and there is not default opener of text/html files set for Chromium. I have to type :open_with command each time opening an HTML file, and I think similar problem may exist for other Chromium users. So I'm wondering is it possible to add a following line to ranger/config/rifle.conf.

ext x?html?, has chromium, X, flag f = chromium -- "$@"

Thanks in advance.

Non-ASCII codes unreadable

Hi, hut

After I upgrade ranger to 1.4.4, I found my filenames or text-preview unreadable(chinese character in utf-8), it happens in master branch also.

Thanks.

path grabbing with tabs produces crash

Ranger crashes with the following traceback when opened with tabs and attempting to grab path, filenames etc with the default xsel binding. The behaviour under different python versions is a little inconsistent, under python3 this crash will occur when ranger is opened from a normal terminal whereas under python2 it only crashes when using terminalprogram -x to launch a new terminal with ranger.

It's not new behaviour, I've consistently observed this since the path grabbing was introduced but hadn't found time to rule out problems on my end.

xsel is installed, testing was done with current git build and under openbox in archlinux.

python3:

  • ranger /mnt/cthulhu /home/lashni

python2:

  • terminator -m -x ranger /home/lashni /mnt/mythos
  • gnome-terminal --maximize -x ranger /mnt/cthulhu /mnt/mythos
Ranger version: 1.5.0, executed with python 3.2.2
Locale: en_AU.UTF-8
Current file: /home/lashni/bin
Traceback (most recent call last):
  File "/usr/lib/python3.2/site-packages/ranger/core/main.py", line 103, in main
    fm.loop()
  File "/usr/lib/python3.2/site-packages/ranger/core/fm.py", line 202, in loop
    ui.handle_input()
  File "/usr/lib/python3.2/site-packages/ranger/gui/ui.py", line 210, in handle_input
    self.handle_key(key)
  File "/usr/lib/python3.2/site-packages/ranger/gui/ui.py", line 146, in handle_key
    self.press(key)
  File "/usr/lib/python3.2/site-packages/ranger/gui/ui.py", line 161, in press
    quantifier=keybuffer.quantifier)
  File "/usr/lib/python3.2/site-packages/ranger/core/actions.py", line 111, in execute_console
    string = self.substitute_macros(string, additional=macros)
  File "/usr/lib/python3.2/site-packages/ranger/core/actions.py", line 115, in substitute_macros
    return _MacroTemplate(string).safe_substitute(self._get_macros(),
  File "/usr/lib/python3.2/site-packages/ranger/core/actions.py", line 152, in _get_macros
    macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
AttributeError: 'NoneType' object has no attribute 'path'

Ranger crashed.  Please report this traceback at:
http://savannah.nongnu.org/bugs/?group=ranger&func=additem
Ranger version: 1.5.0, executed with python 2.7.2
Locale: en_AU.UTF-8
Current file: /home/lashni/arch
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ranger/core/main.py", line 103, in main
    fm.loop()
  File "/usr/lib/python2.7/site-packages/ranger/core/fm.py", line 202, in loop
    ui.handle_input()
  File "/usr/lib/python2.7/site-packages/ranger/gui/ui.py", line 210, in handle_input
    self.handle_key(key)
  File "/usr/lib/python2.7/site-packages/ranger/gui/ui.py", line 146, in handle_key
    self.press(key)
  File "/usr/lib/python2.7/site-packages/ranger/gui/ui.py", line 161, in press
    quantifier=keybuffer.quantifier)
  File "/usr/lib/python2.7/site-packages/ranger/core/actions.py", line 111, in execute_console
    string = self.substitute_macros(string, additional=macros)
  File "/usr/lib/python2.7/site-packages/ranger/core/actions.py", line 115, in substitute_macros
    return _MacroTemplate(string).safe_substitute(self._get_macros(),
  File "/usr/lib/python2.7/site-packages/ranger/core/actions.py", line 152, in _get_macros
    macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
AttributeError: 'NoneType' object has no attribute 'path'

Ranger crashed.  Please report this traceback at:
http://savannah.nongnu.org/bugs/?group=ranger&func=additem

"open_with" complete command from $PATH

Hi, hut

I believe it will be more convenient if "TAB" can complete command from $PATH when invoke "open_with". Could you please add this feature to your todo list? Thank you.

solarized colorscheme

Hello,

I modified the default colorscheme that ranger and ls output look more unique. Perhaps somebody wants to use it as well. So here it is.

# Joseph Tannhuber <[email protected]>, 2013
# Solarized like colorscheme, similar to solarized-dircolors
# from https://github.com/seebi/dircolors-solarized.
# This is a modification of Roman Zimbelmann's default colorscheme.
# This software is distributed under the terms of the GNU GPL version 3.

from ranger.gui.colorscheme import ColorScheme
from ranger.gui.color import *

class Solarized(ColorScheme):
    progress_bar_color = blue

    def use(self, context):
        fg, bg, attr = default_colors

        if context.reset:
            return default_colors

        elif context.in_browser:
            fg = 244
            if context.selected:
                attr = reverse
            else:
                attr = normal
            if context.empty or context.error:
                bg = red
            if context.border:
                fg = default
            if context.media:
                if context.image:
                    fg = 136
                else:
                    fg = 166
            if context.container:
                fg = 61
            if context.directory:
                fg = 33
            elif context.executable and not \
                    any((context.media, context.container,
                        context.fifo, context.socket)):
                fg = 64
                attr |= bold
            if context.socket:
                fg = 136
                bg = 230
                attr |= bold
            if context.fifo:
                fg = 136
                bg = 230
                attr |= bold
            if context.device:
                fg = 244
                bg = 230
                attr |= bold
            if context.link:
                fg = context.good and 37 or 160
                bg = context.bad and 235
                attr |= bold
            if context.tag_marker and not context.selected:
                attr |= bold
                if fg in (red, magenta):
                    fg = white
                else:
                    fg = red
            if not context.selected and (context.cut or context.copied):
                fg = 234
                attr |= bold
            if context.main_column:
                if context.selected:
                    attr |= bold
                if context.marked:
                    attr |= bold
                    bg = 237
            if context.badinfo:
                if attr & reverse:
                    bg = magenta
                else:
                    fg = magenta

        elif context.in_titlebar:
            attr |= bold
            if context.hostname:
                fg = context.bad and 160 or 93
                bg = context.bad and 235
            elif context.directory:
                fg = 33
            elif context.tab:
                fg = context.good and 47 or 33
                bg = 239
            elif context.link:
                fg = cyan

        elif context.in_statusbar:
            if context.permissions:
                if context.good:
                    fg = 93
                elif context.bad:
                    fg = 160
            if context.marked:
                attr |= bold | reverse
                fg = 237
            if context.message:
                if context.bad:
                    attr |= bold
                    fg = 160
                    bg = 235
            if context.loaded:
                bg = self.progress_bar_color

        if context.text:
            if context.highlight:
                attr |= reverse

        if context.in_taskview:
            if context.title:
                fg = 93

            if context.selected:
                attr |= reverse

            if context.loaded:
                if context.selected:
                    fg = self.progress_bar_color
                else:
                    bg = self.progress_bar_color

        return fg, bg, attr

Background of item remains highlighted in tmux

When moving between files and directories in tmux, the background of the item remains highlighted. Also, when moving into another directory, if the previous file name was bigger than the current file at the same position in the list, the larger part still appears. This only happens in tmux, on two arch distributions of linux computers. I have tried recent patches of tmux, but I think this is a ranger issue. Pressing to redraw_window() still works. If the columns are similar in size to the filename length, this doesn't occur.

why non-text files' default opener is editor?

Hi, hut

Why non-text files' default opener is editor now? It invoked open_with before.

I think the old way is better. We can't describe all types in rifle.conf, so many types are defined as unknown non-text types, it's not appropriate to open them all with editor.

I am so addicted to vim and ranger. I pressed "l, l, l", and bang! I opened a 2GB binary data file with vim by accident...

'cw' can overwrite files without warning

If you use cw in ranger to rename a file to a filename that already exists, this file is overwritten without warning. Ranger should give a warning or refuse the rename.

Copy-pasting same name directory unexpected behavior

Copying and pasting a directory when a directory with the same name already exists (e.g., trying to duplicate a directory) instead places a copy within that directory.

E.g. doing yypp on a directory called tmp results in the directories tmp and tmp/tmp instead of tmp and tmp.1

PDF Files Are Not Seen as Documents

In fsobject/fsobject.py:

self.document = self._mimetype.startswith('text')

Won't capture PDF files and a bunch of other document mime types.

delete with argument deletes selection

when issuing ":delete file1" while file2 is selected, file2 is, as intended according to man where it nowhere mentions arguments, deleted
Since however a wrong delete can be critical perhaps it would be a good thing to err on the bright side and either show an error or accept the argument as file name.

Exception when passing a path to the file as argument

ranger ~/somedir/ works fine, while ranger ~/somedir/somefile raises exception:

Traceback (most recent call last):
  File "/usr/lib/python3.2/site-packages/ranger/core/runner.py", line 227, in __call__
    self.fm.signal_emit('runner.execute.before',
AttributeError: 'NoneType' object has no attribute 'signal_emit'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/ranger", line 52, in <module>
    sys.exit(ranger.main())
  File "/usr/lib/python3.2/site-packages/ranger/core/main.py", line 85, in main
    runner(files=[File(target)], mode=arg.mode, flags=arg.flags)
  File "/usr/lib/python3.2/site-packages/ranger/core/runner.py", line 242, in __call__
    self.fm.signal_emit('runner.execute.after',
AttributeError: 'NoneType' object has no attribute 'signal_emit'

Segmentation Faults since 5417dda5

I've been experiencing irregular segfaults in ranger-master for which I can't figure out the reasons. Here is all the info I got:

  • It started around the time of commit 5417dda
  • I think it is a problem with curses' addstr/addnstr function
  • It happens randomly, there is no specific action that causes it
  • It happens more often with python3 than with python2
  • It's most likely somewhere in here: git diff master 5417dda5^ ranger/gui/widgets/browsercolumn.py - but I don't see anything wrong.

Please post any clues you got.

python fork crashing in cygwin on file preview

When operating ranger in Cygwin, as I preview files in the last pane, I am coming into problems where the window overlay occasionally displays an error like :

25076474 [main] python 4808 C:\cygwin\bin\python.exe: *** fatal error - unable to remap \\?\C:\cygwin\lib\python2.6\lib-dynload\select.dll to same address as parent: 0x2D0000 != 0x3D0000
 tags                                                                                          25090441 [main] python 5876 fork: child 4808 - died waiting for dll loading, errno 11

The command window at the bottom of ranger states:

file descriptor out of range in select()

or

[Errno 11] Resource temporarily unavailable

About 1 out of every 4 views will actually show a preview, the rest will show an error. I figure this is just some issue with Cygwin, but wanted to post an issue just in case.

support mc's extfs via avfsd

I find this feature useful, you can treat rar,zip,iso as normal directory,
and even ftp.

May be just a little to do with action::cd.

I like your ranger so much, thanks.

[scope.sh] Bash is not available in every platform.

/bin/bash is not available in every platform and scope.sh will not work without it.
A first step would be to change the shebang line to #!/usr/bin/env bash and include bash as an optional requirement.
Ideally, it could be replaced with python or a more universally available shell.

Tab names

Enough said, its hard to remember on which tab is what when you only have numbers... vim has this too.

"--" argument is badly supported

Hi, hut

As $subject, most programs don't support "--" argument.

For example, libreoffice doesn't support, but rifle.conf does.

And I recommend you to remove "--" from open_with, most programs fails, and all my scripts use for args in "$@" fails. Please...

[REQUEST] Move the 'last directory' bookmark out of the bookmarks file

This may seem pretty minor, but in trying to keep my ranger bookmarks synchronized between different machines (or when keeping dotfiles in version control), having the 'last directory' bookmark in the bookmarks file is a minor annoyance since it constantly changes. To avoid getting pestered by git or unison about changes/conflicts, I have to ignore the bookmarks file, which is a pain, because I've got a bunch of bookmarks that I like to keep synchronized!

Perhaps a small temporary file or something similar?

Thanks!
Scott

separate default apps from python

you can actually let python to parse a list of default programs.

i.e.
file extension:program1,program2,program3
doc:libreoffice,openoffice

so users dont have to touch ranger to modify the default programs.
I think the current default.py is really messy because each time a program is added, you will have to add a new handler or modify the python code.

About preview!

Hello, i want to change highlight style, when i try change scope.sh

try highlight --style=vampire --out-format=ansi "$path" && { dump | trim; exit 5; } || exit 2;;

highlight missing.
What i do wrong?

bookmarks file owner

every now and then i start ranger as "su" which works just fine, but after closing ranger it changes the owner and the group of the bookmarks file of my normal user to root, which isn't very nice.
It isn't a very big deal but maybe it would be easy to change that? I don't know, but ranger is the best i wanna say. Thanks

":grep" output contains visible ANSI escape codes

For instance, ":grep GNU" from ranger base dir gives:
ESC[35mESC[K/home/cci/projects/ranger/doc/help/init.pyESC[mESC[KESC[36mESC[K
:ESC[mESC[KESC[32mESC[K4ESC[mESC[KESC[36mESC[K:ESC[mESC[K# it under the terms of
the ESC[01;31mESC[KGNUESC[mESC[K General Public License as published by
...

Allow executing commands or set options using command line parameters

Ranger should allow executing commands from command line parameters like vim -c

This is useful for example in file picker mode, to show only files with some extension (hidden_filter preference)

Since -c is already used by ranger, maybe it should use vim's other syntax vim +command

e.g: ranger --choosefile=file +'set hidden_filter=foobar'

should not read stdin

Once, I run "ps -A | ranger" by mistake, and the home directory almost messed up. I think ranger really should not read stdin by default. Feature or Bug?

set screen/tmux's window name

Hi, hut

How about adding a feature to set screen/tmux's window name automatically? It's easy, printf "\ekranger\e\\" > /dev/tty is enough.

Sure, we can use screen's shelltitle trick, but after we open a shell with "S" in ranger and come back, the name becomes "exit". So, this feature(especially when come back from shell) will be better.

Thank you.

"Failed to run:" for any external program

Hitting enter on any file should launch it in external program like PDF viewer or mplayer. Ranger, however, fails to run any external program except console-based programs like vim.
I tried to see what's happening and modified runner.py, line 191:

    try:
        process = None
        try:
            process = Popen(**popen_kws)
        except OSError as e:
            self._log("Execution failed:" + e.strerror)

The exception was Bad file descriptor. Since I don't know python I can't figure out what to do. Can someone give a hint at least?

versions: python 3.2, ranger 1.4.1 (stable)

Overwrite key mapping

Hi Hut,
I recently switched to the colemak keyboard layout (http://colemak.com). The j and k letters are replaced with n and e. So I tried to overwrite ranger mappings in ~/.config/ranger/keys.py:

from ranger.api.keys import *
map = vim_aliases = KeyMapWithDirections()
map.dir('n', alias='<down>')
map.dir('e', alias='<up>')

The new e mapping works well. n does not. I think it is because n is already mapped by ranger.
So I'd like to replace this mapping with mine, but I can't figure out how to proceed. Any help would be much appreciated.

scope.sh: regard exit code 141 (SIGPIPE) of highlight as success too

I was using the scope.sh that ships with Ranger for previews. But it turned out Ranger wasn't able to highlight (quite a few of) program sources, and my investigation shows that it's due to highlight not taking care of SIGPIPE:

~/tmp$ for i in `seq 200`; do echo '#include <stdio.h>' >> a.c; done
~/tmp$ highlight --out-format=ansi a.c | sed 1q; echo ${PIPESTATUS[@]}
#include <stdio.h>
141 0

141 = 128 + 13, and signal 13 is SIGPIPE. A bit weirdly this is not always happening; the cases I can identify is when the source is much longer than the part you're preserving with head -n $x (sed ${x}q in case you find head harmful like I do. :) So for programs that are a lot longer than 200 lines (the value of $maxln in scope.sh) there is a chance for highlight to exit with 141, and scope.sh sees that as a failure, returning 1 and causing Ranger to fall back to cat.

This can be solved with either of these 2 solutions:

Modify success to regard 141 as "success" exit code (works for me):

function success { local p=${PIPESTATUS[0]}; test $p = 0 -o $p = 141; }

Write a little wrapper for highlight (not tested):

function highlight { command highlight "$@"; test $? = 0 -o $? = 141; }

Request: Output final directory somewhere at exit?

So I just found this project, I haven't even installed it so sorry if I missed something already implemented...

One thing that irks me about CLI file browsers/managers is that I leave the directory after I close the manager. And I close them a lot. Changes in the directory made by an external program (shell script, Ranger, vim, what have you) persist only within that application, not in the parent shell.

Functions, at least in Zsh, on the other hand, can modify the parent shell's directory, settings, etc. So some type of simple function such as ranger(){ ranger --dir-out /tmp/ranger.dir ; cd $(cat /tmp/ranger.dir)} would be just perfect for me.

Yay or nay?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.