1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2024-12-22 12:48:01 +00:00

Make shell scripts (almost) POSIX compliant

This commit is contained in:
Daniel Carrillo 2019-11-17 17:29:34 +01:00
parent 9d6bbeae7c
commit 5211d4aacb
6 changed files with 38 additions and 55 deletions

View File

@ -1,10 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
killall -q polybar killall -q polybar
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done while pgrep -u "$(id -u)" -x polybar >/dev/null; do sleep 1; done
export TERMINAL_CMD="tilix --profile orange --new-process -e" export TERMINAL_CMD="tilix --profile orange --new-process -e"
export WM_CONTROL="$(dirname $0)/scripts/switch_window_state" WM_CONTROL="$(dirname "$0")/scripts/switch_window_state"
export WM_CONTROL
for monitor in $(polybar --list-monitors | cut -d":" -f1); do for monitor in $(polybar --list-monitors | cut -d":" -f1); do
export MONITOR=$monitor export MONITOR=$monitor

View File

@ -3,6 +3,6 @@
while true; do while true; do
UPDATES=$(checkupdates 2>/dev/null | wc -l) UPDATES=$(checkupdates 2>/dev/null | wc -l)
[[ $UPDATES -gt 0 ]] && echo " $UPDATES" && sleep 30 [ "$UPDATES" -gt 0 ] && echo " $UPDATES" && sleep 30
[[ $UPDATES -eq 0 ]] && echo "" && sleep 300 [ "$UPDATES" -eq 0 ] && echo "" && sleep 300
done done

View File

@ -3,10 +3,9 @@
OUTPUT="" OUTPUT=""
openvpn=$(pgrep -c openvpn$) openvpn=$(pgrep -c openvpn$)
[[ $openvpn -gt 0 ]] && OUTPUT=$(eval printf "%.0s" {1..$openvpn}) [ "$openvpn" -gt 0 ] && OUTPUT=$(eval printf "%.0s" "{1..$openvpn}")
openfortivpn=$(pgrep -c openfortivpn$) openfortivpn=$(pgrep -c openfortivpn$)
[[ $openfortivpn -gt 0 ]] && OUTPUT=${OUTPUT}$(eval printf '%.0s' {1..$openfortivpn}) [ "$openfortivpn" -gt 0 ] && OUTPUT=${OUTPUT}$(eval printf '%.0s' "{1..$openfortivpn}")
echo $OUTPUT | sed -e 's/\(.\)/\1 /g'
echo "$OUTPUT" | sed -e 's/\(.\)/\1 /g'

View File

@ -1,4 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
@ -18,59 +17,46 @@ ROFI="rofi -dmenu
-width 30 -width 30
" "
function build_rofi_menu() build_rofi_menu()
{ {
local menu
local name
local dtype
local device
local option
while read -r line while read -r line
do do
name="$(cut -d':' -f1 <<< $line)" name="$(echo "$line" | cut -d':' -f1)"
dtype="$(cut -d':' -f2 <<< $line)" dtype="$(echo "$line" | cut -d':' -f2)"
device="$(cut -d':' -f3 <<< $line)" device="$(echo "$line" | cut -d':' -f3)"
[[ -z $device ]] && status= || status= [ -z "$device" ] && status= || status=
dtype=${dtype##*-} dtype=${dtype##*-}
option=$(printf '%-35s | %-15s | %s\n' "$name" $dtype $status) option=$(printf '%-35s | %-15s | %s\n' "$name" "$dtype" $status)
menu="$menu # $option" menu="$menu # $option"
done < <(nmcli -c no --terse -f NAME,TYPE,DEVICE connection show) done < <(nmcli -c no --terse -f NAME,TYPE,DEVICE connection show)
echo "$(cut -c 3- <<< $menu)" echo "$menu" | cut -c 3-
} }
function switch_connections() switch_connections()
{ {
local name="$1" name="$1"
local status=$2 status=$2
if [[ "$status" == "" ]]; then if [ "$status" = "" ]; then
nmcli connection down "$name" nmcli connection down "$name"
else else
nmcli connection up "$name" nmcli connection up "$name"
fi fi
} }
function main() main()
{ {
local menu
local choice
local name
local stat
menu=$(build_rofi_menu) menu=$(build_rofi_menu)
choice=$($ROFI <<< $menu) choice=$(echo "$menu" | $ROFI)
[[ $? -ne 0 ]] && return 1 [ "$?" -ne 0 ] && return 1
name=$(cut -d '|' -f 1 <<< $choice | awk '{$1=$1;print}') name=$(echo "$choice" | cut -d '|' -f 1 | awk '{$1=$1;print}')
stat=$(cut -d '|' -f 3 <<< $choice | awk '{$1=$1;print}') stat=$(echo "$choice" | cut -d '|' -f 3 | awk '{$1=$1;print}')
switch_connections "$name" $stat switch_connections "$name" "$stat"
} }
main main

View File

@ -2,16 +2,16 @@
set -e set -e
[[ -z $1 ]] && exit 1 [ -z "$1" ] && exit 1
active_window=$(xdotool getactivewindow) active_window=$(xdotool getactivewindow)
window=$(xdotool search --name "$1") window=$(xdotool search --name "$1")
[[ $? -ne 0 ]] && exit 1 [ "$?" -ne 0 ] && exit 1
if [[ $active_window == $window ]]; then if [ "$active_window" = "$window" ]; then
xdotool windowminimize $window xdotool windowminimize "$window"
else else
xdotool windowactivate $window xdotool windowactivate "$window"
fi fi
exit 0 exit 0

View File

@ -2,7 +2,7 @@
set -e set -e
function dotfiles() dotfiles()
{ {
echo "[INFO] Installing dot files..." echo "[INFO] Installing dot files..."
@ -17,29 +17,26 @@ function dotfiles()
echo "" echo ""
} }
function dconf_loader() dconf_loader()
{ {
local file if ! command -v dconf > /dev/null 2>&1; then
local dconf_path
if ! which dconf > /dev/null 2>&1; then
echo "[WARNING] dconf command not found" echo "[WARNING] dconf command not found"
echo "" echo ""
return 1 return 1
else else
for file in dconf/*; do for file in dconf/*; do
echo -e "[INFO] Loading $(basename $file) config..." echo "[INFO] Loading $(basename "$file") config..."
dconf_path=$(egrep -m1 '^#.+dconf-path=.+$' $file | cut -f2 -d "=") dconf_path=$(grep -E -m1 '^#.+dconf-path=.+$' "$file" | cut -f2 -d "=")
dconf load $dconf_path < $file dconf load "$dconf_path" < "$file"
done done
fi fi
echo "" echo ""
} }
function main() main()
{ {
cd $(dirname $0) cd "$(dirname "$0")"
dotfiles dotfiles
dconf_loader dconf_loader