From 07455024c72c3aa0bacf8338b82d3a0b8a96a9b0 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 4 Jan 2024 11:23:50 -0300 Subject: re "s|echo \"\\\$|printf '%s\\\n' \"\$|g" Replace all cases where `echo` was given a variable as its first argument, even on cases where we always know what the variable's content look like. --- bin/player | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'bin/player') diff --git a/bin/player b/bin/player index b83e8c0..129942e 100755 --- a/bin/player +++ b/bin/player @@ -83,24 +83,24 @@ CURRENT_PLAYER="$(cat "$CURRENT_PLAYER_PATH" ||:)" AVAILABLE_PLAYERS="$(playerctl --list-all | LANG=POSIX.UTF-8 sort)" pick_first() { - echo "$AVAILABLE_PLAYERS" | head -n1 + printf '%s\n' "$AVAILABLE_PLAYERS" | head -n1 } next_player() { if [ -z "$CURRENT_PLAYER" ]; then pick_first - elif ! echo "$AVAILABLE_PLAYERS" | grep -q "$CURRENT_PLAYER"; then + elif ! printf '%s\n' "$AVAILABLE_PLAYERS" | grep -q "$CURRENT_PLAYER"; then # Unknown $CURRENT_PLAYER, pick anyone pick_first else - INDEX="$(echo "$AVAILABLE_PLAYERS" | grep -n "$CURRENT_PLAYER" | cut -d: -f1)" - LENGTH="$(echo "$AVAILABLE_PLAYERS" | wc -l)" + INDEX="$(printf '%s\n' "$AVAILABLE_PLAYERS" | grep -n "$CURRENT_PLAYER" | cut -d: -f1)" + LENGTH="$(printf '%s\n' "$AVAILABLE_PLAYERS" | wc -l)" if [ "$INDEX" = "$LENGTH" ]; then # Reached the end of the $AVAILABLE_PLAYERS list, wrapping pick_first else # Get the next player instead - echo "$AVAILABLE_PLAYERS" | awk -v idx="$INDEX" 'NR == idx+1 {print}' + printf '%s\n' "$AVAILABLE_PLAYERS" | awk -v idx="$INDEX" 'NR == idx+1 {print}' fi fi } @@ -146,14 +146,14 @@ case "$ACTION" in ;; rotate) PLAYER="$(next_player)" - echo "$PLAYER" > "$CURRENT_PLAYER_PATH" + printf '%s\n' "$PLAYER" > "$CURRENT_PLAYER_PATH" notify-send -t 1000 -- \ "$(printf '%s' "$PLAYER" | format_player_name)" \ 'current MPRIS target' ;; synopsis) printf '%s: %s\n' \ - "$(echo "$CURRENT_PLAYER" | format_player_name)" \ + "$(printf '%s\n' "$CURRENT_PLAYER" | format_player_name)" \ "$(formatted_player_title)" ;; *) -- cgit v1.2.3