diff options
author | Wojciech Siewierski <wojciech.siewierski@onet.pl> | 2015-10-09 11:02:34 +0200 |
---|---|---|
committer | Wojciech Siewierski <wojciech.siewierski@onet.pl> | 2015-10-09 11:02:34 +0200 |
commit | 6e8f001cd21558fcadc5e15cbb0b1155b0dab9c0 (patch) | |
tree | c32f071113c052d8c5cd0ce8f2a0309d8574faae | |
parent | f8341333ad3ab127dd9bf215769d77ab828efb0e (diff) | |
download | ranger-6e8f001cd21558fcadc5e15cbb0b1155b0dab9c0.tar.gz |
Add plugin_pmount.py
Implemented as a Python plugin instead of a bunch of rc.conf lines to allow easy nested looping.
-rw-r--r-- | examples/plugin_pmount.py | 30 |
1 files changed, 30 insertions, 0 deletions
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 <letter> <digit>: mount /dev/sd<letter><digit> +# alt+m <uppercase letter> : mount /dev/sd<letter> +# alt+shift+m <letter> <digit>: unmount /dev/sd<letter><digit> +# alt+shift+m <uppercase letter> : unmount /dev/sd<letter> +# alt+shift+n : list the devices + +import ranger.api + +MOUNT_KEY = '<alt>m' +UMOUNT_KEY = '<alt>M' +LIST_MOUNTS_KEY = '<alt>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 |