Compare commits
2 commits
b97c09828d
...
e14010eb53
Author | SHA1 | Date | |
---|---|---|---|
e14010eb53 | |||
7b5b3e6e46 |
4 changed files with 57 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
pipeline:
|
||||
steps:
|
||||
test:
|
||||
image: bats/bats
|
||||
commands:
|
||||
|
|
|
@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- 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
|
||||
|
||||
<!-- ### Security -->
|
||||
|
||||
|
|
19
bemoji
19
bemoji
|
@ -59,6 +59,11 @@ version() {
|
|||
exit
|
||||
}
|
||||
|
||||
msg() {
|
||||
# Outputs a message to stderr, to be used for info, warning and error messages.
|
||||
printf "%s\n" "$1" >&2
|
||||
}
|
||||
|
||||
parse_cli() {
|
||||
while getopts cD:ef:hnpP:tv-: arg "$@"; do
|
||||
case "$arg" in
|
||||
|
@ -130,7 +135,7 @@ prepare_db() {
|
|||
if [ -n "$BEMOJI_DOWNLOAD_LIST" ]; then
|
||||
# Populate default lists
|
||||
if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'none'; then
|
||||
printf "Not downloading a default emoji list.\n"
|
||||
msg "Not downloading a default emoji list."
|
||||
return
|
||||
elif echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'all'; then
|
||||
dl_default_emoji
|
||||
|
@ -158,19 +163,19 @@ dl_default_emoji() {
|
|||
local emojis
|
||||
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"
|
||||
msg "Downloaded default emoji set."
|
||||
}
|
||||
dl_math_symbols() {
|
||||
curl -sSL "https://unicode.org/Public/math/latest/MathClassEx-15.txt" |
|
||||
grep -ve '^#' | cut -d';' -f3,7 | sed -e 's/;/ /' >"$bm_db_location/math.txt"
|
||||
printf "Downloaded math symbols set.\n"
|
||||
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"
|
||||
printf "Downloaded nerdfont symbols set.\n"
|
||||
msg "Downloaded nerdfont symbols set."
|
||||
}
|
||||
|
||||
gather_emojis() {
|
||||
|
@ -231,7 +236,7 @@ _clipper() {
|
|||
elif [ -n "$DISPLAY" ] && command -v xsel >/dev/null 2>&1; then
|
||||
xsel -b
|
||||
else
|
||||
printf "No suitable clipboard tool found."
|
||||
msg "No suitable clipboard tool found."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -250,7 +255,7 @@ _typer() {
|
|||
elif [ -n "$DISPLAY" ] && command -v xdotool >/dev/null 2>&1; then
|
||||
xdotool type --delay 30 "$totype"
|
||||
else
|
||||
printf "No suitable typing tool found."
|
||||
msg "No suitable typing tool found."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -270,7 +275,7 @@ _picker() {
|
|||
fi
|
||||
done
|
||||
|
||||
printf "No suitable picker tool found." 1>&2
|
||||
msg "No suitable picker tool found."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
43
test/bemoji_errors.bats
Normal file
43
test/bemoji_errors.bats
Normal 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."
|
||||
}
|
Loading…
Reference in a new issue