From 74af60c3f7d5be24dd584214dcec7ed4b71a926c Mon Sep 17 00:00:00 2001 From: Jesse Cooke Date: Thu, 14 Sep 2023 17:14:39 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Add=20support=20for=20ilia=20desktop?= =?UTF-8?q?=20executor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ilia is used by Regolith Linux (Ubuntu+i3/sway). Ilia has a slightly different presentation and prompt setup than other pickers, and it makes more sense to use the given GTK icon instead of the emoji character since that is what it seems to support. Nicely explained by @jc00ke here: https://github.com/marty-oehme/bemoji/pull/21#discussion_r1306212419 With the growing amount of picker tools supported out of the box it seems more practical to have them together in a simple list that can grow and through which we can always iterate instead of a cumbersome growing if-else chain. This commit also refactors the pick tool selection to be stored in a bash hash map instead. --- CHANGELOG.md | 1 + README.md | 9 +++++++-- bemoji | 34 +++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ce174c..1b9b5da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Add default support for `ilia` gtk-based picker tool, used by default in Regolith Linux - Pass through return code 1 from selection tool - (!) Number of displayed recent emoji can be set with `-P` option: This replaces previous `-P` history flag toggle. Use number to set amount of recent diff --git a/README.md b/README.md index 0b7af3f..a946f9b 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,12 @@ If you have an idea or improvement, don't hesitate to open a merge request! This project makes use of [bash-bats](https://github.com/bats-core/bats-core) (community fork) to test some of its functionality. -To run the tests locally, simply execute `./test/bats/bin/bats test`. +To run the tests locally: +``` +git submodule init +git submodule update +./test/bats/bin/bats test +``` I would suggest running the test suite in docker instead, just to minimize the possibility of something going awry and borking up your local file system. -To run the tests in a docker suite, execute `docker run --rm -it -v "$PWD:/code" bats/bats:latest /code/test` +To run the tests in a docker suite, execute `docker run --rm -it -v "$PWD:/code" bats/bats:latest /code/test` after initializing the git submodules as listed above. diff --git a/bemoji b/bemoji index 82464cb..a3fd400 100755 --- a/bemoji +++ b/bemoji @@ -20,6 +20,14 @@ bm_private_mode=${BEMOJI_PRIVATE_MODE:-false} # Do not sort results bm_limit_recent="$BEMOJI_LIMIT_RECENT" +declare -A default_pickers=( + ["bemenu"]="bemenu -p 🔍 -i -l 20" + ["wofi"]="wofi -p 🔍 -i --show dmenu" + ["rofi"]="rofi -p 🔍 -i -dmenu --kb-custom-1 "Alt+1" --kb-custom-2 "Alt+2"" + ["dmenu"]="dmenu -p 🔍 -i -l 20" + ["ilia"]="ilia -n -p textlist -l 'Emoji' -i desktop-magnifier" +) + # Report usage usage() { echo "Usage: $(basename "$0") [-t | -c | -e] [-f ] [-p] [-P] [-D ]" 1>&2 @@ -227,7 +235,7 @@ _clipper() { fi } -# Set default typing uti +# Set default typing util _typer() { if [ -n "$BEMOJI_TYPE_CMD" ]; then # shellcheck disable=SC2068 @@ -251,18 +259,18 @@ _picker() { if [ -n "$BEMOJI_PICKER_CMD" ]; then # shellcheck disable=SC2068 ${BEMOJI_PICKER_CMD[@]} - elif command -v bemenu >/dev/null 2>&1; then - bemenu -p 🔍 -i -l 20 - elif command -v wofi >/dev/null 2>&1; then - wofi -p 🔍 -i --show dmenu - elif command -v rofi >/dev/null 2>&1; then - rofi -p 🔍 -i -dmenu --kb-custom-1 "Alt+1" --kb-custom-2 "Alt+2" - elif command -v dmenu >/dev/null 2>&1; then - dmenu -p 🔍 -i -l 20 - else - printf "No suitable picker tool found." - exit 1 - fi + return + fi + + for tool in "${!default_pickers[@]}"; do + if command -v "$tool" >/dev/null 2>&1; then + ${default_pickers[$tool]} + return + fi + done + + printf "No suitable picker tool found." 1>&2 + exit 1 } parse_cli "$@"