🦊 Refactor command functions and variable names

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.
This commit is contained in:
Marty Oehme 2022-08-06 11:18:06 +02:00
parent 7e8fc0c51a
commit a776c63748
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
1 changed files with 13 additions and 23 deletions

36
bemoji
View File

@ -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