diff options
author | hut <hut@lepus.uberspace.de> | 2015-04-12 15:28:05 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2015-04-12 15:28:37 +0200 |
commit | 3259b3112e0b5aa1c2b3ff8d751648a18c5ec721 (patch) | |
tree | 689db2f20ad7a549ba1e7fe838fc9e7a0f918244 | |
parent | 80d517985a0525ffc4b3a1343f67c7d7e63d6c76 (diff) | |
download | ranger-3259b3112e0b5aa1c2b3ff8d751648a18c5ec721.tar.gz |
config/commands: fixed script change detection in :bulkrename
See also: #283
-rw-r--r-- | ranger/config/commands.py | 16 |
1 files 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') |