From c032ffd1a28da0060e738fc98d7fbcc2a020ce19 Mon Sep 17 00:00:00 2001 From: winston Date: Sat, 30 Jul 2022 22:17:25 +0200 Subject: [PATCH] fix: lint custom executables against shellcheck --- dot_local/bin/executable_fix_xcursor | 34 ++++++++++++------------- dot_local/bin/executable_mailcount | 7 +++-- dot_local/bin/executable_mullvad-status | 6 ++--- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/dot_local/bin/executable_fix_xcursor b/dot_local/bin/executable_fix_xcursor index cd4d60f..35674be 100644 --- a/dot_local/bin/executable_fix_xcursor +++ b/dot_local/bin/executable_fix_xcursor @@ -1,6 +1,4 @@ -#! /bin/bash -# -# /usr/bin/setcursor +#! /usr/bin/env bash # config files gtk2=$HOME/.gtkrc-2.0 @@ -11,39 +9,39 @@ gtk3=$HOME/.config/gtk-3.0/settings.ini default=share/icons/default/index.theme glob_default=/usr/$default user_default=$HOME/.local/$default -[[ -e $glob_default ]] && [[ ! -e $user_default ]] && install -D $glob_default $user_default +[[ -e $glob_default ]] && [[ ! -e $user_default ]] && install -D $glob_default "$user_default" # cursor-theme entries -cursor_gtk2=$(grep "cursor-theme-name" $gtk2 | cut -d'"' -f2) -cursor_gtk3=$(grep "cursor-theme-name" $gtk3 | cut -d'=' -f2) -cursor_xr=$(grep "Xcursor.theme" $xr | cut -d' ' -f2) +cursor_gtk2=$(grep "cursor-theme-name" "$gtk2" | cut -d'"' -f2) +cursor_gtk3=$(grep "cursor-theme-name" "$gtk3" | cut -d'=' -f2) +cursor_xr=$(grep "Xcursor.theme" "$xr" | cut -d' ' -f2) cursor=$1 # find config last modified -if [ -z $1 ]; then +if [ -z "$1" ]; then cursor=$cursor_gtk2; newest=$gtk2 - [[ $xr -nt $gtk2 ]] && [[ ! -z $cursor_xr ]] && cursor=$cursor_xr && newest=$xr - [[ $gtk3 -nt $newest ]] && [[ ! -z $cursor_gtk3 ]] && cursor=$cursor_gtk3 + [[ $xr -nt $gtk2 ]] && [[ -n $cursor_xr ]] && cursor=$cursor_xr && newest=$xr + [[ $gtk3 -nt $newest ]] && [[ -n $cursor_gtk3 ]] && cursor=$cursor_gtk3 fi # Strip any quotes from cursor string -cursor=$(echo $cursor | sed -e 's/"//g') +cursor=${cursor/\"/} # set theme in all config files echo "setting cursortheme \"$cursor\"" [[ "$cursor" != "$cursor_xr" ]] && \ - sed -i "s/Xcursor.theme:.*/Xcursor.theme: $cursor/g" $xr &>/dev/null && \ - xrdb -merge -I$HOME ~/.Xresources + sed -i "s/Xcursor.theme:.*/Xcursor.theme: $cursor/g" "$xr" &>/dev/null && \ + xrdb -merge -I"$HOME" ~/.Xresources [[ "$cursor" != "$cursor_gtk2" ]] && \ - sed -i "s/cursor-theme-name=\".*\"/cursor-theme-name=\"$cursor\"/" $gtk2 + sed -i "s/cursor-theme-name=\".*\"/cursor-theme-name=\"$cursor\"/" "$gtk2" [[ "$cursor" != "$cursor_gtk3" ]] && \ - sed -i "s/cursor-theme-name=.*/cursor-theme-name=$cursor/" $gtk3 &>/dev/null -[[ -e $user_default ]] && sed -i "s/Inherits=.*/Inherits=$cursor/" $user_default &>/dev/null + sed -i "s/cursor-theme-name=.*/cursor-theme-name=$cursor/" "$gtk3" &>/dev/null +[[ -e $user_default ]] && sed -i "s/Inherits=.*/Inherits=$cursor/" "$user_default" &>/dev/null # and in the realms of the GNOMEs -[[ -f /usr/bin/gconftool-2 ]] && gconftool-2 --type string -s /desktop/gnome/peripherals/mouse/cursor $cursor -[[ -f /usr/bin/gsettings ]] && gsettings set org.gnome.desktop.interface cursor-theme $cursor +[[ -f /usr/bin/gconftool-2 ]] && gconftool-2 --type string -s /desktop/gnome/peripherals/mouse/cursor "$cursor" +[[ -f /usr/bin/gsettings ]] && gsettings set org.gnome.desktop.interface cursor-theme "$cursor" exit diff --git a/dot_local/bin/executable_mailcount b/dot_local/bin/executable_mailcount index 9c285d6..065ef00 100644 --- a/dot_local/bin/executable_mailcount +++ b/dot_local/bin/executable_mailcount @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash UNREAD_ONLY=true MAIL_DIR=~/.local/share/mail @@ -6,12 +6,12 @@ MAIL_DIR=~/.local/share/mail mailcount=0 if [[ -d ${MAIL_DIR} ]]; then - for dir in ${MAIL_DIR}/*/; do + for dir in "${MAIL_DIR}"/*/; do # get file count for the unread mailbox, add to count mailcount=$(( $( ls ${dir}INBOX/new | wc -l ) + $mailcount )) # also add the rest of the inbox if var is set - if !($UNREAD_ONLY); then + if ! ($UNREAD_ONLY); then mailcount=$(( $( ls ${dir}INBOX/cur | wc -l ) + $mailcount )) fi @@ -19,4 +19,3 @@ if [[ -d ${MAIL_DIR} ]]; then fi echo ${mailcount} - diff --git a/dot_local/bin/executable_mullvad-status b/dot_local/bin/executable_mullvad-status index e74fe31..95e9ad2 100644 --- a/dot_local/bin/executable_mullvad-status +++ b/dot_local/bin/executable_mullvad-status @@ -1,14 +1,14 @@ #!/usr/bin/env bash -while read LINE; do +while read -r LINE; do if echo "$LINE" | grep -q 'Connected'; then # get the relay (3rd word) | drop the wireguard/openvpn suffix | make it uppercase # just replace this with whatever style you like - OUTPUT=$(echo $LINE | cut -d " " -f 3 | cut -d "-" -f 1 | tr '/a-z/' '/A-Z/') + OUTPUT=$(echo "$LINE" | cut -d " " -f 3 | cut -d "-" -f 1 | tr '/a-z/' '/A-Z/') ICON=" " else ICON=" " fi - echo $ICON $OUTPUT + echo "$ICON" "$OUTPUT" done < <(mullvad status listen)