Update home/.config/ranger/commands.py
This commit is contained in:
parent
7ee5a42d46
commit
bd67b1985f
@ -3,11 +3,20 @@
|
|||||||
# File : .config/ranger/commands.py
|
# File : .config/ranger/commands.py
|
||||||
# Author : Jeff LANCE <email@jefflance.me>
|
# Author : Jeff LANCE <email@jefflance.me>
|
||||||
# Date : 12.05.2021
|
# Date : 12.05.2021
|
||||||
# Last Modified Date: 08.03.2024 17:35:06
|
# Last Modified Date: 08.03.2024 20:17:29
|
||||||
# Last Modified By : Jeff Lance <email@jefflance.me>
|
# Last Modified By : Jeff Lance <email@jefflance.me>
|
||||||
|
|
||||||
|
|
||||||
from ranger.api.commands import Command
|
from ranger.api.commands import Command
|
||||||
from plugins.ranger_udisk_menu.mounter import mount
|
from plugins.ranger_udisk_menu.mounter import mount
|
||||||
|
from tmsu import Tmsu
|
||||||
|
|
||||||
|
import os
|
||||||
|
import ranger.api
|
||||||
|
import ranger.core.linemode
|
||||||
|
|
||||||
|
|
||||||
|
tmsu = Tmsu.findTmsu()
|
||||||
|
|
||||||
|
|
||||||
class mkcd(Command):
|
class mkcd(Command):
|
||||||
@ -53,5 +62,78 @@ class tmsu_tag(Command):
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
cf = self.fm.thisfile
|
cf = self.fm.thisfile
|
||||||
|
tmsu.tag(cf.basename, self.rest(1))
|
||||||
|
|
||||||
self.fm.run('tmsu tag "{0}" {1}'.format(cf.basename, self.rest(1)))
|
def tab(self, tabnum):
|
||||||
|
"""Complete with tags"""
|
||||||
|
results = []
|
||||||
|
if self.arg(0) == self.arg(-1):
|
||||||
|
input_tag = ""
|
||||||
|
index = 1
|
||||||
|
else:
|
||||||
|
input_tag = self.arg(-1)
|
||||||
|
index = -1
|
||||||
|
|
||||||
|
if "=" in input_tag:
|
||||||
|
split_value = input_tag.split("=")[1]
|
||||||
|
split_tag = input_tag.split("=")[0]
|
||||||
|
for value in tmsu.values(split_tag):
|
||||||
|
if value.startswith(split_value):
|
||||||
|
results.append(split_tag + "=" + value)
|
||||||
|
else:
|
||||||
|
for tag in tmsu.tags():
|
||||||
|
if tag.startswith(input_tag):
|
||||||
|
results.append(tag)
|
||||||
|
return (self.start(index) + result for result in results)
|
||||||
|
|
||||||
|
|
||||||
|
class tmsu_untag(Command):
|
||||||
|
""":tmsu_untag
|
||||||
|
|
||||||
|
Untags the current file with tmsu
|
||||||
|
"""
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
cf = self.fm.thisfile
|
||||||
|
tmsu.untag(cf.basename, self.rest(1))
|
||||||
|
|
||||||
|
def tab(self, tabnum):
|
||||||
|
"""Complete with tags"""
|
||||||
|
results = []
|
||||||
|
if self.arg(0) == self.arg(-1):
|
||||||
|
input_tag = ""
|
||||||
|
index = 1
|
||||||
|
else:
|
||||||
|
input_tag = self.arg(-1)
|
||||||
|
index = -1
|
||||||
|
cf = self.fm.thisfile
|
||||||
|
|
||||||
|
for tag in tmsu.tags(fileName=cf.basename):
|
||||||
|
if tag.startswith(input_tag):
|
||||||
|
results.append(tag)
|
||||||
|
return (self.start(index) + result for result in results)
|
||||||
|
|
||||||
|
|
||||||
|
class tmsu_ls(Command):
|
||||||
|
""":tmsu_ls
|
||||||
|
|
||||||
|
List tags of the current file with tmsu
|
||||||
|
"""
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
cf = self.fm.thisfile
|
||||||
|
tags = tmsu.tags(cf.basename)
|
||||||
|
self.fm.notify(tags)
|
||||||
|
|
||||||
|
|
||||||
|
@ranger.api.register_linemode # It may be used as a decorator too!
|
||||||
|
class MyLinemode(ranger.core.linemode.LinemodeBase):
|
||||||
|
name = "tmsu_linemode"
|
||||||
|
|
||||||
|
uses_metadata = False
|
||||||
|
|
||||||
|
def filetitle(self, file, metadata):
|
||||||
|
return file.relative_path + str(tmsu.tags(file))
|
||||||
|
|
||||||
|
def infostring(self, file, metadata):
|
||||||
|
return file.user
|
||||||
|
Loading…
Reference in New Issue
Block a user