You are not logged in.

#1576 2013-02-10 16:33:31

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

I'd like to thank PotatoesMaster here for implementing an interface to the w3mimgpreview program that allows ranger to draw images in the terminal. :3

imgpreview.png

It's not 100% ready yet, for example sometimes it draws black lines over the image, but it's usable already. I'll continue to work on better integration. You can get it by installing w3m, updating ranger-git and setting "preview_images" to "true", for example by executing this:

echo "set preview_images true" >> ~/.config/ranger/rc.conf

Note that it will not work on some terminals like gnome-terminal. I tested it successfully on xterm and rxvt-unicode.


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1577 2013-02-10 16:39:29

eruditorum
Member
Registered: 2012-11-12
Posts: 130

Re: Ranger, a textbased filemanager

Whoaaa!

Offline

#1578 2013-02-10 17:12:56

OK100
Member
From: [U==]
Registered: 2010-04-26
Posts: 455

Re: Ranger, a textbased filemanager

Hehe, that's really neat feature. Works fine here.

EDIT: Just noticed that it doesn't work in tmux. The image fills the whole window and leaves the terminal in weird state.
The issue is probably in _get_font_dimensions() function. For me, the function returns "(7, 14)" outside and "(0, 0)" inside tmux.

Last edited by OK100 (2013-02-10 18:40:28)

Offline

#1579 2013-02-10 20:02:16

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Ranger, a textbased filemanager

Super awesome!!!
Is it possible to show some infos (e.g. exif infos etc.) about the image on top? Because I like that as a preview content as well.

Is this also possible for videos?

Last edited by Army (2013-02-10 20:02:43)

Offline

#1580 2013-02-10 20:30:12

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

OK100 wrote:

Hehe, that's really neat feature. Works fine here.

EDIT: Just noticed that it doesn't work in tmux. The image fills the whole window and leaves the terminal in weird state.
The issue is probably in _get_font_dimensions() function. For me, the function returns "(7, 14)" outside and "(0, 0)" inside tmux.

For me, it loads the image in tmux (i experience some lag) but nothing is drawn. I made ranger automatically disable the feature when the font dimensions are zero, thanks for the input. Btw. w3m displays no images in tmux either.

@Army: videos? are you drunk? smile I think gifs are supported theoretically, see http://w3m.cvs.sourceforge.net/viewvc/w … README.img
About additional infos: I didn't think of that, but it shouldn't be too hard. If you write a feature request in the bug tracker, I'll get to it eventually.


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1581 2013-02-11 05:55:43

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Hello everybody!
Recently I've tried 'extracthere' command from https://wiki.archlinux.org/index.php/Ranger#Extraction and there is a problem with  ranger-master 1.5.5.  When I extract a big rar archive (about 700 Mb) only about first 140 Mb are extracted, then the task hangs untill be removed manually. But with '1l' hotkey (aunpack -- "$@") all works fine. Is the code of 'extracthere' obsolete?

Some updates:
Even when the extraction task is killed with 'dd' in taskview, the aunpack process still exists. After some seconds aunpack successfully extracts the remain part of the archive.

Last edited by loop (2013-02-11 06:08:56)

Offline

#1582 2013-02-11 11:20:50

theGunslinger
Member
Registered: 2011-05-20
Posts: 300

Re: Ranger, a textbased filemanager

Is w3m all I need? I have the 0211 ranger from git and I've enabled the preview but when starting ranger it says

Preview script undefined or not found!

Offline

#1583 2013-02-11 12:23:21

PotatoesMaster
Member
From: France
Registered: 2010-08-26
Posts: 54

Re: Ranger, a textbased filemanager

theGunslinger wrote:

Is w3m all I need?

w3m is all you need for image preview. Therefore you should be able to see image yet.

theGunslinger wrote:
Preview script undefined or not found!

Your problem is that the file ~/.config/ranger/scope.sh does not exist. It is a shell script file for enhanced text preview, using pdf2text, w3m or links, atools and other programs to display informations in the preview pane (the default preview can only display content of plain text files).

You can copy this file from the default by running

ranger --copy-config=scope

Offline

#1584 2013-02-11 12:43:07

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Ranger, a textbased filemanager

hut wrote:

