about summary refs log blame commit diff stats
path: root/examples/plugin_new_sorting_method.py
blob: d294067e6baa6c5988b94697d6131021dbc650d5 (plain) (tree)
972d
# Compatible with ranger 1.6.0 through 1.7.*
#
# This plugin adds the sorting algorithm called 'random'.  To enable it, type
# ":set sort=random" or create a key binding with ":map oz set sort=random"

from __future__ import (absolute_import, division, print_function)

from random import random

from ranger.container.directory import Directory

Directory.sort_dict['random'] = lambda path: random()
pan>//' | tail -n 1".format(disk) try: numparts = int(subprocess.check_output( partcmd, shell=True).decode('utf-8').replace('\r', '').replace('\n', '')) except ValueError: numparts = 0 if numparts == 0: # no partition, mount the whole device fm.execute_console("map {key}{0} chain shell pmount sd{0}; cd /media/sd{0}".format( disk, key=MOUNT_KEY)) fm.execute_console("map {key}{0} chain cd; chain shell pumount sd{0}".format( disk, key=UMOUNT_KEY)) elif numparts == 1: # only one partition, mount the partition fm.execute_console( "map {key}{0} chain shell pmount sd{0}1; cd /media/sd{0}1".format( disk, key=MOUNT_KEY)) fm.execute_console("map {key}{0} chain cd; shell pumount sd{0}1".format( disk, key=UMOUNT_KEY)) else: # use range start 1, /dev/sd{device}0 doesn't exist for part in range(1, numparts + 1): 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)) return HOOK_INIT_OLD(fm) ranger.api.hook_init = hook_init