-
Notifications
You must be signed in to change notification settings - Fork 5
/
flatpak-alias
executable file
·42 lines (33 loc) · 1.23 KB
/
flatpak-alias
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
#!/usr/bin/env python3
import os
import subprocess
from configparser import ConfigParser, ExtendedInterpolation
from shutil import which
from xdg.BaseDirectory import xdg_cache_home
binaries = os.listdir("/var/lib/flatpak/exports/bin/")
command = ["flatpak", "info", "-m"]
initial = ["PATH=$PATH:/var/lib/flatpak/exports/bin"]
aliases = []
for binary in binaries:
appid = os.path.basename(binary)
try:
proc = subprocess.run(command + [appid], check=True, capture_output=True)
# This might be overkill
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser.read_string(proc.stdout.decode("utf-8"))
cmd = os.path.basename(parser["Application"]["command"]).replace("-wrapper", "")
if not which(cmd):
aliases.append("alias {}={}".format(cmd, appid))
except:
print("skiping: {}".format(appid))
path = os.path.join(xdg_cache_home, "flatpak-aliases")
contents = [x + "\n" for x in initial + aliases]
with open(path, "w+") as f:
f.writelines(contents)
print(
"""Add
if [ -f "${XDG_CACHE_HOME}"/flatpak-aliases ] && ! [ "$HOSTNAME" == "toolbox" ] && [[ -z "${FLATPAK_ID}" ]]; then
. "${XDG_CACHE_HOME}"/flatpak-aliases
fi
to your ~/.bashrc file."""
)