Compare commits

..

11 commits

Author SHA1 Message Date
7cec73e2db
📖 Bump version, add to changelog 2022-06-29 12:44:42 +02:00
2a17237a96
🧪 Add tests for XDG base directory adherence
Added simple tests for database and cache locations.

Moved test PATH setup to new file-level function which should slightly
speed up testing and makes more sense conceptually to set the bemoji
executable to be in the path once for all tests.
2022-06-29 12:44:42 +02:00
ce17ae58f1
📖 Add simple Changelog 2022-06-29 12:44:42 +02:00
31550448f0
🦊 Add display for directory config to -v option
Added a quick way to see if directories have been set up correctly. This
also eases testing for future ways of setting directories through
environment variables or options.
2022-06-29 12:44:42 +02:00
0b255413d0
🦊 Simplify grep string for POSIX compatibility 2022-06-29 12:44:41 +02:00
75395d2bbd
🐛 Fix custom command invocation quoting 2022-06-29 12:44:41 +02:00
b9708405fa
📖 Add testing instructions to readme 2022-06-29 12:44:41 +02:00
936f19bca6
🧪 Set up default emoji list for tests
Inject a tiny sample emoji list into each test so no download function
is engaged by default.
Add tests for version display.
2022-06-29 12:37:13 +02:00
ceea79eb3a
🧪 Add simple test framework
Now that the project is finding a little adoption it is really high time
to bring some tests into the code to ensure everything works as it
should.
This first version will only provide a simple test harness from which
tests can slowly be written for other parts of the program.
2022-06-29 12:35:52 +02:00
edd5ebd743
📖 Improve installation documentation
Switched sections for dependencies and installation around and created
better sub-headings.
Added section on installing packaged AUR version, thanks to @firegem for
packaging it!
Fixed some whitespace on line endings.

Closes #6.
2022-06-29 08:49:45 +02:00
f791bf093c
📖 Document version and help options in cli help 2022-06-29 08:20:22 +02:00
10 changed files with 187 additions and 27 deletions

9
.gitmodules vendored Normal file
View file

@ -0,0 +1,9 @@
[submodule "test/bats"]
path = test/bats
url = https://github.com/bats-core/bats-core.git
[submodule "test/test_helper/bats-support"]
path = test/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git

35
CHANGELOG.md Normal file
View file

@ -0,0 +1,35 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
<!-- ### Added -->
<!-- ### Changed -->
<!-- ### Deprecated -->
<!-- ### Removed -->
<!-- ### Fixed -->
<!-- ### Security -->
## [0.2.0] - 2022-06-29
### Added
- Display of configuration options on `-v` toggle
- AUR installation instructions
### Changed
- Simplified grep invocation to adhere more closely to POSIX
### Fixed
- Custom picker, clipper, and typer command invocation quoting

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Marty Oehme
Copyright (c) 2022 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

View file

@ -1,4 +1,4 @@
# bemoji ❤ - Quickly ⛏ your 🌟
# bemoji ❤ - Quickly ⛏ your 🌟
![bemoji picker interface on bemenu](assets/bemenu.png)
@ -8,8 +8,20 @@ Will remember your favorite emojis and give you quick access.
## 📁 Installation
### Dependencies
* One of `bemenu`, `wofi`, `rofi`, `dmenu`, or supplying your own picker.
* One of `wl-copy`, `xclip`, `xsel` or supplying your own clipboard tool.
* One of `wtype`, `xdotool` or supplying your own typing tool.
* `sed`, `grep`, `cut`, `sort`, `uniq`, `tr`, `curl` if using the download functionality.
To see how to substitute the default choices with your own tools,
see Options below.
![rofi picker interface](assets/rofi.png)
### Manual
Option 1. Clone the repository and put the executable somewhere in your path:
```bash
@ -27,16 +39,13 @@ chmod +x bemoji/bemoji
ln -s bemoji/bemoji /usr/local/bin/bemoji
```
Dependencies:
### Arch Linux
* One of `bemenu`, `wofi`, `rofi`, `dmenu`, or supplying your own picker.
* One of `wl-copy`, `xclip`, `xsel` or supplying your own clipboard tool.
* One of `wtype`, `xdotool` or supplying your own typing tool.
* `sed`, `grep`, `cut`, `sort`, `uniq`, `tr`, `curl` if using the download functionality.
To see how to substitute the default choices with your own tools,
see Options below.
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.:
```bash
paru -S bemoji-git
```
## 💿 Usage
@ -232,3 +241,12 @@ Thanks for checking this program out! ❤
If there are any problems, don't hesitate to open an issue.
If you have an idea or improvement, don't hesitate to open a merge request!
### Running tests
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`.
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`

