You are not logged in.

#1451 2012-09-03 12:40:41

anekos
Member
Registered: 2012-07-09
Posts: 3

Re: Ranger, a textbased filemanager

"SOLVED"

Veedrac wrote:

I was hoping for a nicer solution, but there seems to be no way to force loading a directory now, so here's my solution.
It's very badly tested, but it seems to work OK.

Thank you!
Works well for me.

Veedrac wrote:

Anyway, the idea is to reload the directory after you've changed it. However, that don' work. Thus, I just manually add the new directory to the Ranger. If making the directory fails, this might crash or summin', tho.

I added some codes for check it big_smile

https://gist.github.com/57f944441aac480feea6

Offline

#1452 2012-09-04 11:36:05

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

Re: Ranger, a textbased filemanager

Veedrac wrote:
anekos wrote:

How to make "mkdir and select_file" command?

I wrote the below code, but it does not works well.
https://gist.github.com/57f944441aac480feea6

self.fm.select_file(dirname) does not work on this code.
Immediately after mkdir, <dirname> does not exist on ranger...

I was hoping for a nicer solution, but there seems to be no way to force loading a directory now, so here's my solution.
It's very badly tested, but it seems to work OK.

class mkseldir(Command):
  """
  :mkseldir <dirname>

  Creates a directory with the name <dirname>, and select it.
  """

  def execute(self):
    from os.path import join, expanduser, lexists
    dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
    if not lexists(dirname):
      self.fm.mkdir(dirname)
      item = ranger.fsobject.directory.Directory(dirname, path_is_abs=True)
      item.load()
      self.fm.thisdir.files.append(item)
      self.fm.select_file(dirname)
    else:
      self.fm.notify("file/directory exists!", bad=True)

Anyway, the idea is to reload the directory after you've changed it. However, that don' work. Thus, I just manually add the new directory to the Ranger. If making the directory fails, this might crash or summin', tho.

The command to force a reload *now* is:

self.fm.thisdir.load_content(schedule=False)

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

Offline

#1453 2012-09-04 15:12:51

anekos
Member
Registered: 2012-07-09
Posts: 3

Re: Ranger, a textbased filemanager

hut wrote:

The command to force a reload *now* is:

self.fm.thisdir.load_content(schedule=False)

Very nice!!
It works perfect.

Thank you big_smile

Offline

#1454 2012-09-13 15:34:26

ibrunton
Member
From: Canada
Registered: 2011-05-05
Posts: 270

Re: Ranger, a textbased filemanager

I'm trying to write a function that will create a symlink to the current file, in a predefined directory that contains other symlinks with the same name followed by a number.  I.e., if that directory contains file-00 file-01 file-02, the command will link the current file to file-03.
This is what I have:

from os import symlink
from os.path import exists

class makemylink (Command):
    def execute (self):
        if self.fm.env.cf.is_directory:
            self.fm.notify ('File is a directory', bad=True)
        else:
            if self.arg(1):
                bname = self.arg(1)
            else:
                bname = self.fm.env.cf.basename

            i = 0
            while True:
                linkname = "~/mylinks/%(file)s-%(i)02d" % {'file': bname, 'i': i}
                if exists (linkname):
                    i = i + 1
                    continue
                else:
                    self.fm.notify (linkname)
                    symlink (self.fm.env.cf.path, linkname)
                    break

But it doesn't work.  "if exists (linkname)" always fails and executes the 'else' block, so that I'm getting '~/mylinks/file-00', even though that file (link) already exists.  I've tried using 'if lexists' and 'if islink', with the same results.

I'm not a python programmer.  Can someone tell me what I'm doing wrong with the 'if exists (linkname)' bit, please?

Thanks

Offline

#1455 2012-09-13 18:23:37

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

Re: Ranger, a textbased filemanager

ibrunton wrote:
from os import symlink
from os.path import exists

class makemylink (Command):
    def execute (self):
        if self.fm.env.cf.is_directory:
            self.fm.notify ('File is a directory', bad=True)
        else:
            if self.arg(1):
                bname = self.arg(1)
            else:
                bname = self.fm.env.cf.basename

            i = 0
            while True:
                linkname = "~/mylinks/%(file)s-%(i)02d" % {'file': bname, 'i': i}
                if exists (linkname):
                    i = i + 1
                    continue
                else:
                    self.fm.notify (linkname)
                    symlink (self.fm.env.cf.path, linkname)
                    break
