Compare commits

..

26 commits

Author SHA1 Message Date
ab10547336
📖 Add example for setting manual picker to README
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
2024-04-17 10:20:57 +02:00
1cf9971d8b
📖 Bump version
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-22 13:46:45 +01:00
46fa824d42
🐛 Remove deprecated CI instruction 2024-02-22 13:46:45 +01:00
551e3468d8
📖 Bump license copyright year
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Bumping the year again. I am honestly not entirely sure what the best or
correct way to display this is - so I am simply copying what the `curl`
project is doing and stating the whole period of me working on it.

Perhaps one day (should we get more contributors or much more popular)
it may also make sense to copy its `THANKS` file to keep a stable copy
of my contributing helpers.
2024-01-11 11:28:44 +01:00
cb3d8fd5d6
🐛 Remove deprecated woodpecker ci conditions
Tag condition (when: event: tag) filters are not generalized to `ref`
instead of the old `tag` key. This switches them to the new version.

See
https://woodpecker-ci.org/docs/usage/workflow-syntax#when---conditional-execution
2024-01-11 11:17:47 +01:00
e14010eb53
🐛 Print user messages to stderr (#27)
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
Previously, any messages only intended for the user (status messages,
warnings, errors) were sent over stdout. The actual emoji items are also
sent to the pickers over stdout so they would sometimes pick up the
messages and show them as an option to pick. If history is enabled, we
then also save the falsely included items there to forever display as an
option.

This commit changes internal messages to all be sent over stderr
instead, so they should not be picked up by any external programs we
hand off to.
2024-01-11 10:58:11 +01:00
7b5b3e6e46
🦊 Migrate major woodpecker ci version
Migrated to newer woodpecker version requiring different pipeline
naming scheme, see https://woodpecker-ci.org/docs/migrations.
2024-01-11 09:25:23 +01:00
Laureηt
b97c09828d
Add support for fuzzel desktop executor
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Fuzzel is a wayland-native picker which support dmenu-like picking based
on standard input.
---------

Co-authored-by: Marty Oehme <marty.oehme@gmail.com>
2023-11-28 10:53:31 +01:00
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
6c037a5771
📖 Add reference to stable and git archlinux versions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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.
2023-08-25 20:55:39 +02:00
a8256100f9
🐛 Fix release automation naming scheme
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.
2023-08-25 20:47:14 +02:00
e720343ffc
Add ability to download nerdfont symbols (#10)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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.
2023-05-01 16:03:09 +02:00
54b72e583b
📖 Bump license copyright year
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-04-30 18:28:23 +02:00
0aaca26b0e
BREAKING: Add ability to limit recent emoji shown (#1)
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.
2023-04-30 18:22:44 +02:00
6b39e5e05a
🐛 Create dist package contents at root directory 2023-04-12 11:22:00 +02:00
07de35e92f
📖 Fix riverwm usage instructions assuming variable
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.
2023-04-11 23:25:41 +02:00
941dd4aaea
📖 Change AUR instructions to fit multiple packages
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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!
2023-04-11 23:20:03 +02:00
56ae0f1bab
🐛 Pass through stdin to custom typing tool (#19)
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.
2023-04-11 23:00:19 +02:00
71d5dc455d
🦊 Exit status 1 on cancelled selection (#20)
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.
2023-04-11 22:33:26 +02:00
32fc9f45dd
🦊 Update emoji url to latest version (#18)
Point url to grab emoji from to latest version of emoji list, which
should automatically point to upcoming versions as well.

Fixes #18.
2023-04-11 22:00:45 +02:00
59d436a944
🦊 BREAKING: Use new XDG Base specification for state (#5)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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.
2022-11-19 15:03:14 +01:00
4209b90669
📖 Bump version
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-10 16:12:15 +01:00
7f5c3772e2
🦊 Change download option to work multiple times (#16)
Changed `-D` option to always download the lists supplied, regardless of
the database directory being empty or not.

This means you can download additional lists after the first program
run, or re-download lists later on. It *will* overwrite your custom
changes however if your files are called the same as the default list
names.

Additionally removed dependency on GNU version of cut and added some
simple tests for the download functionality.

Fixes #16.
2022-11-10 16:05:23 +01:00
dc68887091
Add automated tagged releases
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
Using woodpecker ci most of the release process is now automated.
That means as soon as a new version tag (e.g. `v0.2.3`) is pushed the
release process is started and will (if versions have been bumped
correctly) set up a new release on Gitea and Github simultaneously.

The release process will fail if changelog and program versions
mismatch, or the version has not been bumped in general.

The release contains the executable and some documentation, including
the README as a manpage-formatted gzip file which can be included in the
correct directory to enable a simple manpage for the program.
2022-11-10 14:58:16 +01:00
12 changed files with 530 additions and 115 deletions

3
.gitmodules vendored
View file

@ -7,3 +7,6 @@
[submodule "test/test_helper/bats-assert"] [submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git url = https://github.com/bats-core/bats-assert.git
[submodule "test/test_helper/mocks"]
path = test/test_helper/mocks
url = https://github.com/jasonkarns/bats-mock.git

View file

@ -1,5 +1,80 @@
pipeline: steps:
test: test:
image: bats/bats image: bats/bats
commands: commands:
- /opt/bats/bin/bats test - /opt/bats/bin/bats test
release-prep:
# prepare changelog and version information for release candidate
when:
event: tag
ref: refs/tags/v*
image: alpine
commands:
- 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
when:
event: tag
ref: refs/tags/v*
image: alpine
secrets: [ github_release_token, github_repo ]
commands:
- apk add jq curl
- "lastversion=$(curl -X GET -H \"Accept: application/vnd.github.v3+json\" -H \"Authorization: Bearer $GITHUB_RELEASE_TOKEN\" https://api.github.com/repos/$GITHUB_REPO/releases/latest | jq -r '.name')"
- "programversion=$(cat NEWEST_VERSION.txt)"
- changelogversion=$(sed -ne 's/^## \[\([0-9].*\)\].*$/\1/p' CHANGELOG.md | head -n1)
- echo "Last version - $lastversion"
- echo "New version - $programversion"
- echo "Changelog version - $changelogversion"
- "if [ \"$changelogversion\" != \"$programversion\" ]; then { echo \"VERSION MISMATCH: Changelog - $changelogversion, Program - $programversion\" && exit 1; }; fi"
- "if [ \"$lastversion\" = \"$programversion\" ]; then { echo \"RELEASE DUPLICATE: Last release already had version - $programversion\" && exit 1; }; fi"
build:
when:
event: tag
ref: refs/tags/v*
image: savant/md2man
commands:
- apk update && apk add zip
- BM_VERSION=$(cat NEWEST_VERSION.txt)
- mkdir -p build/doc dist
- cp bemoji build
- md2man -in README.md -out bemoji.1 && gzip bemoji.1
- cp LICENSE README.md bemoji.1.gz build/doc
- 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:
when:
event: tag
ref: refs/tags/v*
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_release_token
base_url: https://git.martyoeh.me
files: dist/*
title: NEWEST_VERSION.txt
note: NEWEST_CHANGES.txt
release-github:
when:
event: tag
ref: refs/tags/v*
image: alpine
secrets: [ github_release_token, github_repo ]
commands:
- apk add file jq curl
- BM_VERSION=$(cat NEWEST_VERSION.txt)
- BM_CHANGED=$(sed -e 's|#||g' -e 's|^.*$|\0 <br />|' NEWEST_CHANGES.txt) # display newlines workaround
- 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; }"
- "curl -X POST -H \"Accept:\\ application/vnd.github.v3+json\" -H \"Authorization:\\ Bearer $GITHUB_RELEASE_TOKEN\" -H \"Content-Type:\\ $(file -b --mime-type dist/bemoji-$BM_VERSION.zip)\" -H \"Content-Length:\\ $(wc -c <dist/bemoji-$BM_VERSION.zip | xargs)\" -T dist/bemoji-$BM_VERSION.zip \"$uploadurl?name=bemoji-$BM_VERSION.zip\""
- "curl -X POST -H \"Accept:\\ application/vnd.github.v3+json\" -H \"Authorization:\\ Bearer $GITHUB_RELEASE_TOKEN\" -H \"Content-Type:\\ $(file -b --mime-type dist/bemoji-$BM_VERSION.tar.gz)\" -H \"Content-Length:\\ $(wc -c <dist/bemoji-$BM_VERSION.tar.gz | xargs)\" -T dist/bemoji-$BM_VERSION.tar.gz \"$uploadurl?name=bemoji-$BM_VERSION.tar.gz\""

View file

@ -7,13 +7,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
<!-- ### Added -->
<!-- ### Changed -->
<!-- ### Deprecated -->
<!-- ### Removed -->
<!-- ### Fixed -->
<!-- ### Security -->
## [0.4.0] - 2024-02-22
### Added ### Added
- Add new option `-n` which suppresses printing the final newline character in output - Add default support for `fuzzel` wayland-native picker tool
- 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 ### Changed
- Multiple command options can be combined
- (!) History uses `XDG_STATE_HOME` directory by default: - (!) 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 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 location. To retain your old history file, simply move it from the old cache directory
@ -21,17 +44,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
by default). by default).
- (!) `XDG_CACHE_LOCATION` renamed to `XDG_HISTORY_LOCATION` to better signify its purpose - (!) `XDG_CACHE_LOCATION` renamed to `XDG_HISTORY_LOCATION` to better signify its purpose
<!-- ### Deprecated --> ### Fixed
<!-- ### Removed --> - Always download from newest emoji list url
- Pass selection to custom typing tools through stdin
- Pass info messages to stderr to avoid passing to picker tools
## [0.3.0] - 2022-11-10
### Added
- Add new option `-n` which suppresses printing the final newline character in output
### Changed
- Multiple command options can be combined
- Allow downloading emoji sets at any time after initial run with `-D <choice>`
### Fixed ### Fixed
- Custom default command is only executed when no command option given - Custom default command is only executed when no command option given
- Results are matched case insensitively when using rofi picker to match other pickers - Results are matched case insensitively when using rofi picker to match other pickers
<!-- ### Security -->
## [0.2.0] - 2022-06-29 ## [0.2.0] - 2022-06-29
### Added ### Added

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2022 Marty Oehme Copyright (c) 2021 - 2024 Marty Oehme
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -12,7 +12,7 @@ Will remember your favorite emojis and give you quick access.
### Dependencies ### Dependencies
* One of `bemenu`, `wofi`, `rofi`, `dmenu`, or supplying your own picker. * One of `bemenu`, `wofi`, `rofi`, `dmenu`, `ilia`, `fuzzel` or supplying your own picker.
* One of `wl-copy`, `xclip`, `xsel` or supplying your own clipboard tool. * One of `wl-copy`, `xclip`, `xsel` or supplying your own clipboard tool.
* One of `wtype`, `xdotool` or supplying your own typing tool. * One of `wtype`, `xdotool` or supplying your own typing tool.
* `sed`, `grep`, `cut`, `sort`, `uniq`, `tr`, `curl` if using the download functionality. * `sed`, `grep`, `cut`, `sort`, `uniq`, `tr`, `curl` if using the download functionality.
@ -43,10 +43,10 @@ ln -s bemoji/bemoji /usr/local/bin/bemoji
### Arch Linux ### 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 ```bash
paru -S bemoji-git paru -S bemoji # or bemoji-git
``` ```
## 💿 Usage ## 💿 Usage
@ -78,7 +78,7 @@ bindsym Mod4+Shift+e exec bemoji -t
For `riverwm`, put the following in `~/.config/river/init`: 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`: In `sxhkd`, put the following into `~/.config/sxhkd/sxhkdrc`:
@ -118,35 +118,46 @@ 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 bemoji --hist-limit 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: 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 -Pp bemoji -p -P0
``` ```
Like this, you'll be hiding any recent personal emoji and no one will know that you always type 👄🍆💦. 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 --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,
so kept in single-use lists for example. so kept in single-use lists for example.
If you don't wish those to show up, make use of these options. 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`, By default bemoji stores your recent history in `$XDG_STATE_HOME/bemoji-history.txt`,
so most often in `~/.local/state/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: You can overwrite the directories bemoji uses for its emoji lists and history files with the following two environment variables:
``` ```
@ -161,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,
@ -174,21 +185,27 @@ 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" bemoji -f "https://raw.githubusercontent.com/jchook/emoji-menu/master/data/emojis.txt"
``` ```
### Change the default emoji set ### Download additional emoji sets
bemoji downloads emoji for you to use on first invocation. 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 change this setting, 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 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.
Other valid options for this setting are `emoji`, `math`, `none`. Other valid options for this setting are `emoji`, `math`, `nerd`, `none`.
```bash
bemoji -D "math emoji nerd"
```
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 simply complain and not show anything. bemoji will complain and not show anything.
### Do not skip to new line after output ### Do not skip to new line after output
@ -216,7 +233,15 @@ BEMOJI_CLIP_CMD="path/to/your/clipboard/tool"
BEMOJI_TYPE_CMD="path/to/your/xdotool" BEMOJI_TYPE_CMD="path/to/your/xdotool"
``` ```
This is pretty experimental and you'll have to see how well it works for you. The candidate list (in the case of picker tool) or the picked selection are passed to the tools through stdin.
For example, to manually invoke fuzzel with no extra options as the picker for bemoji you would use:
```bash
BEMOJI_PICKER_CMD="fuzzel -d" bemoji
```
This is somewhat experimental still and you'll have to see how well it works for you.
The setting can not be changed through the commandline alone. The setting can not be changed through the commandline alone.
### Execute a custom command with my emoji ### Execute a custom command with my emoji
@ -226,7 +251,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.
@ -240,16 +265,16 @@ What follows is a list of all environment variables bemoji understands,
with their default settings with their default settings
```bash ```bash
BEMOJI_DB_LOCATION=$XDG_DATA_HOME/bemoji # where the emoji lists reside BEMOJI_DB_LOCATION="$XDG_DATA_HOME/bemoji" # where the emoji lists reside
BEMOJI_HISTORY_LOCATION=$XDG_STATE_HOME # where the state file resides BEMOJI_HISTORY_LOCATION="$XDG_STATE_HOME" # where the state file resides
BEMOJI_CUSTOM_LIST="" # the custom emoji list to display BEMOJI_CUSTOM_LIST="" # the custom emoji list to display
BEMOJI_DOWNLOAD_LIST="" # the default emoji lists to download to database BEMOJI_DOWNLOAD_LIST="" # the default emoji lists to download to database
BEMOJI_DEFAULT_COMMAND=<clip-tool> # which command to invoke by default BEMOJI_DEFAULT_COMMAND="" # which command to invoke by default
BEMOJI_PICKER_CMD=bemenu # which picker tool to use BEMOJI_PICKER_CMD="bemenu" # which picker tool to use
BEMOJI_CLIP_CMD=wl-copy # which clipboard 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_TYPE_CMD="wtype" # which typing tool to use (ydotool will NOT work)
BEMOJI_PRIVATE_MODE=false # whether to save new entries 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 BEMOJI_ECHO_NEWLINE=true # whether to end the output with a newline character
``` ```
@ -265,7 +290,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

242
bemoji
View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
bm_version=0.2.0 bm_version=0.4.0
# Emoji default database location # Emoji default database location
bm_db_location=${BEMOJI_DB_LOCATION:-"${XDG_DATA_HOME:-$HOME/.local/share}/bemoji"} bm_db_location=${BEMOJI_DB_LOCATION:-"${XDG_DATA_HOME:-$HOME/.local/share}/bemoji"}
# Setting custom emoji list file location: # Setting custom emoji list file location:
@ -18,31 +18,40 @@ bm_echo_newline=${BEMOJI_ECHO_NEWLINE:-true}
# Do not save choices # Do not save choices
bm_private_mode=${BEMOJI_PRIVATE_MODE:-false} bm_private_mode=${BEMOJI_PRIVATE_MODE:-false}
# Do not sort results # Do not sort results
bm_ignore_recent=${BEMOJI_IGNORE_RECENT:-false} 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"
["fuzzel"]="fuzzel -d -p 🔍"
)
# 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
echo echo
echo "A simple emoji picker. Runs on bemenu/wofi/rofi/dmenu by default." 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 "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 Do not order emoji by recently used." echo " -P, --hist-limit <number> Limit number of recent emoji to display."
echo " -D <choice> Choose specific default lists to download if none found locally." echo " -D, --download <choice> Choose from default lists to download."
echo " Valid choices: all|none|emoji|math." 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"
} }
version() { version() {
@ -50,22 +59,72 @@ version() {
exit exit
} }
# Get Options msg() {
while getopts ":f:D:tcenpPhv" o; do # Outputs a message to stderr, to be used for info, warning and error messages.
case "${o}" in printf "%s\n" "$1" >&2
f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;; }
t) bm_cmds+=(_typer) ;;
c) bm_cmds+=(_clipper) ;; parse_cli() {
e) bm_cmds+=(cat) ;; while getopts cD:ef:hnpP:tv-: arg "$@"; do
n) bm_echo_newline=false ;; case "$arg" in
D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;; c) bm_cmds+=(_clipper) ;;
p) bm_private_mode=true ;; D) _opt_set_download_list "${OPTARG}" ;;
P) bm_ignore_recent=true ;; e) bm_cmds+=(cat) ;;
h) usage 0 ;; f) _opt_set_custom_list "${OPTARG}" ;;
v) version ;; h) usage 0 ;;
*) usage 1 ;; n) bm_echo_newline=false ;;
esac p) bm_private_mode=true ;;
done 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"
}
prepare_db() { prepare_db() {
# Create list directory # Create list directory
@ -73,34 +132,50 @@ prepare_db() {
mkdir -p "$bm_db_location" mkdir -p "$bm_db_location"
fi fi
if [ -n "$(find "$bm_db_location" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then if [ -n "$BEMOJI_DOWNLOAD_LIST" ]; then
# Populate default lists # Populate default lists
if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'none'; then if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'none'; then
printf "No emoji list found, but set to not download any default lists." msg "Not downloading a default emoji list."
exit 1 return
elif echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'all'; then elif echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'all'; then
dl_default_emoji dl_default_emoji
dl_math_symbols dl_math_symbols
dl_nerd_symbols
return return
else
if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'emoji'; then
dl_default_emoji
fi
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 [ -z "$BEMOJI_DOWNLOAD_LIST" ] || echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'emoji'; then fi
dl_default_emoji if [ -n "$(find "$bm_db_location" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
fi dl_default_emoji
if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'math'; then
dl_math_symbols
fi
fi fi
} }
dl_default_emoji() { dl_default_emoji() {
curl -sSL "https://unicode.org/Public/emoji/14.0/emoji-test.txt" | local emojis
sed -ne 's/^.*; fully-qualified.*# \(\S*\) \S* \(.*$\)/\1 \2/gp' >"$bm_db_location/emojis.txt" emojis=$(curl -sSL "https://unicode.org/Public/emoji/latest/emoji-test.txt")
printf "Downloaded default emoji set." printf "%s" "$emojis" | sed -ne 's/^.*; fully-qualified.*# \(\S*\) \S* \(.*$\)/\1 \2/gp' >"$bm_db_location/emojis.txt"
msg "Downloaded default emoji set."
} }
dl_math_symbols() { dl_math_symbols() {
curl -sSL "https://unicode.org/Public/math/latest/MathClassEx-15.txt" | curl -sSL "https://unicode.org/Public/math/latest/MathClassEx-15.txt" |
grep -ve '^#' | cut -d';' -f3,7 --output-delimiter=' ' >"$bm_db_location/math.txt" grep -ve '^#' | cut -d';' -f3,7 | sed -e 's/;/ /' >"$bm_db_location/math.txt"
printf "Downloaded math symbols set." msg "Downloaded math symbols set."
}
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"
msg "Downloaded nerdfont symbols set."
} }
gather_emojis() { gather_emojis() {
@ -112,25 +187,33 @@ gather_emojis() {
result=$(cat "$bm_db_location"/*.txt) result=$(cat "$bm_db_location"/*.txt)
fi fi
if [ "$bm_ignore_recent" = true ]; then if [ -n "$bm_limit_recent" ] && [ "$bm_limit_recent" -eq 0 ]; then
printf "%s" "$result" printf "%s" "$result"
else return
printf "%s\n%s" "$(get_most_recent)" "$result" | cat -n - | sort -uk2 | sort -n | cut -f2-
fi fi
printf "%s\n%s" "$(get_most_recent "$bm_limit_recent")" "$result" | cat -n - | sort -uk2 | sort -n | cut -f2-
} }
get_most_recent() { get_most_recent() {
limit=${1}
recent_file="$bm_history_file" recent_file="$bm_history_file"
if [ ! -f "$recent_file" ]; then if [ ! -f "$recent_file" ]; then
touch "$recent_file" touch "$recent_file"
fi fi
# TODO improve this messy line # TODO improve this messy line
sed -e '/^$/d' "$recent_file" | local result
result=$(sed -e '/^$/d' "$recent_file" |
sort | sort |
uniq -c | uniq -c |
sort -rn | sort -k1rn |
sed -e 's/^\s*//' | 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() { add_to_recent() {
@ -153,23 +236,26 @@ _clipper() {
elif [ -n "$DISPLAY" ] && command -v xsel >/dev/null 2>&1; then elif [ -n "$DISPLAY" ] && command -v xsel >/dev/null 2>&1; then
xsel -b xsel -b
else else
printf "No suitable clipboard tool found." msg "No suitable clipboard tool found."
exit 1 exit 1
fi fi
} }
# Set default typing uti # Set default typing util
_typer() { _typer() {
totype=$(cat -)
if [ -n "$BEMOJI_TYPE_CMD" ]; then if [ -n "$BEMOJI_TYPE_CMD" ]; then
# shellcheck disable=SC2068 # shellcheck disable=SC2068
${BEMOJI_TYPE_CMD[@]} ${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" wtype -s 30 "$totype"
elif [ -n "$DISPLAY" ] && command -v xdotool >/dev/null 2>&1; then elif [ -n "$DISPLAY" ] && command -v xdotool >/dev/null 2>&1; then
xdotool type --delay 30 "$totype" xdotool type --delay 30 "$totype"
else else
printf "No suitable typing tool found." msg "No suitable typing tool found."
exit 1 exit 1
fi fi
} }
@ -179,20 +265,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 fi
elif command -v wofi >/dev/null 2>&1; then
wofi -p 🔍 -i --show dmenu for tool in "${!default_pickers[@]}"; do
elif command -v rofi >/dev/null 2>&1; then if command -v "$tool" >/dev/null 2>&1; then
rofi -p 🔍 -i -dmenu --kb-custom-1 "Alt+1" --kb-custom-2 "Alt+2" ${default_pickers[$tool]}
elif command -v dmenu >/dev/null 2>&1; then return
dmenu -p 🔍 -i -l 20 fi
else done
printf "No suitable picker tool found."
exit 1 msg "No suitable picker tool found."
fi 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="$?"
@ -201,7 +289,7 @@ result=$(echo "$result" | grep -o '^\S\+' | tr -d '\n')
case "$exit_value" in case "$exit_value" in
1) 1)
exit exit 1
;; ;;
0) 0)
if [ ${#bm_cmds[@]} -eq 0 ]; then if [ ${#bm_cmds[@]} -eq 0 ]; then

View file

@ -54,6 +54,11 @@ setup() {
typing result" 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" { @test "Runs custom default command" {
BEMOJI_DEFAULT_CMD="echo my custom command" run bemoji 3>&- BEMOJI_DEFAULT_CMD="echo my custom command" run bemoji 3>&-
assert_output "my custom command" assert_output "my custom command"
@ -64,6 +69,11 @@ typing result"
assert_output "my clipping" 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" { @test "Prints output with newline by default" {
bats_require_minimum_version 1.5.0 bats_require_minimum_version 1.5.0
BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -e BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -e
@ -75,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
}

48
test/bemoji_download.bats Normal file
View file

@ -0,0 +1,48 @@
#!/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'
load 'test_helper/mocks/stub'
# mock out interactive picker for static emoji return
export BEMOJI_PICKER_CMD="echo heart"
# 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"
}
@test "Runs emoji download on -D emoji option" {
stub curl \
"echo -e '1F605 ; fully-qualified # emoji E0.6 grinning face with sweat\nnot picked up\n1F605 ; fully-qualified # emoji2 E0.6 picked up'"
run bemoji -D emojis 3>&-
outcome=$(cat "$BEMOJI_DB_LOCATION/emojis.txt")
assert_equal "$outcome" "emoji grinning face with sweat
emoji2 picked up"
unstub curl
}
@test "Runs maths download on -D maths option" {
stub curl \
"echo '03A3;A;Σ;Sigma;ISOGRK3;;GREEK CAPITAL LETTER SIGMA'"
run bemoji -D math 3>&-
outcome=$(cat "$BEMOJI_DB_LOCATION/math.txt")
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
}

43
test/bemoji_errors.bats Normal file
View file

@ -0,0 +1,43 @@
#!/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'
# 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"
# these tests require stdout to be separated from stderr
# such run flags were only introduced in recent bats version
bats_require_minimum_version 1.5.0
}
@test "Prints clipper error to stderr" {
BEMOJI_PICKER_CMD="echo hi" run --separate-stderr bemoji 3>&-
assert_output ""
output="$stderr"
assert_output "No suitable clipboard tool found."
}
@test "Prints picker error to stderr" {
run --separate-stderr bemoji 3>&-
assert_output ""
output="$stderr"
assert_output "No suitable picker tool found."
}
@test "Prints typer error to stderr" {
BEMOJI_PICKER_CMD="echo hi" run --separate-stderr bemoji -t 3>&-
assert_output ""
output="$stderr"
assert_output "No suitable typing tool found."
}

57
test/bemoji_history.bats Normal file
View file

@ -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"
}

@ -0,0 +1 @@
Subproject commit 7e0fbf6bc705bd1b09daa2d5ff88962ddbe832f6