17
bemoji
View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
bm_version=0.1
bm_version=0.2.0
# Emoji default database location
bm_db_location=${BEMOJI_DB_LOCATION:-"${XDG_DATA_HOME:-$HOME/.local/share}/bemoji"}
# Setting custom emoji list file location:
@ -33,12 +33,14 @@ usage() {
echo " -e Only echo out the picked emoji."
echo " -D <choice> Choose specific default lists to download if none found locally."
echo " Valid choices: all|none|emoji|math."
echo " -v Display current program version and directory configuration."
echo " -h Show this help."
echo
exit "$1"
}
version() {
echo "v${bm_version}"
printf "v%s\ndatabase=%s\nhistory=%s\n" "$bm_version" "$bm_db_location" "$bm_history_file"
exit
}
@ -135,7 +137,8 @@ add_to_recent() {
# Set default clipboard util
_clipper() {
if [ -n "$BEMOJI_CLIP_CMD" ]; then
"${BEMOJI_CLIP_CMD[@]}"
# shellcheck disable=SC2068
${BEMOJI_CLIP_CMD[@]}
elif [ -n "$WAYLAND_DISPLAY" ] && command -v wl-copy >/dev/null 2>&1; then
wl-copy
elif [ -n "$DISPLAY" ] && command -v xclip >/dev/null 2>&1; then
@ -152,7 +155,8 @@ _clipper() {
_typer() {
totype=$(cat -)
if [ -n "$BEMOJI_TYPE_CMD" ]; then
"${BEMOJI_TYPE_CMD[@]}"
# shellcheck disable=SC2068
${BEMOJI_TYPE_CMD[@]}
elif [ -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
@ -166,7 +170,8 @@ _typer() {
# Set default picker util
_picker() {
if [ -n "$BEMOJI_PICKER_CMD" ]; then
"${BEMOJI_PICKER_CMD[@]}"
# shellcheck disable=SC2068
${BEMOJI_PICKER_CMD[@]}
elif command -v bemenu >/dev/null 2>&1; then
bemenu -p 🔍 -i -l 20
elif command -v wofi >/dev/null 2>&1; then
@ -194,7 +199,7 @@ _clipResult() {
result=$(gather_emojis | _picker)
exit_value="$?"
[ "$bm_private_mode" = true ] || add_to_recent "$result"
result=$(echo "$result" | grep -oP '^[^\s]+' | tr -d '\n')
result=$(echo "$result" | grep -o '^\S\+' | tr -d '\n')
case "$exit_value" in
1)

1
test/bats Submodule

@ -0,0 +1 @@
Subproject commit 26c9b18983c3ce4cf24c6f6ee942abd8b1c3ee18

86
test/bemoji.bats Normal file
View file

@ -0,0 +1,86 @@
#!/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_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache"
mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_CACHE_LOCATION"
cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt"
}
@test "can run script" {
export BEMOJI_CLIP_CMD="echo clip test only"
# closing FD3 manually to prevent hangs, see
# https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs
run bemoji 3>&-
assert_success
}
@test "can receive custom picker mock output" {
run bemoji -e 3>&-
assert_output "❤️"
}
@test "-v prints correct version number" {
the_version=$(grep 'bm_version=' $(which bemoji))
run bemoji -v
assert_output --partial "v${the_version#bm_version=}"
}
@test "sets XDG directory for db by default" {
unset BEMOJI_DB_LOCATION
export XDG_DATA_HOME="$BATS_TEST_TMPDIR/xdb-db"
run bemoji -v
assert_output --regexp "
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"
run bemoji -v
assert_output --regexp "
history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$"
}
@test "falls back to default db directory if no XDG found" {
unset BEMOJI_DB_LOCATION
run bemoji -v
assert_output --regexp "
database=$HOME/.local/share/bemoji
"
}
@test "falls back to default history location if no XDG found" {
unset BEMOJI_CACHE_LOCATION
run bemoji -v
assert_output --regexp "
history=$HOME/.cache/bemoji-history.txt$"
}
@test "BEMOJI_DB_LOCATION sets correct db directory" {
run bemoji -v
assert_output --regexp "
database=$BATS_TEST_TMPDIR/database
"
}
@test "BEMOJI_CACHE_LOCATION sets correct cache directory" {
run bemoji -v
assert_output --regexp "
history=$BATS_TEST_TMPDIR/cache/bemoji-history.txt$"
}

View file

@ -0,0 +1,4 @@
❤️ red heart
😀 grinning face
😃 grinning face with big eyes
😄 grinning face with smiling eyes

@ -0,0 +1 @@
Subproject commit ffe84ea5dd43b568851549b3e241db150c12929c

@ -0,0 +1 @@
Subproject commit 3c8fadc5097c9acfc96d836dced2bb598e48b009