from os.path import expanduser
linkname = expanduser(linkname)

I'll leave the integration, checking and testing as a task to you, but that should solve it.
Also, please use  "~/mylinks/{file}s-{i}02d".format(file=bname, i=i)
and "i += 1"
and remove the "continue"

NOTHING I WRITE IS TESTED

That said, nice code.

Offline

#1456 2012-09-13 18:43:57

ibrunton
Member
From: Canada
Registered: 2011-05-05
Posts: 270

Re: Ranger, a textbased filemanager

Veedrac wrote:
from os.path import expanduser
linkname = expanduser(linkname)

I'll leave the integration, checking and testing as a task to you, but that should solve it.
Also, please use  "~/mylinks/{file}s-{i}02d".format(file=bname, i=i)
and "i += 1"
and remove the "continue"

NOTHING I WRITE IS TESTED

That said, nice code.

Thanks, that did it!

Offline

#1457 2012-09-17 15:24:16

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

Re: Ranger, a textbased filemanager

Hi there!
This command is from my rc.conf:

eval fm.open_console('rename ' + fm.thisfile.basename.replace(' ', '_'))

It waits for Return to be pressed before runnig. How can I omit this Return pressing?
Thanks in advance.

Btw, what is the usual way to get the list of all fm methods and submethods (like fm.cd, fm.notify, fm.env.get_directory, etc)?

Last edited by loop (2012-09-17 16:19:27)

Offline

#1458 2012-09-17 18:18:23

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

Re: Ranger, a textbased filemanager

loop wrote:

Hi there!
This command is from my rc.conf:

eval fm.open_console('rename ' + fm.thisfile.basename.replace(' ', '_'))

It waits for Return to be pressed before runnig. How can I omit this Return pressing?
Thanks in advance.

Btw, what is the usual way to get the list of all fm methods and submethods (like fm.cd, fm.notify, fm.env.get_directory, etc)?

I believe you may want fm.execute_console(), but I am not *certain*

For your second question there is a far less defined answer. help(fm) would probably work best. You can run this inline ("eval help(fm)") while Ranger is loaded.

Offline

#1459 2012-09-19 10:49:30

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

Re: Ranger, a textbased filemanager

Hello, everyone.
@Veedrack, thank you again.

-----
Bring some points:

1. I have two files in directory. Their names (without quotes) are "1924_lg.jpg" and "1924069.jpg". With natural sort option enabled, the file "1924_lg.jpg" is on top of the ranger`s panel. But if I list files in my shell, the file "1924069.jpg" comes first. How can I change ranger`s behaviour to be shell identical?

2. Sometimes (can`t trace exact conditions) 'n' key stops working to find most recently modified file(s). Keys 'N' and 'cm' work neither at the moment. But if toggle search method for any other and back again, mtime search works properly. Have anyone else experienced that?

3. Ranger`s manual (opened with '?' key) dosn`t know about '-f' flag for forking and suggests '-d' flag.

4. As you can see on screenshot, files sizes are not displayed for filenames with non-ascii chars. Similar situation is about filescount for directories: screenshot.

5. Tried to change the :delete command to use the quick() function, but failed. I`m eager to press single key 'y' (without 'Enter') when ranger warns to delete files seriously. Such code modification is not trivial for me, any help would be appreciated.
-----
ranger-master 1.5.5
Python 2.7.3rc2 (default, Apr 22 2012, 22:35:38)
[GCC 4.6.3]

Last edited by loop (2012-09-20 18:35:33)

Offline

#1460 2012-09-20 22:42:43

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

Re: Ranger, a textbased filemanager

loop wrote:

Hello, everyone.
@Veedrack, thank you again.

*Veedrac, or Vee

loop wrote:

-----
Bring some points:

1. I have two files in directory. Their names (without quotes) are "1924_lg.jpg" and "1924069.jpg". With natural sort option enabled, the file "1924_lg.jpg" is on top of the ranger`s panel. But if I list files in my shell, the file "1924069.jpg" comes first. How can I change ranger`s behaviour to be shell identical?

Press "o". This will list the various sorting algorithms. Press "b" to chose "basename", which is probably what you want. To make this permanent, set "sort = 'basename'" in your ~/.config/ranger/options.py.

loop wrote:

2. Sometimes (can`t trace exact conditions) 'n' key stops working to find most recently modified file(s). Keys 'N' and 'cm' work neither at the moment. But if toggle search method for any other and back again, mtime search works properly. Have anyone else experienced that?

Can you restate the question? I don't follow what you're saying, sorry.
"n" will search in terms of make time until you do a real search, when it will find the next thing matching your search.

loop wrote:

3. Ranger`s manual (opened with '?' key) dosn`t know about '-f' flag for forking and suggests '-d' flag.

4. As you can see on screenshot, files sizes are not displayed for filenames with non-ascii chars. Similar situation is about filescount for directories: screenshot.

This is not a problem for me.

loop wrote:

5. Tried to change the :delete command to use the quick() function, but failed. I`m eager to press single key 'y' (without 'Enter') when ranger warns to delete files seriously. Such code modification is not trivial for me, any help would be appreciated.

Normally I would just go and make something, but I'm tired. This time, tell me *exactly* what you want it to do. Is it just :delete<RETURN>y instead of :delete<RETURN>y<RETURN>? I could do that, but sleep first [as if!].

loop wrote:

-----
ranger-master 1.5.5
Python 2.7.3rc2 (default, Apr 22 2012, 22:35:38)
[GCC 4.6.3]

Offline

#1461 2012-09-21 04:49:29

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

Re: Ranger, a textbased filemanager

Veedrac wrote:

*Veedrac, or Vee

Hello, Vee, sorry.

Veedrac wrote:

Press "o". This will list the various sorting algorithms. Press "b" to chose "basename", which is probably what you want. To make this permanent, set "sort = 'basename'" in your ~/.config/ranger/options.py.

Thats it, thank you!

Veedrac wrote:

Can you restate the question? I don't follow what you're saying, sorry.
"n" will search in terms of make time until you do a real search, when it will find the next thing matching your search.

Okay, I would catch the situation again and get more information about.

Veedrac wrote:

Normally I would just go and make something, but I'm tired. This time, tell me *exactly* what you want it to do. Is it just :delete<RETURN>y instead of :delete<RETURN>y<RETURN>? I could do that, but sleep first [as if!].

Yes, to save excess keypress it would be great to do just ":delete<RETURN>y" to delete files with confirmation. Any other characterc except "y" to be treated as rejection.
Sorry for my being annoying.

Offline

#1462 2012-09-21 16:26:13

Miblo
Member
From: Manchester, UK
Registered: 2010-07-05
Posts: 159
Website

Re: Ranger, a textbased filemanager

loop wrote:

Yes, to save excess keypress it would be great to do just ":delete<RETURN>y" to delete files with confirmation. Any other characterc except "y" to be treated as rejection.
Sorry for my being annoying.

You could do ":delete y<RETURN>" to automatically confirm. Personally, I tend to do ";de<TAB>y<RETURN>" (note that ";" can, by default, be pressed to open the console). This seems to amount to the same thing you want to do, loop – at least in ranger-1.5.5-1 – since the confirmation applies to the whole selection rather than each file one-by-one.


@archun: Intel® Core™ i5-4210M • [GPU] Intel® HD Graphics 4600 • [Kernel] linux-ck-haswell
Handmade.NetworkGitLab
The Life and Times of Miblo del Carpio

Offline

#1463 2012-09-21 20:07:06

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

Re: Ranger, a textbased filemanager

loop wrote:
Veedrac wrote:

Normally I would just go and make something, but I'm tired. This time, tell me *exactly* what you want it to do. Is it just :delete<RETURN>y instead of :delete<RETURN>y<RETURN>? I could do that, but sleep first [as if!].

Yes, to save excess keypress it would be great to do just ":delete<RETURN>y" to delete files with confirmation. Any other characterc except "y" to be treated as rejection.
Sorry for my being annoying.

If you were being annoying I wouldn't reply tongue. Keep posting, it's stuff for me to do!

Miblo's answer is new to me and will probably suffice. Thank you Miblo. However, for the sake of completion, look at this.

The source code of ranger's :delete looks like this:

class delete(Command):
	allow_abbrev = False

	def execute(self):
		lastword = self.arg(-1)

		if lastword.startswith('y'):
			return self.fm.delete()
		elif self.line.startswith(DELETE_WARNING):
			return

		cwd = self.fm.thisdir
		cf = self.fm.thisfile

		if cwd.marked_items or (cf.is_directory and not cf.is_link \
				and len(os.listdir(cf.path)) > 0):
			return self.fm.open_console(DELETE_WARNING)

		self.fm.delete()

Let us walk through the code.
First it checks if the last word in the arguments starts with "y". So ":delete sadas vsavsa ysdasd" would force a delete.
Then it checks if it starts with DELETE_WARNING. This will mean "delete seriously? ". If it does, it has asked and you hadn't said yes, so abort.
Then it checks if it needs to ask, since it hasn't. If it does, it asks. Otherwise it deletes.

So all a quick() method needs to do is the first part: "[check] if the last word in the arguments starts with 'y'". The comments write """
# The return value for quick() can be:
#   False: Nothing happens
#   True: Execute the command afterwards
"""
so all we need to do is return True if lastword.startswith('y').

	def quick(self):
		lastword = self.arg(-1)

		if lastword.startswith('y'):
			return True
		else:
			return False

which is the same as:

	def quick(self):
		return self.arg(-1).startswith('y')

There is one last change. If your command is not named :delete, DELETE_WARNING will redirect to the non-quick version. You then need to change DELETE_WARNING to whatever you want in the body of the code.

Full code:

class qdelete(Command):
	"""
	:qdelete

	Quick version of :delete

	Tries to delete the selection.

	"Selection" is defined as all the "marked files" (by default, you
	can mark files with space or v). If there are no marked files,
	use the "current file" (where the cursor is)

	When attempting to delete non-empty directories or multiple
	marked files, it will require a confirmation: The last word in
	the line has to start with a 'y'.  This may look like:
	:delete yes
	:delete seriously? yeah!
	"""

	allow_abbrev = False

	def execute(self):
		lastword = self.arg(-1)

		if lastword.startswith('y'):
			# user confirmed deletion!
			return self.fm.delete()
		elif self.line.startswith("qdelete [Are you serious?]"):
			# user did not confirm deletion
			return

		cwd = self.fm.thisdir
		cf = self.fm.thisfile

		if cwd.marked_items or (cf.is_directory and not cf.is_link \
				and len(os.listdir(cf.path)) > 0):
			# better ask for a confirmation, when attempting to
			# delete multiple files or a non-empty directory.
			return self.fm.open_console("qdelete [Are you serious?] ")

		# no need for a confirmation, just delete
		self.fm.delete()

	def quick(self):
		return self.arg(-1).startswith('y')

This, however, also means that :qd<tab>y will delete automatically. This is faster, but it may be too scary for the wee littluns. Hence, you may prefer to set the last line to:

return self.arg(-1).startswith('y') and self.line.startswith("qdelete [Are you serious?] ")

This checks if you are on a confirmation as well, so you always need exactly one enter press:

:qdelete y<enter>
:qdelete<enter>y

EDIT: I just realized you may have wanted something more like this:

	def quick(self):
		return self.line.startswith("qdelete [Are you serious?] ")

As :qdelete already checks for confirms in execute(), always executing on confirms will mean that "n" and other non-valids are taken immediately as no. This is probably a better solution. If you want to be able to confirm but not cancel if there isn't a confirmation version as well, use:

	def quick(self):
		return self.arg(-1).startswith('y') or self.line.startswith("qdelete [Are you serious?] ")

Version 1 [self.arg(-1).startswith('y')]:
:qdelete y
:qdelete<enter>y
:qdelete n<enter><enter>
:qdelete<enter>n<enter>

Version 2 [self.arg(-1).startswith('y') and self.line.startswith("qdelete [Are you serious?] ")]:
:qdelete y<enter>
:qdelete<enter>y
:qdelete n<enter><enter>
:qdelete<enter>n<enter>

Version 3 [self.line.startswith("qdelete [Are you serious?] ")]:
:qdelete y<enter>
:qdelete<enter>y
:qdelete n<enter><enter>
:qdelete<enter>n

Version 4 [self.arg(-1).startswith('y') or self.line.startswith("qdelete [Are you serious?] ")]:
:qdelete y
:qdelete<enter>y
:qdelete n<enter><enter>
:qdelete<enter>n

Last edited by Veedrac (2012-09-21 20:21:57)

Offline

#1464 2012-09-22 10:25:49

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

Re: Ranger, a textbased filemanager

@Miblo, thank you, the command completion with <Tab> was new for me.

@Veedrac, I have no words to express my appreciation. The level of your comment detalization rocks, many thanks for your time!
This code works great, it is something special:

Veedrac wrote:
def quick(self):
    return self.line.startswith("qdelete [Are you serious?] ")

------
By the way, are named tags still managed with such command:

ranger --list-tagged-files=A | xargs -d "\n" mv -t /foo

or something like following is already implemented?

:shell mv %tA /foo

By the way 2: is it normal that ranger uses python 2.7.3, while python 3.2.3 also installed?

Last edited by loop (2012-09-23 13:45:10)

Offline

#1465 2012-09-26 05:18:39

Shinryuu
Member
From: 俺のコスモス
Registered: 2010-02-27
Posts: 338

Re: Ranger, a textbased filemanager

Hey! I've been really addicted to this filemanager because it's so simple and nice to use. Also I have fiddled with themes etc. I have a one problem in my quest to finish this colorscheme off. In the title I want to change current/working directory color to something else, now it's white. In the statusbar I want to change everything but I was able to change permission colors. It's also possible something is missing from my template I'm using here.
tZm40aA

Full code:

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

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

		if context.reset:
			return default_colors

		elif context.in_browser:
			if context.selected:
				bg = black
			else:
				attr = normal
			if context.empty or context.error:
				bg = red
			if context.border:
				attr |= bold
				fg = black
			if context.media:
				if context.image:
					attr |= bold
					fg = green
				else:
					fg = black
			if context.container:
				attr |= bold
				fg = cyan
			if context.directory:
				attr |= bold
				fg = magenta
			elif context.executable and not \
					any((context.media, context.container,
						context.fifo, context.socket)):
				attr |= bold
				fg = red
			if context.socket:
				fg = magenta
			if context.fifo or context.device:
				fg = yellow
				if context.device:
					attr |= bold
			if context.link:
				fg = context.good and cyan or magenta
			if context.tag_marker and not context.selected:
				attr |= bold
				if fg in (green, magenta):
					fg = black
				else:
					fg = red
			if not context.selected and (context.cut or context.copied):
				fg = magenta
				attr |= bold
			if context.main_column:
				if context.selected:
					attr |= normal
				if context.marked:
					attr |= bold
					fg = yellow
			if context.badinfo:
				if attr & reverse:
					bg = magenta
				else:
					fg = green

		elif context.in_titlebar:
			attr |= bold
			if context.hostname:
				attr |= bold
				fg = context.bad and black or magenta
			elif context.directory:
				fg = black
			elif context.tab:
				if context.good:
					bg = green
			elif context.link:
				fg = cyan

		elif context.in_statusbar:
			if context.permissions:
				if context.good:
					fg = magenta
				elif context.bad:
					fg = cyan
			if context.marked:
				attr |= bold | reverse
				fg = yellow
			if context.message:
				if context.bad:
					attr |= bold
					fg = red

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

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

			if context.selected:
				attr |= reverse

		return fg, bg, attr

I think this is relevant part of the code:

elif context.in_titlebar:
			attr |= bold
			if context.hostname:
				attr |= bold
				fg = context.bad and black or magenta
			elif context.directory:
				fg = cyan
			elif context.tab:
				if context.good:
					bg = green
			elif context.link:
				fg = cyan

		elif context.in_statusbar:
			if context.permissions:
				if context.good:
					fg = magenta
				elif context.bad:
					fg = cyan
			if context.marked:
				attr |= bold | reverse
				fg = yellow
			if context.message:
				if context.bad:
					attr |= bold
					fg = red

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

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

			if context.selected:
				attr |= reverse

		return fg, bg, attr

Last edited by Shinryuu (2012-09-26 14:54:58)

Offline

#1466 2012-09-26 19:37:00

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

Re: Ranger, a textbased filemanager

Shinryuu wrote:

Hey! I've been really addicted to this filemanager because it's so simple and nice to use. Also I have fiddled with themes etc. I have a one problem in my quest to finish this colorscheme off. In the title I want to change current/working directory color to something else, now it's white. In the statusbar I want to change everything but I was able to change permission colors. It's also possible something is missing from my template I'm using here.

I think it's the variable "context.file" that is set when the color of the current file is being determined. You'd have to check for it just like you check for "context.directory" and everything else.


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

Offline

#1467 2012-09-27 00:24:49

Shinryuu
Member
From: 俺のコスモス
Registered: 2010-02-27
Posts: 338

Re: Ranger, a textbased filemanager

Thanks, that indeed did the trick smile

Offline

#1468 2012-09-27 01:27:37

tweed
Member
Registered: 2011-03-18
Posts: 21

Re: Ranger, a textbased filemanager

Ranger recently as packages it seems, on FreeBSD and OpenBSD.

RANGER rules my ARCH box and although I've yet to
try either of the BSD version it appears are now out there
it's easy to be entirely thrilled about the BSD's.

http://portsmon.freebsd.org/portovervie … =py-ranger

http://ftp5.usa.openbsd.org/pub/OpenBSD … ls/ranger/

Great if RANGER retains the ability to run on BSDs.
NOTE: interesting few points about the differences back at PAGES 42, 50 and 51.


ISSUE at some point?:
http://freebsd.1045724.n5.nabble.com/po … 26757.html

many thanks.
best wishes to all.

Last edited by tweed (2012-09-27 02:22:23)

Offline

#1469 2012-09-27 02:26:44

eyolf
Member
From: Copenhagen
Registered: 2005-11-29
Posts: 336
Website

Re: Ranger, a textbased filemanager

Veedrac wrote:

The source code of ranger's :delete looks like this:

Etc.

I'd like to suggest for the delete code to differentiate between deleting some currently active file/directory (i.e. where the cursor is, without any explicit selection with space/insert), or some explicitly selected file(s)/directorie(s).

Here's a real, actual scenario, taken from own painful experience:
I was browsing through my home folder, cleaning out stuff. Somehow I must have accidentally touched the space bar while scrolling. Unfortunately, the cursor was at the directory which is a symlink to my shared windows/linux document folder, holding all my stuff basically.
I scrolled on, found a file that needed to go, ordered delete and answered truthfully "Yes!" to the "Are you serious?" interrogation. I thought I was deleting a small tmp file, but then ranger went dead. After a while, I killed the process. After a little while longer, I realized that I had just inadvertently deleted 100Gb of my most cherished material.
Most of it was in backup, and the rest I managed to recover, but it was a nerve-wrecking couple of moments, and a long and tedious process.

Morale: it would be nice if ranger made a distinction in the "Are you serious?" message between deleting whatever is under the cursor and whatever is currently selected. I've made it a (good) habit always to think twice whenever I confirm a delete, however trivial. If I had been asked: "Seriously? You want do delete folder ~/everything?" I probably would have hit ESC immediately.
Ideally, I'd like to see a list of what it is that I'm actually deleting before I press "y", the way many other file managers do. But as a second best, have different messages when one is deleting selection and when one is deleting what's under the cursor.

Offline

#1470 2012-09-27 21:58:34

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

Re: Ranger, a textbased filemanager

eyolf wrote:
Veedrac wrote:

The source code of ranger's :delete looks like this:

Etc.

I'd like to suggest for the delete code to differentiate between deleting some currently active file/directory (i.e. where the cursor is, without any explicit selection with space/insert), or some explicitly selected file(s)/directorie(s).

Here's a real, actual scenario, taken from own painful experience:
I was browsing through my home folder, cleaning out stuff. Somehow I must have accidentally touched the space bar while scrolling. Unfortunately, the cursor was at the directory which is a symlink to my shared windows/linux document folder, holding all my stuff basically.
I scrolled on, found a file that needed to go, ordered delete and answered truthfully "Yes!" to the "Are you serious?" interrogation. I thought I was deleting a small tmp file, but then ranger went dead. After a while, I killed the process. After a little while longer, I realized that I had just inadvertently deleted 100Gb of my most cherished material.
Most of it was in backup, and the rest I managed to recover, but it was a nerve-wrecking couple of moments, and a long and tedious process.

Morale: it would be nice if ranger made a distinction in the "Are you serious?" message between deleting whatever is under the cursor and whatever is currently selected. I've made it a (good) habit always to think twice whenever I confirm a delete, however trivial. If I had been asked: "Seriously? You want do delete folder ~/everything?" I probably would have hit ESC immediately.
Ideally, I'd like to see a list of what it is that I'm actually deleting before I press "y", the way many other file managers do. But as a second best, have different messages when one is deleting selection and when one is deleting what's under the cursor.

It should be trivial to add context to the confirmation message, so I'll do that tomorrow. I agree with this post, and I think it should become default behavior.

Offline

#1471 2012-09-28 20:13:37

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

Re: Ranger, a textbased filemanager

Veedrac wrote:
eyolf wrote:
Veedrac wrote:

The source code of ranger's :delete looks like this:

Etc.

I'd like to suggest for the delete code to differentiate between deleting some currently active file/directory (i.e. where the cursor is, without any explicit selection with space/insert), or some explicitly selected file(s)/directorie(s).

Here's a real, actual scenario, taken from own painful experience:
I was browsing through my home folder, cleaning out stuff. Somehow I must have accidentally touched the space bar while scrolling. Unfortunately, the cursor was at the directory which is a symlink to my shared windows/linux document folder, holding all my stuff basically.
I scrolled on, found a file that needed to go, ordered delete and answered truthfully "Yes!" to the "Are you serious?" interrogation. I thought I was deleting a small tmp file, but then ranger went dead. After a while, I killed the process. After a little while longer, I realized that I had just inadvertently deleted 100Gb of my most cherished material.
Most of it was in backup, and the rest I managed to recover, but it was a nerve-wrecking couple of moments, and a long and tedious process.

Morale: it would be nice if ranger made a distinction in the "Are you serious?" message between deleting whatever is under the cursor and whatever is currently selected. I've made it a (good) habit always to think twice whenever I confirm a delete, however trivial. If I had been asked: "Seriously? You want do delete folder ~/everything?" I probably would have hit ESC immediately.
Ideally, I'd like to see a list of what it is that I'm actually deleting before I press "y", the way many other file managers do. But as a second best, have different messages when one is deleting selection and when one is deleting what's under the cursor.

It should be trivial to add context to the confirmation message, so I'll do that tomorrow. I agree with this post, and I think it should become default behavior.

As I said, here is an updated :qdelete. If you want a mere :delete, just remove the .quick() method and change the documentation.

class qdelete(Command):
	"""
	:qdelete

	Quick version of :delete

	Tries to delete the selection.

	"Selection" is defined as all the "marked files" (by default, you
	can mark files with space or v). If there are no marked files,
	use the "current file" (where the cursor is)

	When attempting to delete non-empty directories or multiple
	marked files, it will require a confirmation: The last word in
	the line has to start with a 'y'.  This may look like:
	:delete yes
	:delete seriously? yeah!
	"""

	allow_abbrev = False

	def execute(self):
		lastword = self.arg(-1)

		if lastword.startswith('y'):
			# user confirmed deletion!
			return self.fm.delete()
		elif self.line.startswith("qdelete [Do you really want to delete "):
			# user did not confirm deletion
			return

		cwd = self.fm.thisdir
		cf = self.fm.thisfile

		if cwd.marked_items or (cf.is_directory and not cf.is_link \
				and len(os.listdir(cf.path)) > 0):
			# better ask for a confirmation, when attempting to
			# delete multiple files or a non-empty directory.
			if cwd.marked_items:
				if len(cwd.marked_items) > 1:
					warning = "{} files or folders".format(len(cwd.marked_items))
				else:
					warning = cwd.marked_items[0].basename
			elif cf.is_directory:
				warning = cf.basename

			return self.fm.open_console("qdelete [Do you really want to delete {}?] ".format(warning))

		# no need for a confirmation, just delete
		self.fm.delete()

	def quick(self):
		return self.line.startswith("qdelete [Do you really want to delete ")

EDIT: Fixed a stupidly obvious bug

Last edited by Veedrac (2012-09-28 23:40:22)

Offline

#1472 2012-10-04 07:38:53

ryzion
Member
Registered: 2012-03-20
Posts: 89

Re: Ranger, a textbased filemanager

Is there a way to quickly remove all filters from a list?

Offline

#1473 2012-10-04 08:15:14

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

Re: Ranger, a textbased filemanager

ryzion wrote:

Is there a way to quickly remove all filters from a list?

Could you explain, what exactly do you want to do?

Offline

#1474 2012-10-05 10:38:35

Pranavg1890
Member
From: Nagpur,India
Registered: 2012-09-07
Posts: 111

Re: Ranger, a textbased filemanager

is there gpm support for ranger so that i can use my mouse to view it in tty?


Using Openbox + Tint2 + Idesk

Offline

#1475 2012-10-05 23:58:27

jk121960
Member
Registered: 2011-12-09
Posts: 254

Re: Ranger, a textbased filemanager

Hi, Some weeks back my office apps stopped opening from ranger, the splash would show and then nothing, if I use "r" and type "libreoffice" they open fine. Does someone have an idea of what changed? Other apps open fine.

I am using ranger-git and it is up to date.

thanks in advance for your help.

--jerry


Arch Awesome, Ranger & Vim the coding triple threat.

Offline

Board footer

Powered by FluxBB