@Army: videos? are you drunk? smile I think gifs are supported theoretically, see http://w3m.cvs.sourceforge.net/viewvc/w … README.img

I hope I was sober wink No I just didn't express myself right, I thought of preview thumbnails, e.g. call a script which creates an image which then is being displayed.

hut wrote:

About additional infos: I didn't think of that, but it shouldn't be too hard. If you write a feature request in the bug tracker, I'll get to it eventually.

Will do!

Offline

#1585 2013-02-11 16:53:29

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

Army wrote:
hut wrote:

@Army: videos? are you drunk? smile I think gifs are supported theoretically, see http://w3m.cvs.sourceforge.net/viewvc/w … README.img

I hope I was sober wink No I just didn't express myself right, I thought of preview thumbnails, e.g. call a script which creates an image which then is being displayed.

You can use

ffmpeg -loglevel quiet -i INPUTFILE -f mjpeg -t 0.0001 -ss 0 -y OUTPUTFILE

(where OUTPUTFILE can be "-" [and is a .jpg, I believe]) to make the thumbnail, FYI.

If you use "-ss 5" it'll be a more useful frame (taken 5 seconds in, not 0) but also take longer to make.

I've been looking at w3mimgdisplay and I've no idea how to make it read from stdin, so I'd suggest (to hut or other programmer who knows what he's doing) saving to tmp somewhere and then reading from that.

Army wrote:
hut wrote:

About additional infos: I didn't think of that, but it shouldn't be too hard. If you write a feature request in the bug tracker, I'll get to it eventually.

Will do!

I'd like to add a request too. Can you skip the previewing of images > 1MB or so? I'll put in a feature request if others agree.

Finally, thanks for this update, hut. It's good to see it's still improving at quite a pace.

Last edited by Veedrac (2013-02-11 16:55:29)

Offline

#1586 2013-02-11 17:25:45

OK100
Member
From: [U==]
Registered: 2010-04-26
Posts: 455

Re: Ranger, a textbased filemanager

hut wrote:
OK100 wrote:

Hehe, that's really neat feature. Works fine here.

EDIT: Just noticed that it doesn't work in tmux. The image fills the whole window and leaves the terminal in weird state.
The issue is probably in _get_font_dimensions() function. For me, the function returns "(7, 14)" outside and "(0, 0)" inside tmux.

For me, it loads the image in tmux (i experience some lag) but nothing is drawn. I made ranger automatically disable the feature when the font dimensions are zero, thanks for the input. Btw. w3m displays no images in tmux either.

If I write window dimensions directly into the function like this:

def _get_font_dimensions():
    """
    Get the height and width of a character displayed in the terminal in
    pixels.
    """
    s = struct.pack("HHHH", 0, 0, 0, 0)
    fd_stdout = sys.stdout.fileno()
    x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
    rows, cols, xpixels, ypixels = struct.unpack("HHHH", x)

    xpixels, ypixels = (1024, 584)

    return (xpixels // cols), (ypixels // rows)

the image is displayed correctly:
taGZsZw

Offline

#1587 2013-02-12 04:20:10

trilla
Member
Registered: 2012-09-27
Posts: 8

Re: Ranger, a textbased filemanager

Hi all, i try change color-scheme preview window. but i can't do
I know ranger use ./scope.sh for preview and then scope.sh use highlight.
highlight have many color-scheme (higlight -w), and set color-scheme can highlight --style=...
i edit ./scope.sh
highlight --style=vampire  --out-format=ansi "$path" | head -n $maxln
but nothing happen, what i do wrong?

Offline

#1588 2013-02-12 05:16:42

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Hi, @trilla, try to change '--out-format=ansi' for something else (e.g. '--out-format=xterm256')
--style=<something> takes effect then.

Last edited by loop (2013-02-12 05:19:29)

Offline

#1589 2013-02-12 06:04:11

trilla
Member
Registered: 2012-09-27
Posts: 8

Re: Ranger, a textbased filemanager

loop wrote:

Hi, @trilla, try to change '--out-format=ansi' for something else (e.g. '--out-format=xterm256')
--style=<something> takes effect then.

try
highlight --style=vampire  --out-format=xterm256 "$path" | head -n $maxln
highlight --out-format=xterm256 "$path" | head -n $maxln
but nothing happen, only miss highlight on preview

Offline

#1590 2013-02-12 07:16:21

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

@trilla
Hmm...
I'm not sure, but does your terminal supports 256 colors and have it enabled?
I've just checked out, 'highlight --style=vampire  --out-format=xterm256 "$path" | head -n $maxln' works fine for rxvt-unicode-256color  (in my case).

Offline

#1591 2013-02-13 00:06:43

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

I didn't know about the --out-format=xterm256 option, it's pretty awesome smile
Bribe me now to decide which style will be used by default in scope.sh smile

trilla wrote:
loop wrote:

Hi, @trilla, try to change '--out-format=ansi' for something else (e.g. '--out-format=xterm256')
--style=<something> takes effect then.

try
highlight --style=vampire  --out-format=xterm256 "$path" | head -n $maxln
highlight --out-format=xterm256 "$path" | head -n $maxln
but nothing happen, only miss highlight on preview

Does colored preview work with an unmodified scope.sh?
Does the highlight command work outside of ranger? Like if you simply type

highlight --out-format=xterm256 --style=vampire my_code_file.c

If you're using linux mint, maybe this is your problem: http://forums.linuxmint.com/viewtopic.php?t=122220

Can't say more than that, because for me it works.

Last edited by hut (2013-02-13 00:07:33)


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1592 2013-02-13 03:05:45

trilla
Member
Registered: 2012-09-27
Posts: 8

Re: Ranger, a textbased filemanager

hut wrote:

I didn't know about the --out-format=xterm256 option, it's pretty awesome smile
Bribe me now to decide which style will be used by default in scope.sh smile

trilla wrote:
loop wrote:

Hi, @trilla, try to change '--out-format=ansi' for something else (e.g. '--out-format=xterm256')
--style=<something> takes effect then.

try
highlight --style=vampire  --out-format=xterm256 "$path" | head -n $maxln
highlight --out-format=xterm256 "$path" | head -n $maxln
but nothing happen, only miss highlight on preview

Does colored preview work with an unmodified scope.sh?
Does the highlight command work outside of ranger? Like if you simply type

highlight --out-format=xterm256 --style=vampire my_code_file.c

If you're using linux mint, maybe this is your problem: http://forums.linuxmint.com/viewtopic.php?t=122220

Can't say more than that, because for me it works.

Yes, default colored preview work, and if i use

highlight --out-format=xterm256 --style=vampire my_code_file.c

work too
But if i changed scope.sh, try changed --style, colored preview crashed
i just want changed colored style smile

Last edited by trilla (2013-02-13 03:06:57)

Offline

#1593 2013-02-13 03:33:46

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

trilla wrote:
hut wrote:

I didn't know about the --out-format=xterm256 option, it's pretty awesome smile
Bribe me now to decide which style will be used by default in scope.sh smile

trilla wrote:

try
highlight --style=vampire  --out-format=xterm256 "$path" | head -n $maxln
highlight --out-format=xterm256 "$path" | head -n $maxln
but nothing happen, only miss highlight on preview

Does colored preview work with an unmodified scope.sh?
Does the highlight command work outside of ranger? Like if you simply type

highlight --out-format=xterm256 --style=vampire my_code_file.c

If you're using linux mint, maybe this is your problem: http://forums.linuxmint.com/viewtopic.php?t=122220

Can't say more than that, because for me it works.

Yes, default colored preview work, and if i use

highlight --out-format=xterm256 --style=vampire my_code_file.c

work too
But if i changed scope.sh, try changed --style, colored preview crashed
i just want changed colored style smile

Can you paste the whole scope.sh? What's the output of "ranger --version"?


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1594 2013-02-13 07:31:15

trilla
Member
Registered: 2012-09-27
Posts: 8

Re: Ranger, a textbased filemanager

ranger --version
ranger 1.5.5 (stable)
cat ~/scope.sh
#!/bin/bash
# ranger supports enhanced previews.  If the option "use_preview_script"
# is set to True and this file exists, this script will be called and its
# output is displayed in ranger.  ANSI color codes are supported.

# NOTES: This script is considered a configuration file.  If you upgrade
# ranger, it will be left untouched. (You must update it yourself.)
# Also, ranger disables STDIN here, so interactive scripts won't work properly

# Meanings of exit codes:
# code | meaning    | action of ranger
# -----+------------+-------------------------------------------
# 0    | success    | success. display stdout as preview
# 1    | no preview | failure. display no preview at all
# 2    | plain text | display the plain content of the file
# 3    | fix width  | success. Don't reload when width changes
# 4    | fix height | success. Don't reload when height changes
# 5    | fix both   | success. Don't ever reload

# Meaningful aliases for arguments:
path="$1"    # Full path of the selected file
width="$2"   # Width of the preview pane (number of fitting characters)
height="$3"  # Height of the preview pane (number of fitting characters)

maxln=200    # Stop after $maxln lines.  Can be used like ls | head -n $maxln

# Find out something about the file:
mimetype=$(file --mime-type -Lb "$path")
extension=${path##*.}

# Functions:
# "have $1" succeeds if $1 is an existing command/installed program
function have { type -P "$1" > /dev/null; }
# "success" returns the exit code of the first program in the last pipe chain
function success { test ${PIPESTATUS[0]} = 0; }

case "$extension" in
	# Archive extensions:
	7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
	rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
		als "$path" | head -n $maxln
		success && exit 0 || acat "$path" | head -n $maxln && exit 3
		exit 1;;
	# PDF documents:
	pdf)
		pdftotext -l 10 -nopgbrk -q "$path" - | head -n $maxln | fmt -s -w $width
		success && exit 0 || exit 1;;
	# BitTorrent Files
	torrent)
		transmission-show "$path" | head -n $maxln && exit 3
		success && exit 5 || exit 1;;
	# HTML Pages:
	htm|html|xhtml)
		have w3m    && w3m    -dump "$path" | head -n $maxln | fmt -s -w $width && exit 4
		have lynx   && lynx   -dump "$path" | head -n $maxln | fmt -s -w $width && exit 4
		have elinks && elinks -dump "$path" | head -n $maxln | fmt -s -w $width && exit 4
		;; # fall back to highlight/cat if theres no lynx/elinks
