Skip to content

Commit

Permalink
[sweep][launcher] support for spawner argument
Browse files Browse the repository at this point in the history
  • Loading branch information
aslpavel committed Sep 21, 2024
1 parent b96d7e6 commit d1be589
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions sweep/sweep/apps/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,22 @@

import argparse
import asyncio
import re
import shlex
import shutil
import re
import subprocess
from typing import Any, List, NamedTuple, cast

from gi.repository import Gio # type: ignore
from .. import Candidate, Icon, sweep, Field

from .. import Candidate, Field, Icon, sweep
from . import sweep_default_cmd

# material-rocket-launch-outline
PROMPT_ICON = Icon(
view_box=(0, 0, 24, 24),
size=(1, 3),
path="M13.13 22.19L11.5 18.36C13.07 17.78 14.54 17 15.9 16.09L13.13 22.19"
"M5.64 12.5L1.81 10.87L7.91 8.1C7 9.46 6.22 10.93 5.64 12.5M19.22 4"
"C19.5 4 19.75 4 19.96 4.05C20.13 5.44 19.94 8.3 16.66 11.58"
"C14.96 13.29 12.93 14.6 10.65 15.47L8.5 13.37C9.42 11.06 10.73 9.03 12.42 7.34"
"C15.18 4.58 17.64 4 19.22 4M19.22 2C17.24 2 14.24 2.69 11 5.93"
"C8.81 8.12 7.5 10.53 6.65 12.64C6.37 13.39 6.56 14.21 7.11 14.77L9.24 16.89"
"C9.62 17.27 10.13 17.5 10.66 17.5C10.89 17.5 11.13 17.44 11.36 17.35"
"C13.5 16.53 15.88 15.19 18.07 13C23.73 7.34 21.61 2.39 21.61 2.39"
"S20.7 2 19.22 2M14.54 9.46C13.76 8.68 13.76 7.41 14.54 6.63"
"S16.59 5.85 17.37 6.63C18.14 7.41 18.15 8.68 17.37 9.46"
"C16.59 10.24 15.32 10.24 14.54 9.46M8.88 16.53L7.47 15.12L8.88 16.53"
"M6.24 22L9.88 18.36C9.54 18.27 9.21 18.12 8.91 17.91L4.83 22H6.24M2 22"
"H3.41L8.18 17.24L6.76 15.83L2 20.59V22M2 19.17L6.09 15.09"
"C5.88 14.79 5.73 14.47 5.64 14.12L2 17.76V19.17Z",
path="M13.13 22.19L11.5 18.36C13.07 17.78 14.54 17 15.9 16.09L13.13 22.19 M5.64 12.5L1.81 10.87L7.91 8.1C7 9.46 6.22 10.93 5.64 12.5M19.22 4 C19.5 4 19.75 4 19.96 4.05C20.13 5.44 19.94 8.3 16.66 11.58 C14.96 13.29 12.93 14.6 10.65 15.47L8.5 13.37C9.42 11.06 10.73 9.03 12.42 7.34 C15.18 4.58 17.64 4 19.22 4M19.22 2C17.24 2 14.24 2.69 11 5.93 C8.81 8.12 7.5 10.53 6.65 12.64C6.37 13.39 6.56 14.21 7.11 14.77L9.24 16.89 C9.62 17.27 10.13 17.5 10.66 17.5C10.89 17.5 11.13 17.44 11.36 17.35 C13.5 16.53 15.88 15.19 18.07 13C23.73 7.34 21.61 2.39 21.61 2.39 S20.7 2 19.22 2M14.54 9.46C13.76 8.68 13.76 7.41 14.54 6.63 S16.59 5.85 17.37 6.63C18.14 7.41 18.15 8.68 17.37 9.46 C16.59 10.24 15.32 10.24 14.54 9.46M8.88 16.53L7.47 15.12L8.88 16.53 M6.24 22L9.88 18.36C9.54 18.27 9.21 18.12 8.91 17.91L4.83 22H6.24M2 22 H3.41L8.18 17.24L6.76 15.83L2 20.59V22M2 19.17L6.09 15.09 C5.88 14.79 5.73 14.47 5.64 14.12L2 17.76V19.17Z",
)
# fluent-box-multiple
FLATPAK_ICON = Icon(
Expand Down Expand Up @@ -173,8 +163,11 @@ async def main(args: list[str] | None = None) -> None:
parser.add_argument("--sweep", help="path to the sweep command")
parser.add_argument("--tty", help="path to the tty")
parser.add_argument("--log", help="log file")
parser.add_argument("--spawner", help="command line will be passed to spawner")
parser.add_argument(
"--no-window", action="store_true", help="do not create new terminal window"
"--no-window",
action="store_true",
help="do not create new terminal window",
)
parser.add_argument(
"--action",
Expand All @@ -184,31 +177,22 @@ async def main(args: list[str] | None = None) -> None:
)
opts = parser.parse_args(args)

fields = {
FLATPAK_REF: Field(glyph=FLATPAK_ICON),
TERMINAL_REF: Field(glyph=TERMINAL_ICON),
}

sweep_theme = opts.theme
sweep_args: dict[str, Any] = {}
sweep_cmd: list[str] = []
if not opts.no_window:
sweep_theme = sweep_theme or "dark"
sweep_args.update(
dict(
altscreen=True,
height=1024,
tmp_socket=True,
border=0,
)
)
sweep_args.update({"altscreen": True, "height": 1024, "tmp_socket": True})
sweep_cmd.extend(["kitty", "--class", "org.aslpavel.sweep.launcher"])
sweep_cmd.extend(shlex.split(opts.sweep) if opts.sweep else sweep_default_cmd())

items = await sweep(
DesktopEntry.get_all(),
sweep=sweep_cmd,
fields=fields,
fields={
FLATPAK_REF: Field(glyph=FLATPAK_ICON),
TERMINAL_REF: Field(glyph=TERMINAL_ICON),
},
scorer="substr",
tty=opts.tty,
theme=sweep_theme,
Expand All @@ -222,10 +206,16 @@ async def main(args: list[str] | None = None) -> None:
return
item = items[0]
match opts.action:
case _ if opts.spawner is not None:
cmd = item.commandline()
if cmd is not None:
args = shlex.split(opts.spawner)
args.extend(shlex.split(cmd))
subprocess.check_call(args, shell=False)
case "print":
cmd = item.commandline()
if cmd is not None:
print(item.commandline())
print(cmd)
case "launch":
item.app_info.launch()
case _:
Expand Down

0 comments on commit d1be589

Please sign in to comment.