Last active
September 21, 2024 19:07
-
-
Save madprops/db01a7e714e5305b8b46443cd665ddd6 to your computer and use it in GitHub Desktop.
command palette for terminals
This file contains hidden or 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
import time | |
from subprocess import Popen, PIPE | |
from pathlib import Path | |
info = "Pick a command" | |
items = Path("~/.config/awesome/scripts/data/commands.data").expanduser().read_text().split("\n") | |
selected = 0 | |
rofi_cmd = f""" | |
rofi -dmenu -i -format i | |
-inputchange-action 'kb-row-first' | |
keys -kb-accept-alt '' | |
-p '{info}' | |
-selected-row {selected} | |
""" | |
rofi_cmd = " ".join(rofi_cmd.strip().split()) | |
proc = Popen( | |
rofi_cmd, | |
stdout=PIPE, | |
stdin=PIPE, | |
shell=True, | |
text=True, | |
) | |
s_index, stderr = proc.communicate("\n".join(items)) | |
code = proc.returncode | |
if code == 1: | |
exit(0) | |
index = int(s_index) | |
ans = items[index].strip() | |
if ans == "": | |
exit(0) | |
time.sleep(0.2) | |
Popen(f"xdotool type '{ans}'", shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment