From 14cb3a12254c917705eb29c134dbfcceb8c2ca29 Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Tue, 22 Aug 2023 00:02:58 +0100 Subject: [PATCH] Add a post about fuzzy launcher --- content/posts/a_fuzzy_laungher_i_use/note.md | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 content/posts/a_fuzzy_laungher_i_use/note.md diff --git a/content/posts/a_fuzzy_laungher_i_use/note.md b/content/posts/a_fuzzy_laungher_i_use/note.md new file mode 100644 index 0000000..b86fa62 --- /dev/null +++ b/content/posts/a_fuzzy_laungher_i_use/note.md @@ -0,0 +1,31 @@ +X-Date: 2023-08-21T23:30:00Z +X-Note-Id: 19a3f09f-467c-4ba5-ba58-fd954cd931ea +Subject: A fuzzy launcher I use for the last 2 years +X-Slug: a_fuzzy_launcher_i_use + +About 2 years ago, I decided to write [my own launcher](https://git.sr.ht/~knazarov/q.sh). +It's been originally for [Yabai](https://github.com/koekeishiya/yabai) +WM, which is a tiling WM for the mac. I wrote it because at the time there were no satisfactory replacements to dmenu/rofi +that suited my personal needs. Right now I use it with Linux, because it's fully portable. + +Since I was short on time, I decided to not write my own GUI. Instead, I was starting a terminal in the middle of the screen +without window decorations, which started my launcher instead of bash. + +For the launcher, I decided to pick fzf, which already has great fuzzy search-and-complete. It turned out eventually that +fzf can not only filter stdin and run a command, but can also run a script that would interactively receive an updated +line that the user is typing. + +Using `change:reload-sync:`, you can make fzf run any external program that can essentially produce auto-completions for +the line the user is typing. So, using it you can implement prefix commands. In my case, if I type an equal sign and then +press space, the shell script underneath will switch into an expression evaluation mode (pipe the rest of the command to +"bc" and print the result). As the user edits the expression, the output will be updated as well. + +And as a final addition, depending on the prefix command the action taken when the user presses "enter" will be different. +For passwords, I use the "pass" tool and the action would be to copy the password to the clipboard. For bookmarks, the +action would be to open them in the browser. + +To be fair, some other people have come to roughly the same idea. +See [sway-launcher-desktop](https://github.com/Biont/sway-launcher-desktop) for example. I just don't think that other people +went as far as to add prefix commands and extensibility. + +If you want to read through the code, you can find it [here](https://git.sr.ht/~knazarov/q.sh).