diff --git a/bemoji b/bemoji index da39218..90ebf57 100755 --- a/bemoji +++ b/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_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 bm_private_mode=${BEMOJI_PRIVATE_MODE:-false} # Do not sort results @@ -48,9 +45,9 @@ version() { while getopts ":f:D:tcepPhv" o; do case "${o}" in f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;; - t) bm_default_cmd=_typeResult ;; - c) bm_default_cmd=_clipResult ;; - e) bm_default_cmd=_echo ;; + t) bm_default_cmd+=(_typeResult) ;; + c) bm_default_cmd+=(_clipResult) ;; + e) bm_default_cmd+=(_echoResult) ;; D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;; p) bm_private_mode=true ;; P) bm_ignore_recent=true ;; @@ -195,6 +192,10 @@ _clipResult() { cat - | _clipper } +_echoResult() { + cat - +} + [ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db result=$(gather_emojis | _picker) exit_value="$?" @@ -206,11 +207,17 @@ case "$exit_value" in exit ;; 0) - if [ "$bm_default_cmd" = "_echo" ]; then - echo "$result" - exit + if [ ${#bm_default_cmd[@]} -eq 0 ]; then + if [ -n "$BEMOJI_DEFAULT_CMD" ]; then + # shellcheck disable=SC2068 + echo "$result" | ${BEMOJI_DEFAULT_CMD[@]} + exit + fi + bm_default_cmd+=(_clipResult) fi - echo "$result" | "$bm_default_cmd" + for cmd in "${bm_default_cmd[@]}"; do + echo "$result" | "$cmd" + done ;; 10) echo "$result" | _clipResult diff --git a/test/bemoji_cmds.bats b/test/bemoji_cmds.bats index ac1c3a4..3f7f681 100644 --- a/test/bemoji_cmds.bats +++ b/test/bemoji_cmds.bats @@ -46,3 +46,20 @@ setup() { 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" +}