-
Notifications
You must be signed in to change notification settings - Fork 0
/
flatpak-reshim
executable file
·49 lines (39 loc) · 1.33 KB
/
flatpak-reshim
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
44
45
46
47
48
49
#!/usr/bin/env python
# Create shims that allow flatpak apps to be executed from the command line by only using the end part of the packge name.
# ie com.valvesoftware.Steam -> steam
# Requires "~/.flatpak-shims" to be added to $PATH.
import subprocess
import os
import stat
import shutil
import textwrap
DIRS = [
os.path.expanduser("~/.local/share/flatpak/exports/share/applications/"),
"/var/lib/flatpak/exports/share/applications/",
]
SHIM_PATH = os.path.expanduser("~/.flatpak-shims")
def main():
try:
os.mkdir(SHIM_PATH)
except:
shutil.rmtree(SHIM_PATH)
os.mkdir(SHIM_PATH)
# All the executable apps are in these folders
for dir in DIRS:
if not os.path.exists(dir):
continue
for file in os.listdir(dir):
if "mimeinfo.cache" in file:
continue
full_app_name = file.removesuffix(".desktop")
app_name = full_app_name.split(".")[-1].lower()
file = f"{SHIM_PATH}/{app_name}"
with open(file, "w") as f:
f.write(textwrap.dedent(f"""\
#!/bin/sh
exec flatpak run {full_app_name} $@
"""))
st = os.stat(file)
os.chmod(file, st.st_mode | stat.S_IEXEC)
if __name__ == '__main__':
main()