dotfiles/scripts/rofi/config-selector.py

21 lines
683 B
Python
Raw Normal View History

2021-02-16 01:07:53 +01:00
#!/bin/python3
from subprocess import Popen, PIPE
from os.path import expandvars
def call_rofi(entries,command):
proc = Popen(command,
stdin=PIPE,
stdout=PIPE)
for e in entries:
proc.stdin.write((e+"\n").encode('utf-8'))
proc.stdin.close()
answer = proc.stdout.read().decode('utf-8')
return answer.replace("\n","")
with open('$HOME/.scripts/rofi/configfiles', 'r') as file:
choices = dict([(file.capitalize(), path) for file, path in [line.split(' ') for line in file.readlines()]])
choice = call_rofi(choices, ['rofi', '-dmenu','-i', '-matching', 'fuzzy', '-p', 'Configfile'])
print(expandvars(choices[choice]), end='')