shell-scripts: Use [[ instead of [ where possible
Replace all occurrences of [ with [[ in bash and zsh scripts and configs. Performance wise it makes sense to use the builtin instead of calling an external command also when from a functionality stand point `test` would suffice.
This commit is contained in:
@@ -24,7 +24,7 @@ if ! pgrep -ax polybar >/dev/null 2>&1; then
|
||||
primary="$(xrandr -q | grep primary | cut -d' ' -f1)"
|
||||
for m in $(polybar --list-monitors | cut -d':' -f1); do
|
||||
export TRAY_POS=none
|
||||
[ "$m" != "$primary" ] || export TRAY_POS=right
|
||||
[[ "$m" != "$primary" ]] || export TRAY_POS=right
|
||||
export MONITOR="$m"
|
||||
polybar --reload -c "$BASE_DIR/config" main &
|
||||
done
|
||||
|
||||
@@ -17,13 +17,13 @@ declare -a ramp
|
||||
ramp=( )
|
||||
|
||||
# display in red when under $low and no charger is connected
|
||||
[ "$bat" -gt "$low" ] || [ "$ac" -eq 1 ] || color="$red"
|
||||
[[ "$bat" -gt "$low" || "$ac" -eq 1 ]] || color="$red"
|
||||
# display in green when over $full and a charger is connected
|
||||
[ "$bat" -lt "$full" ] || [ "$ac" -eq 0 ] || color="$green"
|
||||
[[ "$bat" -lt "$full" || "$ac" -eq 0 ]] || color="$green"
|
||||
|
||||
let "icon_index = $bat / (${#ramp[@]} - 1)"
|
||||
[ $icon_index -lt ${#ramp[@]} ] || icond_index=10
|
||||
[[ $icon_index -lt ${#ramp[@]} ]] || icond_index=10
|
||||
icon="${ramp[$icon_index]}"
|
||||
[ "$ac" -eq 0 ] || charge=""
|
||||
[[ "$ac" -eq 0 ]] || charge=""
|
||||
|
||||
echo "${color}${icon}${charge} ${bat}%"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
bluetooth_print() {
|
||||
bluetoothctl | while read -r; do
|
||||
if [ "$(systemctl is-active "bluetooth.service")" = "active" ]; then
|
||||
if [[ "$(systemctl is-active "bluetooth.service")" = "active" ]]; then
|
||||
|
||||
devices_paired=$(echo paired-devices | bluetoothctl | sed -n '/paired-devices/,$p' | grep Device | cut -d ' ' -f 2)
|
||||
counter=0
|
||||
@@ -14,7 +14,7 @@ bluetooth_print() {
|
||||
if echo "$device_info" | grep -q "Connected: yes"; then
|
||||
device_alias=$(echo "$device_info" | grep "Alias" | cut -d ' ' -f 2-)
|
||||
|
||||
if [ $counter -gt 0 ]; then
|
||||
if [[ $counter -gt 0 ]]; then
|
||||
printf ", %s" "$device_alias"
|
||||
else
|
||||
printf ": %s" "$device_alias"
|
||||
|
||||
Reference in New Issue
Block a user