コード例 #1
0
ファイル: ifconfless.py プロジェクト: wiedzmin/nixos-config
import argparse

from pystdlib.uishim import get_selection_rofi, show_text_dialog
from pystdlib import shell_cmd

parser = argparse.ArgumentParser(description="Repository overview search")
parser.add_argument('--selector-font',
                    dest="selector_font",
                    type=str,
                    help="Selector font")
args = parser.parse_args()

ifconfig_result = shell_cmd("ifconfig -s", split_output="\n")
iface_names = [iface_meta.split()[0] for iface_meta in ifconfig_result[1:]]

iface_name = get_selection_rofi(iface_names, "describe")
iface_traits = shell_cmd(f"ifconfig {iface_name}")

shell_cmd(["xsel", "-ib"],
          universal_newlines=True,
          input=f"{iface_traits.encode('utf-8')}")
show_text_dialog(text=iface_traits)
コード例 #2
0
host_meta = extra_hosts_data.get(hostname, None)
if not host_meta:
    notify("[docker]", f"Host '{hostname}' not found", urgency=URGENCY_CRITICAL, timeout=5000)
    sys.exit(1)

if hostname == "localhost":
    os.environ["DOCKER_HOST"] = "unix:///var/run/docker.sock"
else:
    os.environ["DOCKER_HOST"] = f"ssh://{hostname}"
    host_vpn = host_meta.get("vpn", None)
    if host_vpn:
        shell_cmd(f"vpn --start {host_vpn}")

container_status = get_selection_rofi(CONTAINER_STATUSES, "status")
if not container_status:
    sys.exit(1)

select_container_result = shell_cmd(
    f"docker ps {'-a ' if container_status == 'all' else ''}--format '{{.Names}}'",
    split_output="\n")

selected_container = get_selection_rofi(select_container_result, "container")
selected_trait = get_selection_rofi(CONTAINER_TRAITS.keys(), "inspect")

docker_inspect_cmd = f'docker inspect {selected_container} --format "{CONTAINER_TRAITS[selected_trait]}"'
inspect_result = shell_cmd(["xsel", "-ib"], universal_newlines=True, input=docker_inspect_cmd
                           env={"DOCKER_HOST": os.environ['DOCKER_HOST']})

show_text_dialog(text=inspect_result)
コード例 #3
0
                                      "service",
                                      case_insensitive=True,
                                      lines=10,
                                      font="@wmFontDmenu@")
selected_service_name = selected_service_meta.split("|")[0].strip()
selected_mode = get_selection(service_modes,
                              "show",
                              case_insensitive=True,
                              lines=5,
                              font="@wmFontDmenu@")

service_status = shell_cmd(f"docker service ps {selected_service_name}",
                           split_output="\n")

if selected_mode == "status":
    show_text_dialog(text=service_status)
elif selected_mode == "logs":
    service_running_tasks_items = [
        task.split() for task in service_status if "Running" in task
    ]
    task_mappings = dict([(task_meta[1], task_meta[0])
                          for task_meta in service_running_tasks_items])
    selected_task = get_selection(list(task_mappings.keys()) +
                                  [selected_service_name],
                                  "task",
                                  case_insensitive=True,
                                  lines=10,
                                  font="@wmFontDmenu@")
    if not selected_task:
        sys.exit(1)
コード例 #4
0
from pystdlib.uishim import show_text_dialog


# TODO: add parameter for various search approaches
# Either full list (as is) or dmenu noop choices should be displayed
# dmenu approach is essential for fuzzy recalling

r = redis.Redis(host='localhost', port=6379, db=0)

if not os.path.exists("@keybindingsCachePath@"):
    keybindings = json.loads(r.get("wm/keybindings"))

    legend = []
    for key, meta in keybindings.items():
        desktop = None
        if type(meta) == str:
            cmd = meta
        else:
            cmd = meta.get("cmd")
            desktop = meta.get("desktop", None)
        ands_index = cmd.rfind("&&")
        if ands_index == -1:
            cmd_result = cmd
        else:
            cmd_result = cmd[:ands_index]
        cmd_clean = cmd_result[cmd_result.rfind("/")+1:].strip('"/').replace('"', '')
        maybe_desktop = " (" + desktop + ")" if desktop else ""
        legend.append('{key}: {cmd_clean}{maybe_desktop}\n')

show_text_dialog(text=legend, title="keybindings", keep=True, path="@keybindingsCachePath@")
コード例 #5
0
        kb["modebinding"] = modebindings.get(kb["mode"], "")
        keybindings_by_mode.setdefault(kb["mode"], []).append(kb)
    else:
        kb["modebinding"] = ""
        dangling_keybindings_by_mode.setdefault(kb["mode"], []).append(kb)

for mode_name in keybindings_by_mode:
    if not args.fuzzy:
        legend.append(format_modebinding(mode_name,
                                         binding=modebindings[mode_name]
                                         if mode_name != "root" else "non-prefix"))
    for kb in keybindings_by_mode[mode_name]:
        legend.append(format_keybinding(kb, fuzzy=args.fuzzy))

if len(dangling_keybindings_by_mode):
    if not args.fuzzy:
        legend.append("================== DANGLING KEYBINDINGS ==================")
    for mode_name in dangling_keybindings_by_mode:
        if not args.fuzzy:
            legend.append(format_modebinding(mode_name))
        for kb in dangling_keybindings_by_mode[mode_name]:
            legend.append(format_keybinding(kb, fuzzy=args.fuzzy, dangling=True))

if args.fuzzy:
    get_selection_rofi(legend, "")
else:
    try:
        show_text_dialog(text=legend, title="keybindings")
    except ValueError:
        print("Canceled")