summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorrandnobx <randynobx@gmail.com>2015-04-11 15:56:01 -0400
committerrandnobx <randynobx@gmail.com>2015-04-11 16:18:18 -0400
commitdc86cf762d2fcea44c538990f36726f060b56ea1 (patch)
treef6318225c1bc0d2be8ecddd7114dcf39ce611bfe
parentc56bf8705f75301d4dabf49991e4c509b71d5901 (diff)
downloadranger-dc86cf762d2fcea44c538990f36726f060b56ea1.tar.gz
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
-rw-r--r--ranger/config/commands.py30
1 files 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 <newcommand> <oldcommand>
@@ -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 <newpath>