✨ Add ability to execute multiple command options
Can combine command options (-c, -t, -e) in any way to simultaneously clip, type and/or echo the picked results. Still defaults to clipping, as before. If a custom default command is given with `BEMOJI_DEFAULT_CMD` env var, then invoking bemoji without any command option will invoke this command. Otherwise, the other commands are added to the default given command. Additionally, refactor echo command to mirror other commands Both typing and clipping simply invoke the corresponding program function while echo had an extra role so far. This adjusts the echo command to also work the same way.
This commit is contained in:
parent
28aa2aa522
commit
7e8fc0c51a
2 changed files with 34 additions and 10 deletions
25
bemoji
25
bemoji
|
@ -10,9 +10,6 @@ bm_db_location=${BEMOJI_DB_LOCATION:-"${XDG_DATA_HOME:-$HOME/.local/share}/bemoj
|
||||||
bm_cache_dir="${BEMOJI_CACHE_LOCATION:-${XDG_CACHE_HOME:-$HOME/.cache}}"
|
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
|
|
||||||
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}
|
||||||
# Do not sort results
|
# Do not sort results
|
||||||
|
@ -48,9 +45,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_default_cmd=_typeResult ;;
|
t) bm_default_cmd+=(_typeResult) ;;
|
||||||
c) bm_default_cmd=_clipResult ;;
|
c) bm_default_cmd+=(_clipResult) ;;
|
||||||
e) bm_default_cmd=_echo ;;
|
e) bm_default_cmd+=(_echoResult) ;;
|
||||||
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 ;;
|
||||||
|
@ -195,6 +192,10 @@ _clipResult() {
|
||||||
cat - | _clipper
|
cat - | _clipper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_echoResult() {
|
||||||
|
cat -
|
||||||
|
}
|
||||||
|
|
||||||
[ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db
|
[ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db
|
||||||
result=$(gather_emojis | _picker)
|
result=$(gather_emojis | _picker)
|
||||||
exit_value="$?"
|
exit_value="$?"
|
||||||
|
@ -206,11 +207,17 @@ case "$exit_value" in
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
0)
|
0)
|
||||||
if [ "$bm_default_cmd" = "_echo" ]; then
|
if [ ${#bm_default_cmd[@]} -eq 0 ]; then
|
||||||
echo "$result"
|
if [ -n "$BEMOJI_DEFAULT_CMD" ]; then
|
||||||
|
# shellcheck disable=SC2068
|
||||||
|
echo "$result" | ${BEMOJI_DEFAULT_CMD[@]}
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
echo "$result" | "$bm_default_cmd"
|
bm_default_cmd+=(_clipResult)
|
||||||
|
fi
|
||||||
|
for cmd in "${bm_default_cmd[@]}"; do
|
||||||
|
echo "$result" | "$cmd"
|
||||||
|
done
|
||||||
;;
|
;;
|
||||||
10)
|
10)
|
||||||
echo "$result" | _clipResult
|
echo "$result" | _clipResult
|
||||||
|
|
|
@ -46,3 +46,20 @@ setup() {
|
||||||
BEMOJI_TYPE_CMD="echo typing result" run bemoji -t 3>&-
|
BEMOJI_TYPE_CMD="echo typing result" run bemoji -t 3>&-
|
||||||
assert_output "typing result"
|
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