Compare commits
2 commits
dc68887091
...
4209b90669
Author | SHA1 | Date | |
---|---|---|---|
4209b90669 | |||
7f5c3772e2 |
6 changed files with 92 additions and 28 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -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
|
||||||
|
|
21
CHANGELOG.md
21
CHANGELOG.md
|
@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
<!-- ### Added -->
|
||||||
|
|
||||||
|
<!-- ### Changed -->
|
||||||
|
|
||||||
|
<!-- ### Deprecated -->
|
||||||
|
|
||||||
|
<!-- ### Removed -->
|
||||||
|
|
||||||
|
<!-- ### Fixed -->
|
||||||
|
|
||||||
|
<!-- ### Security -->
|
||||||
|
|
||||||
|
## [0.3.0] - 2022-11-10
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Add new option `-n` which suppresses printing the final newline character in output
|
- Add new option `-n` which suppresses printing the final newline character in output
|
||||||
|
@ -14,18 +28,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Multiple command options can be combined
|
- Multiple command options can be combined
|
||||||
|
- Allow downloading emoji sets at any time after initial run with `-D <choice>`
|
||||||
<!-- ### Deprecated -->
|
|
||||||
|
|
||||||
<!-- ### Removed -->
|
|
||||||
|
|
||||||
### 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
|
||||||
|
|
14
README.md
14
README.md
|
@ -174,11 +174,11 @@ 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 set
|
||||||
|
|
||||||
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 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 -D all
|
||||||
|
@ -187,8 +187,14 @@ 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.
|
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`.
|
Other valid options for this setting are `emoji`, `math`, `none`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bemoji -D "math emoji"
|
||||||
|
```
|
||||||
|
|
||||||
|
The above command is equivalent 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
|
||||||
|
|
||||||
|
|
33
bemoji
33
bemoji
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
bm_version=0.2.0
|
bm_version=0.3.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:
|
||||||
|
@ -36,8 +36,8 @@ usage() {
|
||||||
echo " -n Do not print a newline after the picked emoji."
|
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 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 " -D <choice> Choose specific default lists to download if none found locally."
|
echo " -D <choice> Choose from default lists to download."
|
||||||
echo " Valid choices: all|none|emoji|math."
|
echo " Valid choices: all|none|emoji|math (multiple choices possible)."
|
||||||
echo " -f <filepath> Use a custom emoji database. Can be a url which will be retrieved."
|
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."
|
||||||
|
@ -57,7 +57,7 @@ while getopts ":f:D:tcenpPhv" o; do
|
||||||
t) bm_cmds+=(_typer) ;;
|
t) bm_cmds+=(_typer) ;;
|
||||||
c) bm_cmds+=(_clipper) ;;
|
c) bm_cmds+=(_clipper) ;;
|
||||||
e) bm_cmds+=(cat) ;;
|
e) bm_cmds+=(cat) ;;
|
||||||
n) bm_echo_newline=false;;
|
n) bm_echo_newline=false ;;
|
||||||
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 ;;
|
||||||
|
@ -73,34 +73,39 @@ 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."
|
printf "Not downloading a default emoji list.\n"
|
||||||
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
|
||||||
return
|
return
|
||||||
fi
|
else
|
||||||
if [ -z "$BEMOJI_DOWNLOAD_LIST" ] || echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'emoji'; then
|
if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'emoji'; then
|
||||||
dl_default_emoji
|
dl_default_emoji
|
||||||
fi
|
fi
|
||||||
if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'math'; then
|
if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'math'; then
|
||||||
dl_math_symbols
|
dl_math_symbols
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
if [ -n "$(find "$bm_db_location" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
|
||||||
|
dl_default_emoji
|
||||||
|
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/14.0/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"
|
||||||
|
printf "Downloaded default emoji set.\n"
|
||||||
}
|
}
|
||||||
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."
|
printf "Downloaded math symbols set.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
gather_emojis() {
|
gather_emojis() {
|
||||||
|
|
40
test/bemoji_download.bats
Normal file
40
test/bemoji_download.bats
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/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
|
||||||
|
}
|
1
test/test_helper/mocks
Submodule
1
test/test_helper/mocks
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 7e0fbf6bc705bd1b09daa2d5ff88962ddbe832f6
|
Loading…
Reference in a new issue