forked from mirrors/ranger_udisk_menu
open selected mountpoint in the current tab
This commit is contained in:
parent
0dde4583b7
commit
a7548bee17
@ -34,3 +34,4 @@ Enter in ranger `:mount`, than will be shown menu. In this menu you can press:
|
|||||||
- `m` to mount selected partition
|
- `m` to mount selected partition
|
||||||
- `u` to unmount selected partition
|
- `u` to unmount selected partition
|
||||||
- `e` to unmount all partitions of selected partition's drive
|
- `e` to unmount all partitions of selected partition's drive
|
||||||
|
- `ENTER` to open selected mountpoint in current tab
|
||||||
|
24
menu.py
24
menu.py
@ -9,17 +9,19 @@ import curses
|
|||||||
import curses.ascii
|
import curses.ascii
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class ChoosePartition:
|
class ChoosePartition:
|
||||||
blkinfo = None
|
blkinfo = None
|
||||||
screen = None
|
screen = None
|
||||||
selected_partn = 1
|
selected_partn = 1
|
||||||
|
selected_mountpoint = None
|
||||||
partn = 1
|
partn = 1
|
||||||
help_message = [("Press 'm' to mount, " +
|
help_message = [("Press 'm' to mount, " +
|
||||||
"'u' to unmount, " +
|
"'u' to unmount, " +
|
||||||
"'g' to refresh"),
|
"'g' to refresh"),
|
||||||
" and 'e' to unmount the whole drive"]
|
" and 'e' to unmount, 'enter' to cd"]
|
||||||
message = ""
|
message = ""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -75,9 +77,13 @@ class ChoosePartition:
|
|||||||
label = part[f]
|
label = part[f]
|
||||||
break
|
break
|
||||||
|
|
||||||
mp = "Not mounted"
|
mp = None
|
||||||
if part['mountpoint'] is not None:
|
if part['mountpoint'] is not None:
|
||||||
mp = part['mountpoint']
|
mp = part['mountpoint']
|
||||||
|
if is_selected:
|
||||||
|
self.selected_mountpoint = mp
|
||||||
|
if mp is None:
|
||||||
|
mp = "Not mounted"
|
||||||
|
|
||||||
s = "{name:<12} {size:<8} {label:<16} {mp}".format(
|
s = "{name:<12} {size:<8} {label:<16} {mp}".format(
|
||||||
name=part['name'] if part['name'] is not None else "None",
|
name=part['name'] if part['name'] is not None else "None",
|
||||||
@ -145,7 +151,8 @@ class ChoosePartition:
|
|||||||
sel = None
|
sel = None
|
||||||
x = 0
|
x = 0
|
||||||
# quit when pressed `q` or `Esc` or `Ctrl+g`
|
# quit when pressed `q` or `Esc` or `Ctrl+g`
|
||||||
while x not in (ord('q'), curses.ascii.ESC, curses.ascii.BEL):
|
while x not in (ord('q'), curses.ascii.ESC,
|
||||||
|
curses.ascii.BEL, curses.ascii.NL):
|
||||||
self._select_print(x)
|
self._select_print(x)
|
||||||
x = self.screen.getch()
|
x = self.screen.getch()
|
||||||
if x in (ord('j'), curses.ascii.SO, curses.KEY_DOWN):
|
if x in (ord('j'), curses.ascii.SO, curses.KEY_DOWN):
|
||||||
@ -171,6 +178,9 @@ class ChoosePartition:
|
|||||||
elif x == ord('g') or x == ord('r'):
|
elif x == ord('g') or x == ord('r'):
|
||||||
self._read_partitions()
|
self._read_partitions()
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
if self.selected_mountpoint is not None and x == curses.ascii.NL:
|
||||||
|
return self.selected_mountpoint
|
||||||
|
return ""
|
||||||
|
|
||||||
def _udisk_mount_unmount(self, cmd, dev):
|
def _udisk_mount_unmount(self, cmd, dev):
|
||||||
r = ""
|
r = ""
|
||||||
@ -193,4 +203,10 @@ class ChoosePartition:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cp = ChoosePartition()
|
cp = ChoosePartition()
|
||||||
cp.select()
|
sel = cp.select()
|
||||||
|
# print(sel)
|
||||||
|
# print(len(sys.argv))
|
||||||
|
if len(sys.argv) >= 2:
|
||||||
|
# print(sys.argv[1])
|
||||||
|
with open(sys.argv[1], 'w') as f:
|
||||||
|
f.write(sel)
|
||||||
|
11
mounter.py
11
mounter.py
@ -6,6 +6,8 @@
|
|||||||
# Description: This launches script that draws menu to choose, mount and unmount drives from ranger file manager
|
# Description: This launches script that draws menu to choose, mount and unmount drives from ranger file manager
|
||||||
|
|
||||||
from ranger.api.commands import Command
|
from ranger.api.commands import Command
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class mount(Command):
|
class mount(Command):
|
||||||
@ -16,5 +18,12 @@ class mount(Command):
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
""" Show menu to mount and unmount """
|
""" Show menu to mount and unmount """
|
||||||
|
(f, p) = tempfile.mkstemp()
|
||||||
|
os.close(f)
|
||||||
self.fm.execute_console(
|
self.fm.execute_console(
|
||||||
"shell python3 ~/.config/ranger/ranger_udisk_menu/menu.py")
|
f"shell python3 ~/.config/ranger/ranger_udisk_menu/menu.py {p}")
|
||||||
|
with open(p, 'r') as f:
|
||||||
|
d = f.readline()
|
||||||
|
if os.path.exists(d):
|
||||||
|
self.fm.cd(d)
|
||||||
|
os.remove(p)
|
||||||
|
Loading…
Reference in New Issue
Block a user