예제 #1
0
from os import linesep
import json
from rofi import Rofi
r = Rofi()
subprocess.run("whoami > /tmp/whoami", shell=True)
with open("/tmp/whoami", "r") as whoami:
    user = whoami.read().replace(linesep, "")
subprocess.run("rm /tmp/whoami".split(" "))
home = str(f"/home/{user}")
multimc_folder = f"{home}/.local/share/multimc/instances"  # replace with wherever multimc folder is, if this isn't it

try:
    with open(f"{multimc_folder}/instgroups.json", "r") as raw_inst_groups:
        instgroups = json.loads(raw_inst_groups.read())
except:
    r.exit_with_error("MultiMC folder not found. Please add it to the code.")

instances = []
instances_shown = []
instance_name = ""
for group in instgroups["groups"]:
    for instance in instgroups["groups"][group]["instances"]:
        instances.append(instance)
        with open(f"{multimc_folder}/{instance}/instance.cfg",
                  "r") as instancecfg:
            configs = instancecfg.read().split("\n")
            for cfg in configs:
                if (cfg.startswith("name=")):
                    instance_name = cfg.replace("name=", "")
                    break
        instances_shown.append(f"{instance_name} ({group})")
예제 #2
0
from rofi import Rofi

# initialize argument parser
parser = argparse.ArgumentParser(description='Rofi frontend for keepassxc interaction')
parser.add_argument('--database', help='Path to your keepass database', required=True)
args = parser.parse_args()

# initialize rofi
r = Rofi()
password = r.text_entry('Master Password', rofi_args=['-password', '-lines', '0'])

try:
    # load database
    kp = PyKeePass(args.database, password=password)
except CredentialsIntegrityError as e:
    r.exit_with_error('Could not open database')

options = []
for entry in kp.entries:
    options.append(entry.title)

index, key = r.select('Name', options, key1=('Alt+1', "Type all"), key2=('Alt+2', "Type user"), key3=('Alt+3', "Type pass"), rofi_args=['-i', '-no-custom'])

if(key == 0):
    # copy password
    cmd = "echo -n " + shlex.quote(kp.entries[index].password) + " | xclip -selection clipboard"
    subprocess.Popen(cmd,shell=True).communicate()
    Notification("Will be cleared in 15 seconds", kp.entries[index].title + " copied")
    subprocess.Popen("sleep 15 && echo -n "" | xclip -selection clipboard", shell=True).communicate()
elif(key == 1):
    # type all