Compare commits

...

3 commits

Author SHA1 Message Date
Jesse Cooke
74af60c3f7
Add support for ilia desktop executor
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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.
2023-09-14 17:14:39 +02:00
011fcdefdd
📖 Update usage screenshot
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-08-26 14:58:45 +02:00
d44cbf5b74
Add long-form option parsing
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
So far we could only add single-letter (POSIX) options: `-e`, `-n` and
so forth. Since we will run out of alphabet at some point, this commit
introduces parsing of multi-letter long-form (gnu) options (plus any
modern application should really support it anyways):
`--echo`, `--noline`.

Additionally, we support supplying long-form options that supply a value
both in the spaced (`--hist-limit 0`) and the equals (`--hist-limit=0`)
forms. Short, long, spaced, equals can be mixed and matched between
freely.

Lastly, we retain the ability to concatenate short options as before
(`-ne` is valid, as is `-P0` for the respective options above).

This should cover all bases and does not complicate the code too much to
keep a coherent overview.

Changed several code samples in the documentation to make
use of short- or long-form options to point out
possibility.
2023-08-26 14:37:44 +02:00
5 changed files with 152 additions and 60 deletions

View file

@ -9,11 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Add default support for `ilia` gtk-based picker tool, used by default in Regolith Linux
- Pass through return code 1 from selection tool - Pass through return code 1 from selection tool
- (!) Number of displayed recent emoji can be set with `-P` option: - (!) 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 This replaces previous `-P` history flag toggle. Use number to set amount of recent
entries to display, `-P3`. To completely hide history use `-P0`. entries to display, `-P3`. To completely hide history use `-P0`.
- Add nerdfont emoji set download with `-D nerd` - Add nerdfont emoji set download with `-D nerd`
- Add parsing for long-form options (`--private` instead of `-p` and so on):
Options requiring a value can be given both in space-separated (`--hist-limit 2`)
and equals-separated (`--hist-limit=2`) versions. POSIX option concatenation still
works (`-ne` to echo without newline).
### Changed ### Changed

View file

@ -118,7 +118,7 @@ By default, bemoji will sort the list it displays by your most frequently and mo
To disable this behavior, execute bemoji like the following: To disable this behavior, execute bemoji like the following:
```bash ```bash
bemoji -P 0 bemoji --hist-limit 0
``` ```
This will stop bemoji from adding recently used emoji before displaying the list. This will stop bemoji from adding recently used emoji before displaying the list.
@ -126,11 +126,12 @@ This will stop bemoji from adding recently used emoji before displaying the list
You can also stop bemoji from adding any emoji to your history in the first place: You can also stop bemoji from adding any emoji to your history in the first place:
```bash ```bash
bemoji -p bemoji --private
``` ```
This will not add any of the emoji you pick to your recent emojis. This will not add any of the emoji you pick to your recent emojis.
Put both together to completely ignore the recent emoji feature of the program: Put both together to completely ignore the recent emoji feature of the program
(these are the equivalent short versions of the options above):
```bash ```bash
bemoji -p -P0 bemoji -p -P0
@ -142,7 +143,7 @@ To limit the number of your recently used emoji that are shown without hiding th
For example, to display only the top 4 recently used emoji: For example, to display only the top 4 recently used emoji:
```bash ```bash
bemoji -P 4 bemoji --hist-limit 4
``` ```
The recent list will also contain emoji that are *not* usually on your lists, The recent list will also contain emoji that are *not* usually on your lists,
@ -171,7 +172,7 @@ There are no equivalent commandline arguments to overwrite these two settings.
A custom emoji list can be supplied as commandline argument `-f` or `BEMOJI_CUSTOM_LIST` environment variable. A custom emoji list can be supplied as commandline argument `-f` or `BEMOJI_CUSTOM_LIST` environment variable.
```bash ```bash
bemoji -f path/to/my/list.txt bemoji --file path/to/my/list.txt
``` ```
The list will override the normally presented emoji, The list will override the normally presented emoji,
@ -191,7 +192,7 @@ By default, it only downloads emoji, though you can have it download math symbol
To download additional sets, execute bemoji like the following: To download additional sets, execute bemoji like the following:
```bash ```bash
bemoji -D all bemoji --download all
``` ```
This will download *all* default sets bemoji knows - which is currently the default emoji list, nerd font icons, and a long list of math symbols. This will download *all* default sets bemoji knows - which is currently the default emoji list, nerd font icons, and a long list of math symbols.
@ -201,7 +202,7 @@ Other valid options for this setting are `emoji`, `math`, `nerd`, `none`.
bemoji -D "math emoji nerd" bemoji -D "math emoji nerd"
``` ```
The above command is equivalent to `all` as you can mention multiple sets you want downloaded. The above command is equivalent to the previous `all` as you can mention multiple sets you want downloaded.
If set to `none` and no files are in the emoji directory, If set to `none` and no files are in the emoji directory,
bemoji will complain and not show anything. bemoji will complain and not show anything.
@ -244,7 +245,7 @@ You can execute bemoji with the `-e` flag with which you tell it not to do anyth
This can be very useful for creating your own little script with it: This can be very useful for creating your own little script with it:
```bash ```bash
bemoji -e | cat <(echo -n "https://emojipedia.org/") - | xargs xdg-open bemoji --echo | cat <(echo -n "https://emojipedia.org/") - | xargs xdg-open
``` ```
This snippet will open a wiki page for the picked emoji in your browser. This snippet will open a wiki page for the picked emoji in your browser.
@ -283,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. 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. 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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 241 KiB

