Compare commits
3 commits
6c037a5771
...
74af60c3f7
Author | SHA1 | Date | |
---|---|---|---|
|
74af60c3f7 | ||
011fcdefdd | |||
d44cbf5b74 |
5 changed files with 152 additions and 60 deletions
|
@ -9,11 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Added
|
||||
|
||||
- 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
|
||||
|
||||
|
|
26
README.md
26
README.md
|
@ -118,7 +118,7 @@ By default, bemoji will sort the list it displays by your most frequently and mo
|
|||
To disable this behavior, execute bemoji like the following:
|
||||
|
||||
```bash
|
||||
bemoji -P 0
|
||||
bemoji --hist-limit 0
|
||||
```
|
||||
|
||||
This will stop bemoji from adding recently used emoji before displaying the list.
|
||||
|
@ -126,11 +126,12 @@ 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:
|
||||
|
||||
```bash
|
||||
bemoji -p
|
||||
bemoji --private
|
||||
```
|
||||
|
||||
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
|
||||
bemoji -p -P0
|
||||
|
@ -142,7 +143,7 @@ To limit the number of your recently used emoji that are shown without hiding th
|
|||
For example, to display only the top 4 recently used emoji:
|
||||
|
||||
```bash
|
||||
bemoji -P 4
|
||||
bemoji --hist-limit 4
|
||||
```
|
||||
|
||||
The recent list will also contain emoji that are *not* usually on your lists,
|
||||
|
@ -171,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.
|
||||
|
||||
```bash
|
||||
bemoji -f path/to/my/list.txt
|
||||
bemoji --file path/to/my/list.txt
|
||||
```
|
||||
|
||||
The list will override the normally presented emoji,
|
||||
|
@ -191,7 +192,7 @@ By default, it only downloads emoji, though you can have it download math symbol
|
|||
To download additional sets, execute bemoji like the following:
|
||||
|
||||
```bash
|
||||
bemoji -D all
|
||||
bemoji --download all
|
||||
```
|
||||
|
||||
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.
|
||||
|
@ -201,7 +202,7 @@ Other valid options for this setting are `emoji`, `math`, `nerd`, `none`.
|
|||
bemoji -D "math emoji nerd"
|
||||
```
|
||||
|
||||
The above command is equivalent to `all` as you can mention multiple sets you want downloaded.
|
||||
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,
|
||||
bemoji will complain and not show anything.
|
||||
|
@ -244,7 +245,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:
|
||||
|
||||
```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.
|
||||
|
@ -283,7 +284,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.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
|
BIN
assets/help.png
BIN
assets/help.png
Binary file not shown.
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 241 KiB |
121
bemoji
121
bemoji
|
@ -20,6 +20,14 @@ bm_private_mode=${BEMOJI_PRIVATE_MODE:-false}
|
|||
# Do not sort results
|
||||
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"
|
||||
)
|
||||
|
||||
# Report usage
|
||||
usage() {
|
||||
echo "Usage: $(basename "$0") [-t | -c | -e] [-f <filepath> ] [-p] [-P] [-D <choices>]" 1>&2
|
||||
|
@ -28,19 +36,19 @@ usage() {
|
|||
echo "Invoked without arguments sends the picked emoji to the clipboard."
|
||||
echo
|
||||
echo " Command options (can be combined):"
|
||||
echo " -t Simulate typing the emoji choice with the keyboard."
|
||||
echo " -c Send emoji choice to the clipboard. (default)"
|
||||
echo " -e Only echo out the picked emoji."
|
||||
echo " -t, --type Simulate typing the emoji choice with the keyboard."
|
||||
echo " -c, --clip Send emoji choice to the clipboard. (default)"
|
||||
echo " -e, --echo Only echo out the picked emoji."
|
||||
echo ""
|
||||
echo " Other options:"
|
||||
echo " -n Do not print a newline after the picked emoji."
|
||||
echo " -p Do not save picked emoji to recent history."
|
||||
echo " -P <number> Limit number of recent emoji to display."
|
||||
echo " -D <choice> Choose from default lists to download."
|
||||
echo " -n, --noline Do not print a newline after the picked emoji."
|
||||
echo " -p, --private Do not save picked emoji to recent history."
|
||||
echo " -P, --hist-limit <number> Limit number of recent emoji to display."
|
||||
echo " -D, --download <choice> Choose from default lists to download."
|
||||
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 " -v Display current program version and directory configuration."
|
||||
echo " -h Show this help."
|
||||
echo " -f, --file <filepath> Use a custom emoji database. Can be a url which will be retrieved."
|
||||
echo " -v, --version Display current program version and directory configuration."
|
||||
echo " -h, --help Show this help."
|
||||
echo
|
||||
exit "$1"
|
||||
}
|
||||
|
@ -50,22 +58,67 @@ version() {
|
|||
exit
|
||||
}
|
||||
|
||||
# Get Options
|
||||
while getopts ":f:D:tcenpP:hv" o; do
|
||||
case "${o}" in
|
||||
f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;;
|
||||
t) bm_cmds+=(_typer) ;;
|
||||
parse_cli() {
|
||||
while getopts cD:ef:hnpP:tv-: arg "$@"; do
|
||||
case "$arg" in
|
||||
c) bm_cmds+=(_clipper) ;;
|
||||
D) _opt_set_download_list "${OPTARG}" ;;
|
||||
e) bm_cmds+=(cat) ;;
|
||||
n) bm_echo_newline=false ;;
|
||||
D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;;
|
||||
p) bm_private_mode=true ;;
|
||||
P) bm_limit_recent="${OPTARG}" ;;
|
||||
f) _opt_set_custom_list "${OPTARG}" ;;
|
||||
h) usage 0 ;;
|
||||
n) bm_echo_newline=false ;;
|
||||
p) bm_private_mode=true ;;
|
||||
P) _opt_set_hist_limit "${OPTARG}" ;;
|
||||
t) bm_cmds+=(_typer) ;;
|
||||
v) version ;;
|
||||
*) usage 1 ;;
|
||||
-)
|
||||
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
|
||||
done
|
||||
;;
|
||||
\?) 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() {
|
||||
# Create list directory
|
||||
|
@ -182,7 +235,7 @@ _clipper() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Set default typing uti
|
||||
# Set default typing util
|
||||
_typer() {
|
||||
if [ -n "$BEMOJI_TYPE_CMD" ]; then
|
||||
# shellcheck disable=SC2068
|
||||
|
@ -206,20 +259,22 @@ _picker() {
|
|||
if [ -n "$BEMOJI_PICKER_CMD" ]; then
|
||||
# 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
|
||||
wofi -p 🔍 -i --show dmenu
|
||||
elif command -v rofi >/dev/null 2>&1; then
|
||||
rofi -p 🔍 -i -dmenu --kb-custom-1 "Alt+1" --kb-custom-2 "Alt+2"
|
||||
elif command -v dmenu >/dev/null 2>&1; then
|
||||
dmenu -p 🔍 -i -l 20
|
||||
else
|
||||
printf "No suitable picker tool found."
|
||||
exit 1
|
||||
return
|
||||
fi
|
||||
|
||||
for tool in "${!default_pickers[@]}"; do
|
||||
if command -v "$tool" >/dev/null 2>&1; then
|
||||
${default_pickers[$tool]}
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
printf "No suitable picker tool found." 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
parse_cli "$@"
|
||||
|
||||
[ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db
|
||||
result=$(gather_emojis | _picker)
|
||||
exit_value="$?"
|
||||
|
|
|
@ -85,3 +85,29 @@ typing result"
|
|||
BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -ne
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue