From 59d436a944249cb693b17746c219206b7ebe9f89 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 3 Nov 2022 15:35:06 +0100 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=A6=8A=20BREAKING:=20Use=20new=20XD?= =?UTF-8?q?G=20Base=20specification=20for=20state=20(#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switched the history from using the XDG_CACHE_HOME directory by default to use XDG_STATE_HOME by default. This makes sense since cache can (and should be prepared to) be wiped at any moment and the program functionality should not be hindered by this. Since we need to retain history through such wipes the newly introduced state directory is the perfect match for keeping the history file in. This does constitute a breaking change for existing histories which need to be moved to the new directory if they made use of the old cache directory. Concurrent with this we are renaming `XDG_CACHE_LOCATION` environment variable to `XDG_HISTORY_LOCATION` so this is a second breaking change for those using a custom location for their histories. This change attempts to make the naming scheme coherent and remove some left-over naming cruft from the old location being the cache directory. This provides one of the larger changes to the program so far. Fixes #5. --- CHANGELOG.md | 9 ++++++++- README.md | 8 ++++---- bemoji | 12 ++++++------ test/bemoji_cmds.bats | 4 ++-- test/bemoji_directories.bats | 16 ++++++++-------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0925518..7a86d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - +### Changed + +- (!) History uses `XDG_STATE_HOME` directory by default: + This constitutes a break in behavior if you relied a lot on your pick history in the default + location. To retain your old history file, simply move it from the old cache directory + (`~/.cache/bemoji-history.txt` by default) to the new one (`~/.local/state/bemoji-history.txt` + by default). +- (!) `XDG_CACHE_LOCATION` renamed to `XDG_HISTORY_LOCATION` to better signify its purpose diff --git a/README.md b/README.md index ba08616..f87eb72 100644 --- a/README.md +++ b/README.md @@ -144,14 +144,14 @@ If you don't wish those to show up, make use of these options. ### Setting custom directories -By default bemoji stores your recent history in `$XDG_CACHE_HOME/bemoji-history.txt`, -so most often in `~/.cache/bemoji-history.txt` +By default bemoji stores your recent history in `$XDG_STATE_HOME/bemoji-history.txt`, +so most often in `~/.local/state/bemoji-history.txt` You can overwrite the directories bemoji uses for its emoji lists and history files with the following two environment variables: ``` BEMOJI_DB_LOCATION=/path/to/my/emoji/directory -BEMOJI_CACHE_LOCATION=/path/to/my/cache/directory +BEMOJI_HISTORY_LOCATION=/path/to/my/state/directory ``` There are no equivalent commandline arguments to overwrite these two settings. @@ -247,7 +247,7 @@ with their default settings ```bash BEMOJI_DB_LOCATION=$XDG_DATA_HOME/bemoji # where the emoji lists reside -BEMOJI_CACHE_LOCATION=$XDG_CACHE_HOME # where the cache file resides +BEMOJI_HISTORY_LOCATION=$XDG_STATE_HOME # where the state file resides BEMOJI_CUSTOM_LIST="" # the custom emoji list to display BEMOJI_DOWNLOAD_LIST="" # the default emoji lists to download to database BEMOJI_DEFAULT_COMMAND= # which command to invoke by default diff --git a/bemoji b/bemoji index 723b911..d3df589 100755 --- a/bemoji +++ b/bemoji @@ -5,10 +5,10 @@ bm_version=0.3.0 bm_db_location=${BEMOJI_DB_LOCATION:-"${XDG_DATA_HOME:-$HOME/.local/share}/bemoji"} # Setting custom emoji list file location: # BEMOJI_CUSTOM_LIST=/my/location/emojis.txt -# Setting custom recent emoji cache: -# BEMOJI_CACHE_LOCATION=/path/to/my/recents/directory -bm_cache_dir="${BEMOJI_CACHE_LOCATION:-${XDG_CACHE_HOME:-$HOME/.cache}}" -bm_history_file="${bm_cache_dir}/bemoji-history.txt" +# Setting custom recent emoji history: +# BEMOJI_HISTORY_LOCATION=/path/to/my/recents/directory +bm_state_dir="${BEMOJI_HISTORY_LOCATION:-${XDG_STATE_HOME:-$HOME/.local/state}}" +bm_history_file="${bm_state_dir}/bemoji-history.txt" # Command to run after user chooses an emoji bm_default_cmd="$BEMOJI_DEFAULT_CMD" @@ -140,8 +140,8 @@ get_most_recent() { add_to_recent() { if [ -z "$1" ]; then return; fi - if [ ! -d "$bm_cache_dir" ]; then - mkdir -p "$bm_cache_dir" + if [ ! -d "$bm_state_dir" ]; then + mkdir -p "$bm_state_dir" fi echo "$1" >>"$bm_history_file" } diff --git a/test/bemoji_cmds.bats b/test/bemoji_cmds.bats index 2b0a937..2d0f324 100644 --- a/test/bemoji_cmds.bats +++ b/test/bemoji_cmds.bats @@ -15,8 +15,8 @@ setup() { # set up small default set of test emoji for each test export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database" - export BEMOJI_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache" - mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_CACHE_LOCATION" + export BEMOJI_HISTORY_LOCATION="$BATS_TEST_TMPDIR/history" + mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_HISTORY_LOCATION" cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt" } diff --git a/test/bemoji_directories.bats b/test/bemoji_directories.bats index 28068e1..ede78a0 100644 --- a/test/bemoji_directories.bats +++ b/test/bemoji_directories.bats @@ -15,8 +15,8 @@ setup() { # set up small default set of test emoji for each test export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database" - export BEMOJI_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache" - mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_CACHE_LOCATION" + export BEMOJI_HISTORY_LOCATION="$BATS_TEST_TMPDIR/history" + mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_HISTORY_LOCATION" cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt" } @@ -38,8 +38,8 @@ database=$BATS_TEST_TMPDIR/xdb-db/bemoji } @test "sets XDG directory for history by default" { - unset BEMOJI_CACHE_LOCATION - export XDG_CACHE_HOME="$BATS_TEST_TMPDIR/xdb-cache" + unset BEMOJI_HISTORY_LOCATION + export XDG_STATE_HOME="$BATS_TEST_TMPDIR/xdb-cache" run bemoji -v assert_output --regexp " history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$" @@ -54,10 +54,10 @@ database=$HOME/.local/share/bemoji } @test "falls back to default history location if no XDG found" { - unset BEMOJI_CACHE_LOCATION + unset BEMOJI_HISTORY_LOCATION run bemoji -v assert_output --regexp " -history=$HOME/.cache/bemoji-history.txt$" +history=$HOME/.local/state/bemoji-history.txt$" } @test "BEMOJI_DB_LOCATION sets correct db directory" { @@ -67,8 +67,8 @@ database=$BATS_TEST_TMPDIR/database " } -@test "BEMOJI_CACHE_LOCATION sets correct cache directory" { +@test "BEMOJI_HISTORY_LOCATION sets correct history directory" { run bemoji -v assert_output --regexp " -history=$BATS_TEST_TMPDIR/cache/bemoji-history.txt$" +history=$BATS_TEST_TMPDIR/history/bemoji-history.txt$" } From 32fc9f45ddafd06d0be47086c27aae6a351e5363 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 11 Apr 2023 21:59:24 +0200 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=A6=8A=20Update=20emoji=20url=20to?= =?UTF-8?q?=20latest=20version=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Point url to grab emoji from to latest version of emoji list, which should automatically point to upcoming versions as well. Fixes #18. --- CHANGELOG.md | 4 +++- bemoji | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a86d5a..022b526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - +### Fixed + +- Always download from newest emoji list url diff --git a/bemoji b/bemoji index d3df589..6da4e86 100755 --- a/bemoji +++ b/bemoji @@ -98,7 +98,7 @@ prepare_db() { dl_default_emoji() { local emojis - emojis=$(curl -sSL "https://unicode.org/Public/emoji/14.0/emoji-test.txt") + emojis=$(curl -sSL "https://unicode.org/Public/emoji/latest/emoji-test.txt") printf "%s" "$emojis" | sed -ne 's/^.*; fully-qualified.*# \(\S*\) \S* \(.*$\)/\1 \2/gp' >"$bm_db_location/emojis.txt" printf "Downloaded default emoji set.\n" } From 71d5dc455de7f7e0adb206d0fea2988daf39486e Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 11 Apr 2023 22:05:16 +0200 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=A6=8A=20Exit=20status=201=20on=20c?= =?UTF-8?q?ancelled=20selection=20(#20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When making no selection, i.e. cancelling during the selection process the program will return status code 1, whereas before it would carry the same return code as when making an emoji selection. Fixes #20. --- CHANGELOG.md | 4 +++- bemoji | 2 +- test/bemoji_cmds.bats | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 022b526..e8b0972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - +### Added + +- Pass through return code 1 from selection tool ### Changed diff --git a/bemoji b/bemoji index 6da4e86..1a7c35a 100755 --- a/bemoji +++ b/bemoji @@ -206,7 +206,7 @@ result=$(echo "$result" | grep -o '^\S\+' | tr -d '\n') case "$exit_value" in 1) - exit + exit 1 ;; 0) if [ ${#bm_cmds[@]} -eq 0 ]; then diff --git a/test/bemoji_cmds.bats b/test/bemoji_cmds.bats index 2d0f324..2b0a176 100644 --- a/test/bemoji_cmds.bats +++ b/test/bemoji_cmds.bats @@ -64,6 +64,11 @@ typing result" assert_output "my clipping" } +@test "Returns status code 1 on picker status code 1" { + BEMOJI_PICKER_CMD="return 1" run bemoji -e 3>&- + assert_failure 1 +} + @test "Prints output with newline by default" { bats_require_minimum_version 1.5.0 BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -e From 56ae0f1bab1efeb3dc65eeef43d47a02835efc3d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 11 Apr 2023 22:55:23 +0200 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=90=9B=20Pass=20through=20stdin=20t?= =?UTF-8?q?o=20custom=20typing=20tool=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, stdin contents were consumed and then not passed through to the typing tool. With this commit, they are correctly passed to any custom tool's stdin. Fixes #19. --- CHANGELOG.md | 1 + README.md | 2 ++ bemoji | 7 +++++-- test/bemoji_cmds.bats | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8b0972..2786a06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Always download from newest emoji list url +- Pass selection to custom typing tools through stdin diff --git a/README.md b/README.md index f87eb72..4986da3 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,8 @@ BEMOJI_CLIP_CMD="path/to/your/clipboard/tool" BEMOJI_TYPE_CMD="path/to/your/xdotool" ``` +The candidate list (in the case of picker tool) or the picked selection are passed to the tools through stdin. + This is pretty experimental and you'll have to see how well it works for you. The setting can not be changed through the commandline alone. diff --git a/bemoji b/bemoji index 1a7c35a..10ce980 100755 --- a/bemoji +++ b/bemoji @@ -165,11 +165,14 @@ _clipper() { # Set default typing uti _typer() { - totype=$(cat -) if [ -n "$BEMOJI_TYPE_CMD" ]; then # shellcheck disable=SC2068 ${BEMOJI_TYPE_CMD[@]} - elif [ -n "$WAYLAND_DISPLAY" ] && command -v wtype >/dev/null 2>&1; then + return + fi + + totype=$(cat -) + if [ -n "$WAYLAND_DISPLAY" ] && command -v wtype >/dev/null 2>&1; then wtype -s 30 "$totype" elif [ -n "$DISPLAY" ] && command -v xdotool >/dev/null 2>&1; then xdotool type --delay 30 "$totype" diff --git a/test/bemoji_cmds.bats b/test/bemoji_cmds.bats index 2b0a176..ced326c 100644 --- a/test/bemoji_cmds.bats +++ b/test/bemoji_cmds.bats @@ -54,6 +54,11 @@ setup() { typing result" } +@test "Passes selection to custom typer tool through stdin" { + BEMOJI_TYPE_CMD="cat -" run bemoji -t 3>&- + assert_output "❤️" +} + @test "Runs custom default command" { BEMOJI_DEFAULT_CMD="echo my custom command" run bemoji 3>&- assert_output "my custom command" From 941dd4aaeabcfa7681c708b8a8b79571f9acc948 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 11 Apr 2023 23:17:52 +0200 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=93=96=20Change=20AUR=20instruction?= =?UTF-8?q?s=20to=20fit=20multiple=20packages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generalized AUR package installation instructions slightly to take note of the fact that there are multiple AUR packages available for bemoji. Thanks to @thayne for packaging up the semver release version of bemoji for the AUR! --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4986da3..78f1b02 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,10 @@ ln -s bemoji/bemoji /usr/local/bin/bemoji ### Arch Linux -On Arch Linux, bemoji has been packaged for the [AUR](https://aur.archlinux.org/packages/bemoji-git) so it can be installed manually from here or easily with your preferred AUR helper, e.g.: +On Arch Linux, bemoji has been packaged for the [AUR](https://aur.archlinux.org/packages?K=bemoji) so it can be installed manually from here or easily with your preferred AUR helper, e.g.: ```bash -paru -S bemoji-git +paru -S bemoji ``` ## 💿 Usage From 07de35e92f87c0393181e55991482ca984aba619 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 11 Apr 2023 23:25:41 +0200 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=93=96=20Fix=20riverwm=20usage=20in?= =?UTF-8?q?structions=20assuming=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Usage instructions for mapping the picker in riverwm falsely assumed the super key to already be mapped to a `$mod` variable. This commit fixes it to replace mention of the variable with the key name itself. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78f1b02..9100016 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ bindsym Mod4+Shift+e exec bemoji -t For `riverwm`, put the following in `~/.config/river/init`: ``` -riverctl map normal $mod+Shift E spawn "bemoji -t" +riverctl map normal Mod4+Shift E spawn "bemoji -t" ``` In `sxhkd`, put the following into `~/.config/sxhkd/sxhkdrc`: From 6b39e5e05a78a32e1bbd82aa1d44a68215cb46c6 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 12 Apr 2023 11:22:00 +0200 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=90=9B=20Create=20dist=20package=20?= =?UTF-8?q?contents=20at=20root=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .woodpecker.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 60e18dc..5eac51d 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -4,7 +4,8 @@ pipeline: commands: - /opt/bats/bin/bats test - release-prep: # prepare changelog and version information for release candidate + release-prep: + # prepare changelog and version information for release candidate when: event: tag tag: v* @@ -13,7 +14,8 @@ pipeline: - sed -ne 's/bm_version=\(.*\)/\1/p' bemoji > NEWEST_VERSION.txt - awk '/^## \[\d/{p++} p==2{print; exit} p>=1' CHANGELOG.md | head -n -1 | tail -n+3 > NEWEST_CHANGES.txt - versioncompare: # ensure we correctly bumped versions + versioncompare: + # ensure we correctly bumped versions when: event: tag tag: v* @@ -42,9 +44,10 @@ pipeline: - cp bemoji build - md2man -in README.md -out bemoji.1 && gzip bemoji.1 - cp LICENSE README.md bemoji.1.gz build/doc - - tar -czvf bemoji-$BM_VERSION.tar.gz build/* - - zip -r bemoji-$BM_VERSION.zip build/* - - mv bemoji-$BM_VERSION.tar.gz bemoji-$BM_VERSION.zip dist + - cd build || exit 1 + - tar -czvf bemoji-$BM_VERSION.tar.gz * + - zip -r bemoji-$BM_VERSION.zip * + - mv bemoji-$BM_VERSION.tar.gz bemoji-$BM_VERSION.zip ../dist release-gitea: group: release From 0aaca26b0e5b5ada1d7270ccee265466f4c28ccd Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 30 Apr 2023 18:16:26 +0200 Subject: [PATCH 08/12] =?UTF-8?q?=E2=9C=A8=20BREAKING:=20Add=20ability=20t?= =?UTF-8?q?o=20limit=20recent=20emoji=20shown=20(#1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of `-P` being a flag for showing history it has become an option whose argument is the number of history entries to show, `-P 4`. To mimic the old behavior use `-P 0`. Added some test coverage for history functionality. Fixes #1. --- CHANGELOG.md | 3 +++ README.md | 32 ++++++++++++++-------- bemoji | 28 +++++++++++++------- test/bemoji_history.bats | 57 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 21 deletions(-) create mode 100644 test/bemoji_history.bats diff --git a/CHANGELOG.md b/CHANGELOG.md index 2786a06..c13bcce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - 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` ### Changed diff --git a/README.md b/README.md index 9100016..6211079 100644 --- a/README.md +++ b/README.md @@ -118,10 +118,10 @@ 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 -P +bemoji -P 0 ``` -This will stop bemoji from re-ordering your emoji lists before displaying them. +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: @@ -133,20 +133,30 @@ 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: ```bash -bemoji -Pp +bemoji -p -P0 ``` Like this, you'll be hiding any recent personal emoji and no one will know that you always type 👄🍆💦. +To limit the number of your recently used emoji that are shown without hiding them completely simply increase the number to however many you wish to display. +For example, to display only the top 4 recently used emoji: + +```bash +bemoji -P 4 +``` + The recent list will also contain emoji that are *not* usually on your lists, so kept in single-use lists for example. If you don't wish those to show up, make use of these options. -### Setting custom directories +### Setting custom directories and editing history By default bemoji stores your recent history in `$XDG_STATE_HOME/bemoji-history.txt`, so most often in `~/.local/state/bemoji-history.txt` +You can edit this file in any text editor to change your recent history, +removing, adding or changing the emoji appearing there. + You can overwrite the directories bemoji uses for its emoji lists and history files with the following two environment variables: ``` @@ -248,16 +258,16 @@ What follows is a list of all environment variables bemoji understands, with their default settings ```bash -BEMOJI_DB_LOCATION=$XDG_DATA_HOME/bemoji # where the emoji lists reside -BEMOJI_HISTORY_LOCATION=$XDG_STATE_HOME # where the state file resides +BEMOJI_DB_LOCATION="$XDG_DATA_HOME/bemoji" # where the emoji lists reside +BEMOJI_HISTORY_LOCATION="$XDG_STATE_HOME" # where the state file resides BEMOJI_CUSTOM_LIST="" # the custom emoji list to display BEMOJI_DOWNLOAD_LIST="" # the default emoji lists to download to database -BEMOJI_DEFAULT_COMMAND= # which command to invoke by default -BEMOJI_PICKER_CMD=bemenu # which picker tool to use -BEMOJI_CLIP_CMD=wl-copy # which clipboard tool to use -BEMOJI_TYPE_CMD=wtype # which typing tool to use (ydotool will NOT work) +BEMOJI_DEFAULT_COMMAND="" # which command to invoke by default +BEMOJI_PICKER_CMD="bemenu" # which picker tool to use +BEMOJI_CLIP_CMD="wl-copy" # which clipboard tool to use +BEMOJI_TYPE_CMD="wtype" # which typing tool to use (ydotool will NOT work) BEMOJI_PRIVATE_MODE=false # whether to save new entries -BEMOJI_IGNORE_RECENT=false # whether to display recent entries +BEMOJI_LIMIT_RECENT="" # whether to display recent entries BEMOJI_ECHO_NEWLINE=true # whether to end the output with a newline character ``` diff --git a/bemoji b/bemoji index 10ce980..f054141 100755 --- a/bemoji +++ b/bemoji @@ -18,7 +18,7 @@ bm_echo_newline=${BEMOJI_ECHO_NEWLINE:-true} # Do not save choices bm_private_mode=${BEMOJI_PRIVATE_MODE:-false} # Do not sort results -bm_ignore_recent=${BEMOJI_IGNORE_RECENT:-false} +bm_limit_recent="$BEMOJI_LIMIT_RECENT" # Report usage usage() { @@ -35,7 +35,7 @@ usage() { 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 Do not order emoji by recently used." + echo " -P Limit number of recent emoji to display." echo " -D Choose from default lists to download." echo " Valid choices: all|none|emoji|math (multiple choices possible)." echo " -f Use a custom emoji database. Can be a url which will be retrieved." @@ -51,7 +51,7 @@ version() { } # Get Options -while getopts ":f:D:tcenpPhv" o; do +while getopts ":f:D:tcenpP:hv" o; do case "${o}" in f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;; t) bm_cmds+=(_typer) ;; @@ -60,7 +60,7 @@ while getopts ":f:D:tcenpPhv" o; do n) bm_echo_newline=false ;; D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;; p) bm_private_mode=true ;; - P) bm_ignore_recent=true ;; + P) bm_limit_recent="${OPTARG}" ;; h) usage 0 ;; v) version ;; *) usage 1 ;; @@ -117,25 +117,33 @@ gather_emojis() { result=$(cat "$bm_db_location"/*.txt) fi - if [ "$bm_ignore_recent" = true ]; then + if [ -n "$bm_limit_recent" ] && [ "$bm_limit_recent" -eq 0 ]; then printf "%s" "$result" - else - printf "%s\n%s" "$(get_most_recent)" "$result" | cat -n - | sort -uk2 | sort -n | cut -f2- + return fi + + printf "%s\n%s" "$(get_most_recent "$bm_limit_recent")" "$result" | cat -n - | sort -uk2 | sort -n | cut -f2- } get_most_recent() { + limit=${1} recent_file="$bm_history_file" if [ ! -f "$recent_file" ]; then touch "$recent_file" fi # TODO improve this messy line - sed -e '/^$/d' "$recent_file" | + local result + result=$(sed -e '/^$/d' "$recent_file" | sort | uniq -c | - sort -rn | + sort -k1rn | sed -e 's/^\s*//' | - cut -d' ' -f2- + cut -d' ' -f2-) + if [ -z "$limit" ]; then + echo "$result" + else + echo "$result" | head -n "$limit" + fi } add_to_recent() { diff --git a/test/bemoji_history.bats b/test/bemoji_history.bats new file mode 100644 index 0000000..82d7394 --- /dev/null +++ b/test/bemoji_history.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +setup_file() { + # make bemoji executable from anywhere relative to current testfile + TEST_DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + PATH="$TEST_DIR/..:$PATH" +} + +setup() { + load 'test_helper/bats-support/load' + load 'test_helper/bats-assert/load' + + # mock out interactive picker for static emoji return + export BEMOJI_PICKER_CMD="echo ❤️" + + # set up small default set of test emoji for each test + export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database" + export BEMOJI_HISTORY_LOCATION="$BATS_TEST_TMPDIR/history" + mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_HISTORY_LOCATION" + cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt" +} + +@test "sorts by frecency" { + echo -e "there\nhello\nhello" > "$BEMOJI_HISTORY_LOCATION/bemoji-history.txt" + echo -e "database" > "$BEMOJI_DB_LOCATION/emoji.txt" + BEMOJI_CLIP_CMD="cat -" BEMOJI_PICKER_CMD="cat -" run bemoji 3>&- + assert_output "hellotheredatabase" +} + +@test "history limiting uses sorted results" { + echo -e "zany\nmy\nisee\nonomatopeia" > "$BEMOJI_HISTORY_LOCATION/bemoji-history.txt" + echo -e "database" > "$BEMOJI_DB_LOCATION/emoji.txt" + BEMOJI_CLIP_CMD="cat -" BEMOJI_PICKER_CMD="cat -" run bemoji -P 1 3>&- + assert_output "iseedatabase" +} + +@test "history limiting takes frecency into account" { + echo -e "there\nfriend\nhello\nhello" > "$BEMOJI_HISTORY_LOCATION/bemoji-history.txt" + echo -e "database" > "$BEMOJI_DB_LOCATION/emoji.txt" + BEMOJI_CLIP_CMD="cat -" BEMOJI_PICKER_CMD="cat -" run bemoji -P 1 3>&- + assert_output "hellodatabase" +} + +@test "-P 0 disables history" { + echo -e "there\nfriend\nhello\nhello" > "$BEMOJI_HISTORY_LOCATION/bemoji-history.txt" + echo -e "database" > "$BEMOJI_DB_LOCATION/emoji.txt" + BEMOJI_CLIP_CMD="cat -" BEMOJI_PICKER_CMD="cat -" run bemoji -P 0 3>&- + assert_output "database" +} + +@test "BEMOJI_LIMIT_RECENT=0 disables history" { + echo -e "there\nfriend\nhello\nhello" > "$BEMOJI_HISTORY_LOCATION/bemoji-history.txt" + echo -e "database" > "$BEMOJI_DB_LOCATION/emoji.txt" + BEMOJI_LIMIT_RECENT=0 BEMOJI_CLIP_CMD="cat -" BEMOJI_PICKER_CMD="cat -" run bemoji 3>&- + assert_output "database" +} + From 54b72e583b6f88c30ad0834cb226ab7fcf8f90d6 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 30 Apr 2023 18:23:00 +0200 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=93=96=20Bump=20license=20copyright?= =?UTF-8?q?=20year?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index aa51234..2fb93db 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Marty Oehme +Copyright (c) 2023 Marty Oehme Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From e720343ffc90fcccd0ea6912a54c9a60caf10caf Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 1 May 2023 15:53:19 +0200 Subject: [PATCH 10/12] =?UTF-8?q?=E2=9C=A8=20Add=20ability=20to=20download?= =?UTF-8?q?=20nerdfont=20symbols=20(#10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same as the other symbol download options, this one takes a list of all nerdfont icons and wrangles them into shape to be usable with the emoji picker. Can be used by invoking `bemoji -D nerd` or `bemoji -D all`. Fixes #10. --- CHANGELOG.md | 7 ++++--- README.md | 12 ++++++------ bemoji | 13 ++++++++++++- test/bemoji_download.bats | 8 ++++++++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c13bcce..3b1018c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - 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` +- (!) 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` ### Changed diff --git a/README.md b/README.md index 6211079..13e989f 100644 --- a/README.md +++ b/README.md @@ -184,24 +184,24 @@ The path can also be a weblink which bemoji will download and use: bemoji -f "https://raw.githubusercontent.com/jchook/emoji-menu/master/data/emojis.txt" ``` -### Download additional emoji set +### Download additional emoji sets bemoji automatically downloads an emoji list for you to use on first invocation. -By default, it only downloads emoji, though you can have it download math symbols as well. +By default, it only downloads emoji, though you can have it download math symbols and nerdfont icons as well. To download additional sets, execute bemoji like the following: ```bash bemoji -D all ``` -This will download *all* default sets bemoji knows - which is currently the default emoji list and a long list of math symbols. -Other valid options for this setting are `emoji`, `math`, `none`. +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. +Other valid options for this setting are `emoji`, `math`, `nerd`, `none`. ```bash -bemoji -D "math emoji" +bemoji -D "math emoji nerd" ``` -The above command is equivalent 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. diff --git a/bemoji b/bemoji index f054141..1bb2cc2 100755 --- a/bemoji +++ b/bemoji @@ -37,7 +37,7 @@ usage() { echo " -p Do not save picked emoji to recent history." echo " -P Limit number of recent emoji to display." echo " -D Choose from default lists to download." - echo " Valid choices: all|none|emoji|math (multiple choices possible)." + echo " Valid choices: all|none|emoji|math|nerd (multiple choices possible)." echo " -f 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." @@ -81,6 +81,7 @@ prepare_db() { elif echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'all'; then dl_default_emoji dl_math_symbols + dl_nerd_symbols return else if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'emoji'; then @@ -89,6 +90,9 @@ prepare_db() { if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'math'; then dl_math_symbols fi + if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'nerd'; then + dl_nerd_symbols + fi fi fi if [ -n "$(find "$bm_db_location" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then @@ -107,6 +111,13 @@ dl_math_symbols() { grep -ve '^#' | cut -d';' -f3,7 | sed -e 's/;/ /' >"$bm_db_location/math.txt" printf "Downloaded math symbols set.\n" } +dl_nerd_symbols() { + local nerd all + nerd=$(curl -sSL "https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/css/nerd-fonts-generated.css") + all+=$(printf "%s" "$nerd" | sed -ne '/\.nf-/p' -e '/\s*[^_]content:/p' | sed -e 'N;s/^\.nf-\(.*\):before.* content: \"\\\(.*\)\";/\\U\2 \1/') + echo -e "$all" > "$bm_db_location/nerdfont.txt" + printf "Downloaded nerdfont symbols set.\n" +} gather_emojis() { if [ -n "$BEMOJI_CUSTOM_LIST" ] && [ -f "$BEMOJI_CUSTOM_LIST" ]; then diff --git a/test/bemoji_download.bats b/test/bemoji_download.bats index 6fda12b..707aaf7 100644 --- a/test/bemoji_download.bats +++ b/test/bemoji_download.bats @@ -38,3 +38,11 @@ emoji2 picked up" assert_equal "$outcome" "Σ GREEK CAPITAL LETTER SIGMA" unstub curl } +@test "Runs nerdfont download on -D nerd option" { + stub curl \ + "printf 'meangingless\nafiller lines\n.nf-md-pipe_wrench:before { \n content: \"\\\f1354\";\n }'" + run bemoji -D nerd 3>&- + outcome=$(cat "$BEMOJI_DB_LOCATION/nerdfont.txt") + assert_equal "$outcome" "󱍔 md-pipe_wrench" + unstub curl +} From a8256100f9061081746274b06facef6e5b7f2bb4 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 25 Aug 2023 20:47:14 +0200 Subject: [PATCH 11/12] =?UTF-8?q?=F0=9F=90=9B=20Fix=20release=20automation?= =?UTF-8?q?=20naming=20scheme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Names for tags in this repo start with a `v` (e.g. `v0.3.1`) but the release automation did not know about this and would create duplicate tags without the preceding letter. --- .woodpecker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 5eac51d..ff38c43 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -73,7 +73,7 @@ pipeline: - apk add file jq curl - BM_VERSION=$(cat NEWEST_VERSION.txt) - BM_CHANGED=$(sed -e 's|#||g' -e 's|^.*$|\0
|' NEWEST_CHANGES.txt) # display newlines workaround - - echo "{\"tag_name\":\"$BM_VERSION\",\"target_commitish\":\"main\",\"name\":\"$BM_VERSION\",\"body\":\"$BM_CHANGED\",\"draft\":false,\"prerelease\":false,\"generate_release_notes\":false}" > data.json + - echo "{\"tag_name\":\"v${BM_VERSION}\",\"target_commitish\":\"main\",\"name\":\"v${BM_VERSION}\",\"body\":\"$BM_CHANGED\",\"draft\":false,\"prerelease\":false,\"generate_release_notes\":false}" > data.json - "response=$(curl -X POST -H \"Accept:\\ application/vnd.github+json\" -H \"Authorization:\\ Bearer $GITHUB_RELEASE_TOKEN\" https://api.github.com/repos/$GITHUB_REPO/releases -d \"@data.json\")" - "uploadurl=$(echo $response | jq -r '.upload_url' | cut -d'{' -f1)" - "[ $uploadurl = null ] && { echo $response; exit 1; }" From 6c037a5771373d35549c3b80d19792bf72627f6a Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 25 Aug 2023 20:55:25 +0200 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=93=96=20Add=20reference=20to=20sta?= =?UTF-8?q?ble=20and=20git=20archlinux=20versions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since there is now both a -git version and a stable version in the AUR we make a small note for both in the installation documentation. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 13e989f..9b55372 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ ln -s bemoji/bemoji /usr/local/bin/bemoji On Arch Linux, bemoji has been packaged for the [AUR](https://aur.archlinux.org/packages?K=bemoji) so it can be installed manually from here or easily with your preferred AUR helper, e.g.: ```bash -paru -S bemoji +paru -S bemoji # or bemoji-git ``` ## 💿 Usage