-
Notifications
You must be signed in to change notification settings - Fork 0
/
kdeconnect_send.py
43 lines (32 loc) · 1.11 KB
/
kdeconnect_send.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import subprocess
from ranger.api.commands import Command
class kdeconnect_send(Command):
""":kdeconnect_send
Send selected files to a device using kdeconnect-cli.
Skips any selected directories.
"""
def execute(self):
# Get device id
id = subprocess.run(
["kdeconnect-cli", "-a", "--id-only", "|", "awk", "'{printf $1}'"],
capture_output=True,
encoding="utf-8",
).stdout.rstrip("\n")
# Exit if no connected device
if id == "":
self.fm.notify("No device found", bad=True)
return
# Get paths of selected files
paths = []
for file in self.fm.thisdir.get_selection():
path = file.basename
if os.path.isfile(path):
paths.append("'" + path + "'")
paths = " ".join(paths)
# Share files
command = f"kdeconnect-cli -d {id} --share {paths}"
self.fm.notify(f"Sending {paths} to device {id}")
self.fm.execute_command(command)
# Unmark files when done
self.fm.thisdir.mark_all(False)