From a776c6374873ebe9f1e351a21f6c4d53f69107d4 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 6 Aug 2022 11:18:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=8A=20Refactor=20command=20functions?= =?UTF-8?q?=20and=20variable=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed redundant 'redirection' functions which did nothing to change code and only extended the pipe with an additional `cat` call. Renamed bm_default_cmd to bm_cmds to reflect its nature as an array. Since there is not just one command contained in the variable anymore, it makes much more sense to now call it bm_cmds, note the plural. --- bemoji | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/bemoji b/bemoji index 90ebf57..431ba41 100755 --- a/bemoji +++ b/bemoji @@ -10,6 +10,9 @@ 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" + # Do not save choices bm_private_mode=${BEMOJI_PRIVATE_MODE:-false} # Do not sort results @@ -45,9 +48,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+=(_echoResult) ;; + t) bm_cmds+=(_typer) ;; + c) bm_cmds+=(_clipper) ;; + e) bm_cmds+=(cat) ;; D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;; p) bm_private_mode=true ;; P) bm_ignore_recent=true ;; @@ -183,19 +186,6 @@ _picker() { fi } -# Type result using xdotool -_typeResult() { - cat - | _typer -} - -_clipResult() { - cat - | _clipper -} - -_echoResult() { - cat - -} - [ -n "$BEMOJI_CUSTOM_LIST" ] || prepare_db result=$(gather_emojis | _picker) exit_value="$?" @@ -207,23 +197,23 @@ case "$exit_value" in exit ;; 0) - if [ ${#bm_default_cmd[@]} -eq 0 ]; then - if [ -n "$BEMOJI_DEFAULT_CMD" ]; then + if [ ${#bm_cmds[@]} -eq 0 ]; then + if [ -n "$bm_default_cmd" ]; then # shellcheck disable=SC2068 - echo "$result" | ${BEMOJI_DEFAULT_CMD[@]} + echo "$result" | ${bm_default_cmd[@]} exit fi - bm_default_cmd+=(_clipResult) + bm_cmds+=(_clipper) fi - for cmd in "${bm_default_cmd[@]}"; do + for cmd in "${bm_cmds[@]}"; do echo "$result" | "$cmd" done ;; 10) - echo "$result" | _clipResult + echo "$result" | _clipper ;; 11) - echo "$result" | _typeResult + echo "$result" | _typer ;; esac exit