Compare commits

..

No commits in common. "74af60c3f7d5be24dd584214dcec7ed4b71a926c" and "6c037a5771373d35549c3b80d19792bf72627f6a" have entirely different histories.

5 changed files with 60 additions and 152 deletions

View file

@ -9,16 +9,11 @@ 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
entries to display, `-P3`. To completely hide history use `-P0`.
- 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

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:
```bash
bemoji --hist-limit 0
bemoji -P 0
```
This will stop bemoji from adding recently used emoji before displaying the list.
@ -126,12 +126,11 @@ 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:
```bash
bemoji --private
bemoji -p
```
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
(these are the equivalent short versions of the options above):
Put both together to completely ignore the recent emoji feature of the program:
```bash
bemoji -p -P0
@ -143,7 +142,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:
```bash
bemoji --hist-limit 4
bemoji -P 4
```
The recent list will also contain emoji that are *not* usually on your lists,
@ -172,7 +171,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.
```bash
bemoji --file path/to/my/list.txt
bemoji -f path/to/my/list.txt
```
The list will override the normally presented emoji,
@ -192,7 +191,7 @@ By default, it only downloads emoji, though you can have it download math symbol
To download additional sets, execute bemoji like the following:
```bash
bemoji --download all
bemoji -D 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.
@ -202,7 +201,7 @@ Other valid options for this setting are `emoji`, `math`, `nerd`, `none`.
bemoji -D "math emoji nerd"
```
The above command is equivalent to the previous `all` as you can mention multiple sets you want downloaded.
The above command is equivalent to `all` as you can mention multiple sets you want downloaded.
If set to `none` and no files are in the emoji directory,
bemoji will complain and not show anything.
@ -245,7 +244,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:
```bash
bemoji --echo | cat <(echo -n "https://emojipedia.org/") - | xargs xdg-open
bemoji -e | cat <(echo -n "https://emojipedia.org/") - | xargs xdg-open
```
This snippet will open a wiki page for the picked emoji in your browser.
@ -284,12 +283,7 @@ 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:
```
git submodule init
git submodule update
./test/bats/bin/bats test
```
To run the tests locally, simply execute `./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` after initializing the git submodules as listed above.
To run the tests in a docker suite, execute `docker run --rm -it -v "$PWD:/code" bats/bats:latest /code/test`

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 KiB

After

Width:  |  Height:  |  Size: 41 KiB

155
bemoji
View file

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

View file

@ -85,29 +85,3 @@ typing result"
BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -ne
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
}