Skip to content

Instantly share code, notes, and snippets.

@nimatrueway
Last active March 4, 2020 12:49
Show Gist options
  • Save nimatrueway/b4f2425d3e1344bdd402d16ae56e4785 to your computer and use it in GitHub Desktop.
Save nimatrueway/b4f2425d3e1344bdd402d16ae56e4785 to your computer and use it in GitHub Desktop.
Integration Nemo file manager with massren for bulk renaming (https://github.com/laurent22/massren)
#!/usr/bin/env python3
from re import sub as rereplace, compile as recompile
from sys import argv
from urllib.parse import unquote
from subprocess import run
# prerequisites:
# make sure the editor you assigned to massren is assessible with default PATH (uninitialized .zshrc)
# constants
massren_exec = "{path-to-massren}/massren"
terminal_exec = "/usr/bin/x-terminal-emulator -e"
file_prefix = recompile("^file://")
args = [rereplace(file_prefix, "", unquote(arg)) for arg in argv[1:]]
massren_cmd = "{MASSREN} \"{FILES}\"".format(MASSREN=massren_exec, FILES="\" \"".join(args))
cmd = "{TERMINAL} {CMD}".format(TERMINAL=terminal_exec, CMD=massren_cmd)
run(cmd, shell=True)
[Nemo Action]
Active=true
Name=Mass Rename
Comment=Running massren in this folder.
Exec=konsole --workdir "%F" -e {path-to-massren}/massren
Dependencies={path-to-massren}/massren
Selection=s
Extensions=dir;
Terminal=false
[Nemo Action]
Active=true
Name=Mass Rename
Comment=Running massren in this folder.
Exec=konsole --workdir "%F" -e {path-to-massren}/massren
Dependencies={path-to-massren}/massren
Selection=none
Extensions=any;
Terminal=false
@nimatrueway
Copy link
Author

nimatrueway commented Jan 20, 2019

To add a "Bulk Rename" action to your folders / blank area:

  1. Don't forget to replace {path-to-massren} with the actual path of massren executable. (it should be at $GOPATH/bin/)
  2. Copy *.nemo_action files to $HOME/.local/share/nemo/actions

@nimatrueway
Copy link
Author

nimatrueway commented Jan 22, 2019

To integrate "Rename..." / "F2" of nemo with massren when multiple files are selected:

  1. Copy massren-nemo.py to a desired folder (e.g. ~/scripts/) and make it executable (chmod +x massren-nemo.py)
  2. In the python script replace {path-to-massren} with the actual path of massren executable. (it should be at $GOPATH/bin/)
  3. Open up nemo, in menus select Edit -> Preferences; in the opened window select Behavior tab. The last option is Bulk Rename and set the command to the absolute path of the python script (e.g. {your-home}/scripts/massren-nemo.py).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment