From 6e8f001cd21558fcadc5e15cbb0b1155b0dab9c0 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Fri, 9 Oct 2015 11:02:34 +0200 Subject: Add plugin_pmount.py Implemented as a Python plugin instead of a bunch of rc.conf lines to allow easy nested looping. --- examples/plugin_pmount.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/plugin_pmount.py (limited to 'examples') diff --git a/examples/plugin_pmount.py b/examples/plugin_pmount.py new file mode 100644 index 00000000..61ee0dbd --- /dev/null +++ b/examples/plugin_pmount.py @@ -0,0 +1,30 @@ +# Tested with ranger 1.7.2 +# +# This plugin creates a bunch of keybindings used to mount and unmount +# the devices using pmount(1). +# +# alt+m : mount /dev/sd +# alt+m : mount /dev/sd +# alt+shift+m : unmount /dev/sd +# alt+shift+m : unmount /dev/sd +# alt+shift+n : list the devices + +import ranger.api + +MOUNT_KEY = 'm' +UMOUNT_KEY = 'M' +LIST_MOUNTS_KEY = 'N' + +old_hook_init = ranger.api.hook_init +def hook_init(fm): + try: + fm.execute_console("map {key} shell -p lsblk".format(key=LIST_MOUNTS_KEY)) + for disk in "abcdefgh": + fm.execute_console("map {key}{0} chain shell pmount sd{1}; cd /media/sd{1}".format(disk.upper(), disk, key=MOUNT_KEY)) + fm.execute_console("map {key}{0} chain cd; chain shell pumount sd{1}".format(disk.upper(), disk, key=UMOUNT_KEY)) + for part in "123456789": + fm.execute_console("map {key}{0}{1} chain shell pmount sd{0}{1}; cd /media/sd{0}{1}".format(disk, part, key=MOUNT_KEY)) + fm.execute_console("map {key}{0}{1} chain cd; shell pumount sd{0}{1}".format(disk, part, key=UMOUNT_KEY)) + finally: + return old_hook_init(fm) +ranger.api.hook_init = hook_init -- cgit 1.4.1-2-gfad0