From e2393938bf56f2bd6b93ea11e9282cf6d40a2514 Mon Sep 17 00:00:00 2001 From: Eiichi Sato Date: Sat, 21 Mar 2015 03:04:28 +0900 Subject: ranger.py: fixed issues with $tempfile in embedded shell Previously, $tempfile (namely, /tmp/chosendir) was not cleaned up correctly when the ranger process quit in `pwd` without moving to other directory. This causes permission errors in multi-user environments trying to overwrite $tempfile created by a different user. This commit solves the problem in two ways: - Correctly clean up temporary files - Avoid writing to the same temporary by using mktemp(1) --- ranger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ranger.py b/ranger.py index 4b2e7daa..1d7e42e1 100755 --- a/ranger.py +++ b/ranger.py @@ -9,7 +9,7 @@ # default is simply "ranger". (Not this file itself!) # The other arguments are passed to ranger. """": -tempfile='/tmp/chosendir' +tempfile="$(mktemp)" ranger="${1:-ranger}" test -z "$1" || shift "$ranger" --choosedir="$tempfile" "${@:-$(pwd)}" @@ -17,8 +17,8 @@ returnvalue=$? test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then cd "$(cat "$tempfile")" - rm -f -- "$tempfile" fi +rm -f -- "$tempfile" return $returnvalue """ and None -- cgit v1.2.3 From 41f9d8ccd5ace9d9863397afad84b43412605d42 Mon Sep 17 00:00:00 2001 From: Artyom Veremeenko Date: Sun, 29 Mar 2015 13:03:18 +0300 Subject: rifle.conf: openers for images placed after openers for documents. It fixes, for instance, problem with djvu files opened by image viewers. --- ranger/config/rifle.conf | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ranger/config/rifle.conf b/ranger/config/rifle.conf index f4b438c7..8e98f966 100644 --- a/ranger/config/rifle.conf +++ b/ranger/config/rifle.conf @@ -132,17 +132,6 @@ mime ^video, terminal, !X, has mpv = mpv -- "$@" mime ^video, terminal, !X, has mplayer2 = mplayer2 -- "$@" mime ^video, terminal, !X, has mplayer = mplayer -- "$@" -#------------------------------------------- -# Image Viewing: -#------------------------------------------- -mime ^image, has sxiv, X, flag f = sxiv -- "$@" -mime ^image, has feh, X, flag f = feh -- "$@" -mime ^image, has mirage, X, flag f = mirage -- "$@" -mime ^image, has eog, X, flag f = eog -- "$@" -mime ^image, has eom, X, flag f = eom -- "$@" -mime ^image, has gimp, X, flag f = gimp -- "$@" -ext xcf, X, flag f = gimp -- "$@" - #------------------------------------------- # Documents #------------------------------------------- @@ -168,6 +157,17 @@ ext pptx?|od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has ooffice, X, f ext djvu, has evince, X, flag f = evince -- "$@" ext djvu, has atril, X, flag f = atril -- "$@" +#------------------------------------------- +# Image Viewing: +#------------------------------------------- +mime ^image, has sxiv, X, flag f = sxiv -- "$@" +mime ^image, has feh, X, flag f = feh -- "$@" +mime ^image, has mirage, X, flag f = mirage -- "$@" +mime ^image, has eog, X, flag f = eog -- "$@" +mime ^image, has eom, X, flag f = eom -- "$@" +mime ^image, has gimp, X, flag f = gimp -- "$@" +ext xcf, X, flag f = gimp -- "$@" + #------------------------------------------- # Archives #------------------------------------------- -- cgit v1.2.3 From 1b5c7bd54ac76a3e62a28762402b4db2df5d9e2a Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Mon, 30 Mar 2015 18:54:57 +0200 Subject: new linemode with the information from file(1) --- doc/ranger.1 | 8 ++++++-- doc/ranger.pod | 1 + ranger/config/rc.conf | 1 + ranger/container/fsobject.py | 2 +- ranger/core/linemode.py | 15 +++++++++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index 3ba4fe4e..8a1e00c1 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.6.1" "03/03/2015" "ranger manual" +.TH RANGER 1 "ranger-1.6.1" "30/03/15" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -1006,13 +1006,17 @@ Looks for a string in all marked files or directories. .IX Item "linemode linemodename" Sets the linemode of all files in the current directory. The linemode may be: .Sp -.Vb 5 +.Vb 6 \& "filename": display each line as "..." +\& "fileinfo": display each line as "..." \& "permissions": display each line as " " \& "metatitle": display metadata from .metadata.json files if \& available, fall back to the "filename" linemode if no \& metadata was found. See :meta command. .Ve +.Sp +The custom linemodes may be added by subclassing the \fILinemodeBase\fR class. +See the \fIranger.core.linemode\fR module for some examples. .IP "load_copy_buffer" 2 .IX Item "load_copy_buffer" Load the copy buffer from \fI~/.config/ranger/copy_buffer\fR. This can be used to diff --git a/doc/ranger.pod b/doc/ranger.pod index 336a886c..a6204403 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -1046,6 +1046,7 @@ Looks for a string in all marked files or directories. Sets the linemode of all files in the current directory. The linemode may be: "filename": display each line as "..." + "fileinfo": display each line as "..." "permissions": display each line as " " "metatitle": display metadata from .metadata.json files if available, fall back to the "filename" linemode if no diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index ca67c389..62dd030f 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -251,6 +251,7 @@ map cd console cd # Change the line mode map Mf linemode filename +map Mi linemode fileinfo map Mp linemode permissions map Mt linemode metatitle diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index 131e2304..1bf08e20 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -86,7 +86,7 @@ class FileSystemObject(FileManagerAware, SettingsAware): _linemode = DEFAULT_LINEMODE linemode_dict = dict( (linemode.name, linemode()) for linemode in - [DefaultLinemode, TitleLinemode, PermissionsLinemode] + [DefaultLinemode, TitleLinemode, PermissionsLinemode, FileInfoLinemode] ) def __init__(self, path, preload=None, path_is_abs=False, basename_is_rel_to=None): diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index 7993af82..529c6b93 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -84,3 +84,18 @@ class PermissionsLinemode(LinemodeBase): def infostring(self, file, metadata): return "" + + +class FileInfoLinemode(LinemodeBase): + name = "fileinfo" + + def filetitle(self, file, metadata): + return file.relative_path + + def infostring(self, file, metadata): + if not file.is_directory: + from subprocess import check_output + fileinfo = check_output(["file", "-bL", file.path]).strip() + return fileinfo + else: + raise NotImplementedError -- cgit v1.2.3 From 453a282ed0d599174cc8f45ed13c54b1be1ea4f6 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Mon, 30 Mar 2015 19:12:19 +0200 Subject: :flat statusbar indicator added --- ranger/gui/context.py | 2 +- ranger/gui/widgets/statusbar.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ranger/gui/context.py b/ranger/gui/context.py index 2ad27434..e5aef06c 100644 --- a/ranger/gui/context.py +++ b/ranger/gui/context.py @@ -11,7 +11,7 @@ CONTEXT_KEYS = ['reset', 'error', 'badinfo', 'good', 'bad', 'space', 'permissions', 'owner', 'group', 'mtime', 'nlink', 'scroll', 'all', 'bot', 'top', 'percentage', 'filter', - 'marked', 'tagged', 'tag_marker', 'cut', 'copied', + 'flat', 'marked', 'tagged', 'tag_marker', 'cut', 'copied', 'help_markup', # COMPAT 'seperator', 'key', 'special', 'border', # COMPAT 'title', 'text', 'highlight', 'bars', 'quotes', 'tab', 'loaded', diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 9ff331a0..f5824d99 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -242,8 +242,15 @@ class StatusBar(Widget): max_pos = len(target) - self.column.hei base = 'scroll' + right.add(" ", "space") + + if self.fm.thisdir.flat: + right.add("flat=", base, 'flat') + right.add(str(self.fm.thisdir.flat), base, 'flat') + right.add(", ", "space") + if self.fm.thisdir.filter: - right.add(" f=`", base, 'filter') + right.add("f=`", base, 'filter') right.add(self.fm.thisdir.filter.pattern, base, 'filter') right.add("', ", "space") -- cgit v1.2.3 From 3c2862ea9b84d4f2e4ecd416c0db66db2dad58ba Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 9 Apr 2015 16:37:50 +0200 Subject: examples/bash_automatic_cd.sh: use mktemp This is a follow-up to #282 --- doc/examples/bash_automatic_cd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/examples/bash_automatic_cd.sh b/doc/examples/bash_automatic_cd.sh index 8d72c553..465c9c80 100644 --- a/doc/examples/bash_automatic_cd.sh +++ b/doc/examples/bash_automatic_cd.sh @@ -8,7 +8,7 @@ # original directory. function ranger-cd { - tempfile='/tmp/chosendir' + tempfile="$(mktemp)" /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}" test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then -- cgit v1.2.3 From fabab01bda21868be0d47e053c65b48a9102b820 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 10 Apr 2015 00:02:12 +0200 Subject: added "%space" macro that expands to " ", use it in rc.conf --- ranger/config/rc.conf | 22 +++++++++++----------- ranger/core/actions.py | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index 62dd030f..fd883cb8 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -241,13 +241,13 @@ map S shell $SHELL map : console map ; console -map ! console shell +map ! console shell%space map @ console -p6 shell %%s -map # console shell -p -map s console shell -map r chain draw_possible_programs; console open_with -map f console find -map cd console cd +map # console shell -p%space +map s console shell%space +map r chain draw_possible_programs; console open_with%space +map f console find%space +map cd console cd%space # Change the line mode map Mf linemode filename @@ -271,7 +271,7 @@ map display_file map edit map copy map cut -map console mkdir +map console mkdir%space map console delete map exit @@ -286,7 +286,7 @@ map move down=1 pages=True map move up=1 pages=True map move right=1 #map console delete -map console touch +map console touch%space # VIM-like copymap k @@ -337,7 +337,7 @@ map yn shell -f echo -n %f | xsel -i; xsel -o | xsel -i -b # Filesystem Operations map = chmod -map cw console rename +map cw console rename%space map a rename_append map A eval fm.open_console('rename ' + fm.thisfile.basename) map I eval fm.open_console('rename ' + fm.thisfile.basename, position=7) @@ -372,7 +372,7 @@ map yj eval fm.copy(dirarg=dict(down=1), narg=quantifier) map yk eval fm.copy(dirarg=dict(up=1), narg=quantifier) # Searching -map / console search +map / console search%space map n search_next map N search_next forward=False map ct search_next order=tag @@ -439,7 +439,7 @@ map zP toggle_option preview_directories map zs toggle_option sort_case_insensitive map zu toggle_option autoupdate_cumulative_size map zv toggle_option use_preview_script -map zf console filter +map zf console filter%space # Bookmarks map ` enter_bookmark %any diff --git a/ranger/core/actions.py b/ranger/core/actions.py index c7bdcfec..ef74d7a2 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -210,6 +210,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): macros = {} macros['rangerdir'] = ranger.RANGERDIR + macros['space'] = ' ' if self.fm.thisfile: macros['f'] = self.fm.thisfile.relative_path -- cgit v1.2.3 From 3160c4a7ebedf85c068baa4bae6747cafc123d4b Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 10 Apr 2015 00:12:46 +0200 Subject: ranger.1: added documentation for %rangerdir and %space macros --- doc/ranger.1 | 10 +++++++++- doc/ranger.pod | 8 ++++++++ doc/rifle.1 | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index 8a1e00c1..295314f4 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.6.1" "30/03/15" "ranger manual" +.TH RANGER 1 "ranger-1.6.1" "04/10/2015" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -321,6 +321,14 @@ Macros for file paths are generally shell-escaped so they can be used in the Additionally, if you create a key binding that uses , a special statement which accepts any key, then the macro \f(CW%any\fR (or \f(CW%any0\fR, \f(CW%any1\fR, \f(CW%any2\fR, ...) can be used in the command to get the key that was pressed. +.PP +The macro \f(CW%rangerdir\fR expands to the directory of ranger's python library, you +can use it for something like this command: + alias show_commands shell less \f(CW%rangerdir\fR/config/commands.py +.PP +The macro \f(CW%space\fR expands to a space character. You can use it to add spaces to +the end of a command when needed, while preventing editors to strip spaces off +the end of the line automatically. .SS "\s-1BOOKMARKS\s0" .IX Subsection "BOOKMARKS" Type \fBm\fR to bookmark the current directory. You can re-enter this diff --git a/doc/ranger.pod b/doc/ranger.pod index a6204403..ad75f35a 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -218,6 +218,14 @@ Additionally, if you create a key binding that uses , a special statement which accepts any key, then the macro %any (or %any0, %any1, %any2, ...) can be used in the command to get the key that was pressed. +The macro %rangerdir expands to the directory of ranger's python library, you +can use it for something like this command: + alias show_commands shell less %rangerdir/config/commands.py + +The macro %space expands to a space character. You can use it to add spaces to +the end of a command when needed, while preventing editors to strip spaces off +the end of the line automatically. + =head2 BOOKMARKS Type B> to bookmark the current directory. You can re-enter this diff --git a/doc/rifle.1 b/doc/rifle.1 index 999d56d6..21c53276 100644 --- a/doc/rifle.1 +++ b/doc/rifle.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RIFLE 1" -.TH RIFLE 1 "rifle-1.6.1" "08/26/2014" "rifle manual" +.TH RIFLE 1 "rifle-1.6.1" "04/10/2015" "rifle manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l -- cgit v1.2.3 From c56bf8705f75301d4dabf49991e4c509b71d5901 Mon Sep 17 00:00:00 2001 From: randnobx Date: Fri, 20 Mar 2015 21:02:30 -0400 Subject: added tag management for rename, delete, bulkrename, and moving of files fixed typo in rename added recursive checking to move, rename, and delete; refactored previos code bugfix: moved recursive tag checking for delete to commands.py --- ranger/config/commands.py | 26 ++++++++++++++++++++++++++ ranger/core/loader.py | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 8797cb6b..38b4f598 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -523,10 +523,16 @@ class delete(Command): self._question_callback, ('n', 'N', 'y', 'Y')) else: # no need for a confirmation, just delete + for f in self.fm.tags.tags: + if str(f).startswith(self.fm.thisfile.path): + self.fm.tags.remove(f) self.fm.delete() def _question_callback(self, answer): if answer == 'y' or answer == 'Y': + for f in self.fm.tags.tags: + if str(f).startswith(self.fm.thisfile.path): + self.fm.tags.remove(f) self.fm.delete() @@ -725,6 +731,13 @@ class rename(Command): new_name = self.rest(1) + tagged = {} + old_name = self.fm.thisfile.basename + for f in self.fm.tags.tags: + if str(f).startswith(self.fm.thisfile.path): + tagged[f] = self.fm.tags.tags[f] + self.fm.tags.remove(f) + if not new_name: return self.fm.notify('Syntax: rename ', bad=True) @@ -738,6 +751,9 @@ class rename(Command): f = File(new_name) self.fm.thisdir.pointed_obj = f self.fm.thisfile = f + for t in tagged: + self.fm.tags.tags[t.replace(old_name,new_name)] = tagged[t] + self.fm.tags.dump() def tab(self): return self._tab_directory_content() @@ -813,6 +829,11 @@ class bulkrename(Command): # Create and edit the file list filenames = [f.relative_path for f in self.fm.thistab.get_selection()] + tagged = {} + for f in self.fm.thistab.get_selection(): + if f.path in self.fm.tags: + tagged[f.relative_path] = self.fm.tags.tags[f.path] + self.fm.tags.remove(f.path) listfile = tempfile.NamedTemporaryFile(delete=False) listpath = listfile.name @@ -846,6 +867,11 @@ class bulkrename(Command): self.fm.run(['/bin/sh', cmdfile.name], flags='w') cmdfile.close() + for old,new in zip(filenames, new_filenames): + if old != new and old in tagged: + newpath = self.fm.thisdir.path + '/' + new + self.fm.tags.tags[newpath] = tagged[old] + self.fm.tags.dump() class relink(Command): """:relink diff --git a/ranger/core/loader.py b/ranger/core/loader.py index 86a591f0..8eda544f 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -85,6 +85,13 @@ class CopyLoader(Loadable, FileManagerAware): else: self.description = "moving files from: " + self.one_file.dirname for f in self.copy_buffer: + for tf in self.fm.tags.tags: + if tf == f.path or str(tf).startswith(f.path): + tag = self.fm.tags.tags[tf] + self.fm.tags.remove(tf) + self.fm.tags.tags[tf.replace(f.path, self.original_path \ + + '/' + f.basename)] = tag + self.fm.tags.dump() for _ in shutil_g.move(src=f.path, dst=self.original_path, overwrite=self.overwrite): -- cgit v1.2.3 From dc86cf762d2fcea44c538990f36726f060b56ea1 Mon Sep 17 00:00:00 2001 From: randnobx Date: Sat, 11 Apr 2015 15:56:01 -0400 Subject: commands.py: skip retagging in bulkrename if rename shellscript is changed commands.py: moved first tag section after initial check for name change to fix bugs --- ranger/config/commands.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 38b4f598..554b7af4 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -82,6 +82,7 @@ # =================================================================== from ranger.api.commands import * +from hashlib import sha1 class alias(Command): """:alias @@ -829,11 +830,6 @@ class bulkrename(Command): # Create and edit the file list filenames = [f.relative_path for f in self.fm.thistab.get_selection()] - tagged = {} - for f in self.fm.thistab.get_selection(): - if f.path in self.fm.tags: - tagged[f.relative_path] = self.fm.tags.tags[f.path] - self.fm.tags.remove(f.path) listfile = tempfile.NamedTemporaryFile(delete=False) listpath = listfile.name @@ -852,6 +848,11 @@ class bulkrename(Command): return # Generate and execute script + tagged = {} + for f in self.fm.thistab.get_selection(): + if f.path in self.fm.tags: + tagged[f.relative_path] = self.fm.tags.tags[f.path] + self.fm.tags.remove(f.path) cmdfile = tempfile.NamedTemporaryFile() cmdfile.write(b"# This file will be executed when you close the editor.\n") cmdfile.write(b"# Please double-check everything, clear the file to abort.\n") @@ -863,15 +864,24 @@ class bulkrename(Command): cmdfile.write("\n".join("mv -vi -- " + esc(old) + " " + esc(new) \ for old, new in zip(filenames, new_filenames) if old != new)) cmdfile.flush() + hash1= sha1(cmdfile.read()).hexdigest() self.fm.execute_file([File(cmdfile.name)], app='editor') + chg = False + if hash1 == sha1(cmdfile.read()).hexdigest(): + chg = True self.fm.run(['/bin/sh', cmdfile.name], flags='w') cmdfile.close() - for old,new in zip(filenames, new_filenames): - if old != new and old in tagged: - newpath = self.fm.thisdir.path + '/' + new - self.fm.tags.tags[newpath] = tagged[old] - self.fm.tags.dump() + if chg: + for old,new in zip(filenames, new_filenames): + if old != new and old in tagged: + newpath = self.fm.thisdir.path + '/' + new + #oldpath = self.fm.thisdir.path + '/' + old + #self.fm.tags.remove(oldpath) + self.fm.tags.tags[newpath] = tagged[old] + self.fm.tags.dump() + else: + fm.notify("files have not been retagged") class relink(Command): """:relink -- cgit v1.2.3 From af17ede9ff216d09495672e00a36ba60fbf8bee3 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 12 Apr 2015 15:02:25 +0200 Subject: config/commands: fix + cleanup randy's patch, add comments --- ranger/config/commands.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 554b7af4..6b36350b 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -82,7 +82,6 @@ # =================================================================== from ranger.api.commands import * -from hashlib import sha1 class alias(Command): """:alias @@ -847,12 +846,7 @@ class bulkrename(Command): self.fm.notify("No renaming to be done!") return - # Generate and execute script - tagged = {} - for f in self.fm.thistab.get_selection(): - if f.path in self.fm.tags: - tagged[f.relative_path] = self.fm.tags.tags[f.path] - self.fm.tags.remove(f.path) + # Generate script cmdfile = tempfile.NamedTemporaryFile() cmdfile.write(b"# This file will be executed when you close the editor.\n") cmdfile.write(b"# Please double-check everything, clear the file to abort.\n") @@ -864,22 +858,32 @@ class bulkrename(Command): cmdfile.write("\n".join("mv -vi -- " + esc(old) + " " + esc(new) \ for old, new in zip(filenames, new_filenames) if old != new)) cmdfile.flush() - hash1= sha1(cmdfile.read()).hexdigest() + + # Open the script and let the user review it, then check if the script + # was modified by the user + hash1 = cmdfile.read() self.fm.execute_file([File(cmdfile.name)], app='editor') - chg = False - if hash1 == sha1(cmdfile.read()).hexdigest(): - chg = True + script_was_edited = (hash1 != cmdfile.read()) + + # Do the renaming self.fm.run(['/bin/sh', cmdfile.name], flags='w') cmdfile.close() - if chg: - for old,new in zip(filenames, new_filenames): - if old != new and old in tagged: + # Retag the files, but only if the script wasn't changed during review, + # because only then we know which are the source and destination files. + if not script_was_edited: + tags_changed = False + for old, new in zip(filenames, new_filenames): + if old != new: + oldpath = self.fm.thisdir.path + '/' + old newpath = self.fm.thisdir.path + '/' + new - #oldpath = self.fm.thisdir.path + '/' + old - #self.fm.tags.remove(oldpath) - self.fm.tags.tags[newpath] = tagged[old] - self.fm.tags.dump() + if oldpath in self.fm.tags: + old_tag = self.fm.tags.tags[oldpath] + self.fm.tags.remove(oldpath) + self.fm.tags.tags[newpath] = old_tag + tags_changed = True + if tags_changed: + self.fm.tags.dump() else: fm.notify("files have not been retagged") -- cgit v1.2.3 From 80d517985a0525ffc4b3a1343f67c7d7e63d6c76 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 12 Apr 2015 15:11:34 +0200 Subject: config/commands.py: deduplication --- ranger/config/commands.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 6b36350b..93254350 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -850,13 +850,12 @@ class bulkrename(Command): cmdfile = tempfile.NamedTemporaryFile() cmdfile.write(b"# This file will be executed when you close the editor.\n") cmdfile.write(b"# Please double-check everything, clear the file to abort.\n") + content = "\n".join("mv -vi -- " + esc(old) + " " + esc(new) \ + for old, new in zip(filenames, new_filenames) if old != new) if py3: - cmdfile.write("\n".join("mv -vi -- " + esc(old) + " " + esc(new) \ - for old, new in zip(filenames, new_filenames) \ - if old != new).encode("utf-8")) + cmdfile.write(content.encode("utf-8")) else: - cmdfile.write("\n".join("mv -vi -- " + esc(old) + " " + esc(new) \ - for old, new in zip(filenames, new_filenames) if old != new)) + cmdfile.write(content) cmdfile.flush() # Open the script and let the user review it, then check if the script -- cgit v1.2.3 From 3259b3112e0b5aa1c2b3ff8d751648a18c5ec721 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 12 Apr 2015 15:28:05 +0200 Subject: config/commands: fixed script change detection in :bulkrename See also: #283 --- ranger/config/commands.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 93254350..6399152f 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -848,21 +848,23 @@ class bulkrename(Command): # Generate script cmdfile = tempfile.NamedTemporaryFile() - cmdfile.write(b"# This file will be executed when you close the editor.\n") - cmdfile.write(b"# Please double-check everything, clear the file to abort.\n") - content = "\n".join("mv -vi -- " + esc(old) + " " + esc(new) \ + script_lines = [] + script_lines.append(b"# This file will be executed when you close the editor.\n") + script_lines.append(b"# Please double-check everything, clear the file to abort.\n") + script_lines.extend("mv -vi -- %s %s\n" % (esc(old), esc(new)) \ for old, new in zip(filenames, new_filenames) if old != new) + script_content = "".join(script_lines) if py3: - cmdfile.write(content.encode("utf-8")) + cmdfile.write(script_content.encode("utf-8")) else: - cmdfile.write(content) + cmdfile.write(script_content) cmdfile.flush() # Open the script and let the user review it, then check if the script # was modified by the user - hash1 = cmdfile.read() self.fm.execute_file([File(cmdfile.name)], app='editor') - script_was_edited = (hash1 != cmdfile.read()) + cmdfile.seek(0) + script_was_edited = (script_content != cmdfile.read()) # Do the renaming self.fm.run(['/bin/sh', cmdfile.name], flags='w') -- cgit v1.2.3 From 70f95d4f27869f1fe1dc3d922d408d053d836241 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 13 Apr 2015 12:32:05 +0200 Subject: core.actions: update execute_file() docstring --- ranger/core/actions.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ranger/core/actions.py b/ranger/core/actions.py index ef74d7a2..92b8a097 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -307,13 +307,17 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): (line, str(e)), bad=True) def execute_file(self, files, **kw): - """Execute a file. + """Uses the "rifle" module to open/execute a file - app is the name of a method in Applications, without the "app_" - flags is a string consisting of runner.ALLOWED_FLAGS - mode is a positive integer. - Both flags and mode specify how the program is run.""" - # TODO: docstring out of date + Arguments are the same as for ranger.ext.rifle.Rifle.execute: + + files: a list of file objects (not strings!) + number: a number to select which way to open the file, in case there + are multiple choices + label: a string to select an opening method by its label + flags: a string specifying additional options, see `man rifle` + mimetyle: pass the mimetype to rifle, overriding its own guess + """ mode = kw['mode'] if 'mode' in kw else 0 -- cgit v1.2.3 From 28e23ddcde292efd2968e44d2781e387cba5618f Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 13 Apr 2015 12:41:52 +0200 Subject: doc/ranger.1: added entries for :help and :setintag --- doc/ranger.1 | 12 +++++++++++- doc/ranger.pod | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index 295314f4..e5400efb 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.6.1" "04/10/2015" "ranger manual" +.TH RANGER 1 "ranger-1.6.1" "04/13/2015" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -853,6 +853,7 @@ ranger. For your convenience, this is a list of the \*(L"public\*(R" commands i \& find pattern \& flat level \& grep pattern +\& help \& linemode linemodename \& load_copy_buffer \& map key command @@ -874,6 +875,7 @@ ranger. For your convenience, this is a list of the \*(L"public\*(R" commands i \& search pattern \& search_inc pattern \& set option value +\& setintag tags option value \& setlocal [path=] option value \& shell [\-FLAGS] command \& terminal @@ -1010,6 +1012,9 @@ values \-2 and less are invalid. .IP "grep \fIpattern\fR" 2 .IX Item "grep pattern" Looks for a string in all marked files or directories. +.IP "help" 2 +.IX Item "help" +Provides a quick way to view ranger documentations. .IP "linemode \fIlinemodename\fR" 2 .IX Item "linemode linemodename" Sets the linemode of all files in the current directory. The linemode may be: @@ -1157,6 +1162,11 @@ doesn't work for functions and regular expressions. Valid values are: \& list | 1,2,3,4 \& none | none .Ve +.IP "setintag \fItags\fR \fIoption\fR \fIvalue\fR" 2 +.IX Item "setintag tags option value" +Assigns a new value to an option, but locally for the directories that are +marked with \fItag\fR. This means, that this option only takes effect when +visiting that directory. .IP "setlocal [path=\fIpath\fR] \fIoption\fR \fIvalue\fR" 2 .IX Item "setlocal [path=path] option value" Assigns a new value to an option, but locally for the directory given by diff --git a/doc/ranger.pod b/doc/ranger.pod index ad75f35a..0ac79e12 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -869,6 +869,7 @@ ranger. For your convenience, this is a list of the "public" commands including find pattern flat level grep pattern + help linemode linemodename load_copy_buffer map key command @@ -890,6 +891,7 @@ ranger. For your convenience, this is a list of the "public" commands including search pattern search_inc pattern set option value + setintag tags option value setlocal [path=] option value shell [-FLAGS] command terminal @@ -1049,6 +1051,10 @@ values -2 and less are invalid. Looks for a string in all marked files or directories. +=item help + +Provides a quick way to view ranger documentations. + =item linemode I Sets the linemode of all files in the current directory. The linemode may be: @@ -1209,6 +1215,12 @@ doesn't work for functions and regular expressions. Valid values are: list | 1,2,3,4 none | none +=item setintag I I