119
bemoji
View file

@ -20,6 +20,14 @@ bm_private_mode=${BEMOJI_PRIVATE_MODE:-false}
# Do not sort results # Do not sort results
bm_limit_recent="$BEMOJI_LIMIT_RECENT" 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 # Report usage
usage() { usage() {
echo "Usage: $(basename "$0") [-t | -c | -e] [-f <filepath> ] [-p] [-P] [-D <choices>]" 1>&2 echo "Usage: $(basename "$0") [-t | -c | -e] [-f <filepath> ] [-p] [-P] [-D <choices>]" 1>&2
@ -28,19 +36,19 @@ usage() {
echo "Invoked without arguments sends the picked emoji to the clipboard." echo "Invoked without arguments sends the picked emoji to the clipboard."
echo echo
echo " Command options (can be combined):" echo " Command options (can be combined):"
echo " -t Simulate typing the emoji choice with the keyboard." echo " -t, --type Simulate typing the emoji choice with the keyboard."
echo " -c Send emoji choice to the clipboard. (default)" echo " -c, --clip Send emoji choice to the clipboard. (default)"
echo " -e Only echo out the picked emoji." echo " -e, --echo Only echo out the picked emoji."
echo "" echo ""
echo " Other options:" echo " Other options:"
echo " -n Do not print a newline after the picked emoji." echo " -n, --noline Do not print a newline after the picked emoji."
echo " -p Do not save picked emoji to recent history." echo " -p, --private Do not save picked emoji to recent history."
echo " -P <number> Limit number of recent emoji to display." echo " -P, --hist-limit <number> Limit number of recent emoji to display."
echo " -D <choice> Choose from default lists to download." echo " -D, --download <choice> Choose from default lists to download."
echo " Valid choices: all|none|emoji|math|nerd (multiple choices possible)." echo " Valid choices: all|none|emoji|math|nerd (multiple choices possible)."
echo " -f <filepath> Use a custom emoji database. Can be a url which will be retrieved." echo " -f, --file <filepath> Use a custom emoji database. Can be a url which will be retrieved."
echo " -v Display current program version and directory configuration." echo " -v, --version Display current program version and directory configuration."
echo " -h Show this help." echo " -h, --help Show this help."
echo echo
exit "$1" exit "$1"
} }
@ -50,22 +58,67 @@ version() {
exit exit
} }
# Get Options parse_cli() {
while getopts ":f:D:tcenpP:hv" o; do while getopts cD:ef:hnpP:tv-: arg "$@"; do
case "${o}" in case "$arg" in
f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;;
t) bm_cmds+=(_typer) ;;
c) bm_cmds+=(_clipper) ;; c) bm_cmds+=(_clipper) ;;
D) _opt_set_download_list "${OPTARG}" ;;
e) bm_cmds+=(cat) ;; e) bm_cmds+=(cat) ;;
n) bm_echo_newline=false ;; f) _opt_set_custom_list "${OPTARG}" ;;
D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;;
p) bm_private_mode=true ;;
P) bm_limit_recent="${OPTARG}" ;;
h) usage 0 ;; h) usage 0 ;;
n) bm_echo_newline=false ;;
p) bm_private_mode=true ;;
P) _opt_set_hist_limit "${OPTARG}" ;;
t) bm_cmds+=(_typer) ;;
v) version ;; v) version ;;
*) usage 1 ;; -)
LONG_OPTARG="${OPTARG#*=}"
case "$OPTARG" in
clip) bm_cmds+=(_clipper) ;;
download=?*) _opt_set_download_list "${LONG_OPTARG}" ;;
download*)
_opt_set_download_list "${*:$OPTIND:1}"
OPTIND=$((OPTIND + 1))
;;
echo) bm_cmds+=(cat) ;;
file=?*) _opt_set_custom_list "${LONG_OPTARG}" ;;
file*)
_opt_set_custom_list "${*:$OPTIND:1}"
OPTIND=$((OPTIND + 1))
;;
help) usage 0 ;;
noline) bm_echo_newline=false ;;
private) bm_private_mode=true ;;
hist-limit=?*) _opt_set_hist_limit "${LONG_OPTARG}" ;;
hist-limit*)
_opt_set_hist_limit "${*:$OPTIND:1}"
OPTIND=$((OPTIND + 1))
;;
type) bm_cmds+=(_typer) ;;
version) version ;;
'') break ;;
*)
echo "Unknown option: ${OPTARG}" 1>&2
usage 1
;;
esac
;;
\?) exit 2 ;;
esac esac
done done
shift $((OPTIND - 1))
OPTIND=1
}
_opt_set_custom_list() {
BEMOJI_CUSTOM_LIST="$1"
}
_opt_set_download_list() {
BEMOJI_DOWNLOAD_LIST="$1"
}
_opt_set_hist_limit() {
bm_limit_recent="$1"
}
prepare_db() { prepare_db() {
# Create list directory # Create list directory
@ -182,7 +235,7 @@ _clipper() {
fi fi
} }
# Set default typing uti # Set default typing util
_typer() { _typer() {
if [ -n "$BEMOJI_TYPE_CMD" ]; then if [ -n "$BEMOJI_TYPE_CMD" ]; then
# shellcheck disable=SC2068 # shellcheck disable=SC2068
@ -206,20 +259,22 @@ _picker() {
if [ -n "$BEMOJI_PICKER_CMD" ]; then if [ -n "$BEMOJI_PICKER_CMD" ]; then
# shellcheck disable=SC2068 # shellcheck disable=SC2068
${BEMOJI_PICKER_CMD[@]} ${BEMOJI_PICKER_CMD[@]}
elif command -v bemenu >/dev/null 2>&1; then return
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 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 "$@"
[ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db [ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db
result=$(gather_emojis | _picker) result=$(gather_emojis | _picker)
exit_value="$?" exit_value="$?"

View file

@ -85,3 +85,29 @@ typing result"
BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -ne BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -ne
assert_output --regexp '^heart$' assert_output --regexp '^heart$'
} }
@test "Understands long-form options" {
run bemoji --help
assert_success
assert_output --partial "A simple emoji picker."
}
@test "Understands long-form equals values" {
BEMOJI_CLIP_CMD="echo heart" run bemoji --hist-limit=0
assert_success
}
@test "Understands long-form spaced values" {
BEMOJI_CLIP_CMD="echo heart" run bemoji --hist-limit 0
assert_success
}
@test "Understands short-form spaced values" {
BEMOJI_CLIP_CMD="echo heart" run bemoji -P 0
assert_success
}
@test "Can concatenate short-form options and values" {
BEMOJI_CLIP_CMD="echo heart" run bemoji -neP0
assert_success
}