Created
May 16, 2018 15:46
-
-
Save o-jasper/8f07eddb2d87e86b47deee29b64f21bf to your computer and use it in GitHub Desktop.
ln -s trick you can do with firejail, but with everything. In Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ln -s ~/.bin/lnstrick.py ~/.bin/echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MORE SUPER ECHO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import sys | |
import subprocess | |
import os | |
import sys | |
from pathlib import Path | |
def figure_path_list(): | |
got = os.getenv('LNS_TRICK_PATH') | |
got = got and got.split(';') or [] | |
if len(got) == 0 or got[-1] == '+': | |
return [os.getenv('HOME') + "/.config/lns-trick/", "/etc/lns-trick/", | |
"/usr/share/lib/lns-trick/defaults/", ""] + got | |
else: | |
return got | |
def find_file(path_list, file): | |
for p in path_list: | |
uf = p + "/" + file + ".args" | |
if Path(uf).is_file(): | |
return uf | |
def parse_file(fd, path_list): | |
for line in fd.readlines(): | |
if line.startswith(':inc'): | |
file = find_file(path_list, line[5:-1]) | |
if file: | |
with open(file) as sfd: | |
yield parse_file(sfd, path_list) | |
# elif line.startswith(':as line'): # Better allow quotes? | |
# yield line[9:-1] | |
# elif line.startswith(':just print'): # TODO maybe allow disabling.. | |
# assert line == ":just print\n" | |
# yield 1 | |
else: | |
assert not line.startswith(':'), "Dont have this command; " + line | |
if line.startswith('\\'): line = line[1:] | |
for el in line[:-1].split(" "): # TODO quotation.. | |
yield el | |
def flatten(gen): | |
for el in gen: | |
if type(el) == str: | |
yield el | |
else: | |
for sel in flatten(el): | |
yield sel | |
def prog(): | |
path_list = figure_path_list() | |
progname = sys.argv[0].split('/')[-1] | |
file = find_file(path_list, progname) | |
if file: | |
with open(file) as fd: | |
#print("\n".join(list(flatten(parse_file(fd, path_list))) | |
# + sys.argv[1:])) | |
# TODO instead do $PATH, ignoring this program itself? | |
subprocess.call(["/usr/bin/" + progname] + | |
list(flatten(parse_file(fd, path_list))) | |
+ sys.argv[1:]) | |
else: | |
print("Didn't find file for:", progname) | |
prog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment