summary refs log blame commit diff stats
path: root/examples/plugin_pmount.py
blob: ba61b0e54664b688a95b081672da1fd6ad30ffa8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                         

 











                                                                                                                                       
# 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
pan class="o">!= NULL) contact->status = strdup(status); else contact->status = NULL; return contact; } PContact p_contact_copy(PContact contact) { PContact copy = malloc(sizeof(struct p_contact_t)); copy->name = strdup(contact->name); copy->show = strdup(contact->show); if (contact->status != NULL) copy->status = strdup(contact->status); else copy->status = NULL; return copy; } void p_contact_free(PContact contact) { free(contact->name); if (contact->show != NULL) { free(contact->show); contact->show = NULL; } if (contact->status != NULL) { free(contact->status); contact->status = NULL; } free(contact); contact = NULL; } const char * p_contact_name(const PContact contact) { return contact->name; } const char * p_contact_show(const PContact contact) { return contact->show; } const char * p_contact_status(const PContact contact) { return contact->status; } int p_contacts_equal_deep(const PContact c1, const PContact c2) { int name_eq = (g_strcmp0(c1->name, c2->name) == 0); int show_eq = (g_strcmp0(c1->show, c2->show) == 0); int status_eq = (g_strcmp0(c1->status, c2->status) == 0); return (name_eq && show_eq && status_eq); }