esac

case "$mimetype" in
	# Syntax highlight for text files:
	text/* | */xml)
		#highlight --style=vampire  --out-format=ansi "$path" | head -n $maxln 
		#highlight --out-format=xterm256 "$path" | head -n $maxln 
		highlight --out-format=ansi "$path" | head -n $maxln 
		success && exit 5 || exit 2;;
	# Ascii-previews of images:
	image/*)
		img2txt --gamma=0.6 --width="$width" "$path" && exit 4 || exit 1;;
	# Display information about media files:
	video/* | audio/*)
		have exiftool && exiftool "$path" && exit 5
		# Use sed to remove spaces so the output fits into the narrow window
		if have mediainfo; then
			mediainfo "$path" | sed 's/  \+:/: /;'
			success && exit 5
		fi
		exit 1;;
esac

exit 1

Offline

#1595 2013-02-13 14:01:31

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

trilla wrote:
ranger --version
ranger 1.5.5 (stable)

There's the problem :S ranger 1.5.5 doesn't support 256-color previews yet. Either wait some time for 1.6 or get ranger-git. If you experience weird bugs after upgrading, your config is probably out of date.


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1596 2013-02-13 21:04:06

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

THIS IS OLD AND BROKEN, SEE A FEW POSTS BELOW

If anyone uses my :travel or :narrow commands, I've made new versions that work ONLY with the VERY LATEST Ranger from git. They are a very fast way of moving around directories and, well, travelling. Assign them to a keyboard shortcut, press it and just type your way through to where you want to be. They filter and move as you type, so all you need to do is hit letters and once it knows enough to move you on it'll try to do so.

They're much nicer as they don't use :filter hack-ish-ly anymore, but instead monkeypatch their own filter on top (so you can use them safely in conjunction with the normal filter).

They have support for missing characters so a search of "abc" will match "abracadabra" and "elephant_bucket".
Please note that they do not use regex for this, which was a purposeful choice in order to support non-escaped special characters.

They have "intelligent" case matching, so "abCde" will match "aBCdE" but not "aBcdE" - lowercase match both and uppercase match just upppercase.

".." still goes back a directory for :travel, as a reminder.

They now should work even if you rename them.

They're now commented and coded a little nicer, although I'd prefer removing the monkeypatch somehow.

THIS IS OLD AND BROKEN, SEE A FEW POSTS BELOW

from ranger.fsobject import directory

old_accept_file = directory.accept_file

directory.global_tmp_filter = ""

def accept_file(fname, dirname, hidden_filter, name_filter):
    # Apply all of the old filters
    if old_accept_file(fname, dirname, hidden_filter, name_filter):

        try:
            ifname = iter(fname)
            for letter in directory.global_tmp_filter:
                # Scan across ifname for letter
                while True:
                    # if lowercase, don't be case sensitive
                    if letter.islower() and letter == next(ifname).lower():
                            break
                    elif letter == next(ifname):
                            break

            # global_tmp_filter has ended before ifname, so is contained sequentially in ifname
            return True

        # ifname has ended before global_tmp_filter, so doesn't contain all of global_tmp_filter sequentially
        except StopIteration:
            return False

    return False

directory.accept_file = accept_file

class narrow(Command):
    """
    :narrow <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection and removes the filter.
    """

    def execute(self):
        self.cancel() # Clean up
        self.fm.move(right=1)

    def cancel(self):
        directory.global_tmp_filter = ""
        self.fm.thisdir.load_content(schedule=False)

    def quick(self):
        directory.global_tmp_filter = self.rest(1)
        self.fm.thisdir.load_content(schedule=False)

    def tab(self):
        if self.fm.env.cwd.files[-1] is not self.fm.env.cf:
            self.fm.move(down=1)
        else:
            self.fm.move(to=0)

class travel(Command):
    """
    :travel <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection, removes the filter and starts another :travel command.
    """

    def execute(self, *, special=False):
        self.cancel() # Clean

        if special:
            self.fm.cd(special)

            # Don't block ".." to allow chaining
            if special != "..":
                self.fm.block_input(0.5)

            special = False

        else:
            self.fm.move(right=1)

        self.updated_line = self.__class__.__name__ + " "

    def cancel(self):
        directory.global_tmp_filter = ""
        self.fm.thisdir.load_content(schedule=False)

    def quick(self):
        arg = self.rest(1)

        directory.global_tmp_filter = arg
        self.fm.thisdir.load_content(schedule=False)

        if arg == ".":
            return # Make sure we can always use ".."

        elif arg == "..":
            return self.execute(special="..")

        # Quick-travel
        elif len(self.fm.env.cwd.files) == 1:
            return self.execute(special=self.fm.env.cwd.files[0].basename)

    def tab(self):
        if self.fm.env.cwd.files[-1] is self.fm.env.cf:
            # We're at the bottom, so wrap
            self.fm.move(to=0)
        else:
            self.fm.move(down=1)

If you do use (and like) them (or want to), don't be afraid to ask questions.

Last edited by Veedrac (2013-02-14 18:38:50)

Offline

#1597 2013-02-14 03:57:05

dag
Member
From: US
Registered: 2013-01-20
Posts: 216

Re: Ranger, a textbased filemanager

I cant quit get my head around python is there a way to chown something like :chown username:group?

btw I am loving this file manager text based awsomeness


--------------------------------------
alcoves wonder creates the wonder unto the ages; never lose that.

Offline

#1598 2013-02-14 05:22:34

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

Yeah, type "@chown username:group". It will expand to ":shell chown username:group %s"


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1599 2013-02-14 05:53:32

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

@Vee, thank you, :travel and :narrow are pretty cool. wink
As opposed to :find, :travel executes directories only, but not files, right?

Last edited by loop (2013-02-14 06:13:42)

Offline

#1600 2013-02-14 14:22:27

bslackr
Member
Registered: 2012-01-27
Posts: 131

Re: Ranger, a textbased filemanager

I'm trying to get sxiv to open all the images in the current directory starting with the current file (like it says in the documentation), but sxiv only opens the one file. I put

mime^image,              X, flag f = ~/.config/ranger/rifle_sxiv.sh "$@"

in my rifle.conf and downloaded the script and put it in the right place, but it's a no go.

~ % ranger --version
ranger-master 1.5.5

Python 3.3.0 (default, Dec 22 2012, 21:02:07) 
[GCC 4.7.2]

Offline

Board footer

Powered by FluxBB