Compare commits
No commits in common. "05f0e71b9f78cefb9e8701fcdb5bb70fb07bf033" and "7cec73e2dbdc7702d67116cc729f48f9248ceba0" have entirely different histories.
05f0e71b9f
...
7cec73e2db
4 changed files with 35 additions and 92 deletions
|
@ -9,17 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
<!-- ### Added -->
|
<!-- ### Added -->
|
||||||
|
|
||||||
### Changed
|
<!-- ### Changed -->
|
||||||
|
|
||||||
- Multiple command options can be combined
|
|
||||||
|
|
||||||
<!-- ### Deprecated -->
|
<!-- ### Deprecated -->
|
||||||
|
|
||||||
<!-- ### Removed -->
|
<!-- ### Removed -->
|
||||||
|
|
||||||
### Fixed
|
<!-- ### Fixed -->
|
||||||
|
|
||||||
- Custom default command is only executed when no command option given
|
|
||||||
|
|
||||||
<!-- ### Security -->
|
<!-- ### Security -->
|
||||||
|
|
||||||
|
|
40
bemoji
40
bemoji
|
@ -11,7 +11,7 @@ bm_cache_dir="${BEMOJI_CACHE_LOCATION:-${XDG_CACHE_HOME:-$HOME/.cache}}"
|
||||||
bm_history_file="${bm_cache_dir}/bemoji-history.txt"
|
bm_history_file="${bm_cache_dir}/bemoji-history.txt"
|
||||||
|
|
||||||
# Command to run after user chooses an emoji
|
# Command to run after user chooses an emoji
|
||||||
bm_default_cmd="$BEMOJI_DEFAULT_CMD"
|
bm_default_cmd=${BEMOJI_DEFAULT_CMD:-'_clipResult'}
|
||||||
|
|
||||||
# Do not save choices
|
# Do not save choices
|
||||||
bm_private_mode=${BEMOJI_PRIVATE_MODE:-false}
|
bm_private_mode=${BEMOJI_PRIVATE_MODE:-false}
|
||||||
|
@ -25,17 +25,14 @@ usage() {
|
||||||
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 " -f <filepath> Use a custom emoji database. Can be a url which will be retrieved."
|
||||||
echo " -t Simulate typing the emoji choice with the keyboard."
|
echo " -t Simulate typing the emoji choice with the keyboard."
|
||||||
echo " -c Send emoji choice to the clipboard. (default)"
|
echo " -c Send emoji choice to the clipboard. (default)"
|
||||||
echo " -e Only echo out the picked emoji."
|
|
||||||
echo ""
|
|
||||||
echo " Other options:"
|
|
||||||
echo " -p Do not save picked emoji to recent history."
|
echo " -p Do not save picked emoji to recent history."
|
||||||
echo " -P Do not order emoji by recently used."
|
echo " -P Do not order emoji by recently used."
|
||||||
|
echo " -e Only echo out the picked emoji."
|
||||||
echo " -D <choice> Choose specific default lists to download if none found locally."
|
echo " -D <choice> Choose specific default lists to download if none found locally."
|
||||||
echo " Valid choices: all|none|emoji|math."
|
echo " Valid choices: all|none|emoji|math."
|
||||||
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 " -v Display current program version and directory configuration."
|
||||||
echo " -h Show this help."
|
echo " -h Show this help."
|
||||||
echo
|
echo
|
||||||
|
@ -51,9 +48,9 @@ version() {
|
||||||
while getopts ":f:D:tcepPhv" o; do
|
while getopts ":f:D:tcepPhv" o; do
|
||||||
case "${o}" in
|
case "${o}" in
|
||||||
f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;;
|
f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;;
|
||||||
t) bm_cmds+=(_typer) ;;
|
t) bm_default_cmd=_typeResult ;;
|
||||||
c) bm_cmds+=(_clipper) ;;
|
c) bm_default_cmd=_clipResult ;;
|
||||||
e) bm_cmds+=(cat) ;;
|
e) bm_default_cmd=_echo ;;
|
||||||
D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;;
|
D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;;
|
||||||
p) bm_private_mode=true ;;
|
p) bm_private_mode=true ;;
|
||||||
P) bm_ignore_recent=true ;;
|
P) bm_ignore_recent=true ;;
|
||||||
|
@ -189,6 +186,15 @@ _picker() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Type result using xdotool
|
||||||
|
_typeResult() {
|
||||||
|
cat - | _typer
|
||||||
|
}
|
||||||
|
|
||||||
|
_clipResult() {
|
||||||
|
cat - | _clipper
|
||||||
|
}
|
||||||
|
|
||||||
[ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db
|
[ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db
|
||||||
result=$(gather_emojis | _picker)
|
result=$(gather_emojis | _picker)
|
||||||
exit_value="$?"
|
exit_value="$?"
|
||||||
|
@ -200,23 +206,17 @@ case "$exit_value" in
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
0)
|
0)
|
||||||
if [ ${#bm_cmds[@]} -eq 0 ]; then
|
if [ "$bm_default_cmd" = "_echo" ]; then
|
||||||
if [ -n "$bm_default_cmd" ]; then
|
echo "$result"
|
||||||
# shellcheck disable=SC2068
|
|
||||||
echo "$result" | ${bm_default_cmd[@]}
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
bm_cmds+=(_clipper)
|
echo "$result" | "$bm_default_cmd"
|
||||||
fi
|
|
||||||
for cmd in "${bm_cmds[@]}"; do
|
|
||||||
echo "$result" | "$cmd"
|
|
||||||
done
|
|
||||||
;;
|
;;
|
||||||
10)
|
10)
|
||||||
echo "$result" | _clipper
|
echo "$result" | _clipResult
|
||||||
;;
|
;;
|
||||||
11)
|
11)
|
||||||
echo "$result" | _typer
|
echo "$result" | _typeResult
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit
|
exit
|
||||||
|
|
|
@ -28,6 +28,18 @@ setup() {
|
||||||
assert_success
|
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" {
|
@test "sets XDG directory for db by default" {
|
||||||
unset BEMOJI_DB_LOCATION
|
unset BEMOJI_DB_LOCATION
|
||||||
export XDG_DATA_HOME="$BATS_TEST_TMPDIR/xdb-db"
|
export XDG_DATA_HOME="$BATS_TEST_TMPDIR/xdb-db"
|
|
@ -1,65 +0,0 @@
|
||||||
#!/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 "-v prints correct version number" {
|
|
||||||
the_version=$(grep 'bm_version=' "$(which bemoji)")
|
|
||||||
|
|
||||||
run bemoji -v
|
|
||||||
assert_output --partial "v${the_version#bm_version=}"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Runs clipping command by default" {
|
|
||||||
BEMOJI_CLIP_CMD="echo clipping default" run bemoji 3>&-
|
|
||||||
assert_output "clipping default"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Runs echo command on -e option" {
|
|
||||||
run bemoji -e 3>&-
|
|
||||||
assert_output "❤️"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Runs clipping command on -c option" {
|
|
||||||
BEMOJI_CLIP_CMD="echo clipping result" run bemoji -c 3>&-
|
|
||||||
assert_output "clipping result"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Runs typing command on -t option" {
|
|
||||||
BEMOJI_TYPE_CMD="echo typing result" run bemoji -t 3>&-
|
|
||||||
assert_output "typing result"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Runs typing and clipping on -ct options" {
|
|
||||||
BEMOJI_CLIP_CMD="echo clipping result" BEMOJI_TYPE_CMD="echo typing result" run bemoji -ct 3>&-
|
|
||||||
assert_output \
|
|
||||||
"clipping result
|
|
||||||
typing result"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Runs custom default command" {
|
|
||||||
BEMOJI_DEFAULT_CMD="echo my custom command" run bemoji 3>&-
|
|
||||||
assert_output "my custom command"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Using command option overrides custom default command" {
|
|
||||||
BEMOJI_DEFAULT_CMD="echo my custom command" BEMOJI_CLIP_CMD="echo my clipping" run bemoji -c 3>&-
|
|
||||||
assert_output "my clipping"
|
|
||||||
}
|
|
Loading…
Reference in a new issue