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:
parent
9d6bbeae7c
commit
5211d4aacb
@ -1,10 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
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 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
|
||||
export MONITOR=$monitor
|
||||
|
@ -3,6 +3,6 @@
|
||||
while true; do
|
||||
UPDATES=$(checkupdates 2>/dev/null | wc -l)
|
||||
|
||||
[[ $UPDATES -gt 0 ]] && echo " $UPDATES" && sleep 30
|
||||
[[ $UPDATES -eq 0 ]] && echo "" && sleep 300
|
||||
[ "$UPDATES" -gt 0 ] && echo " $UPDATES" && sleep 30
|
||||
[ "$UPDATES" -eq 0 ] && echo "" && sleep 300
|
||||
done
|
||||
|
@ -3,10 +3,9 @@
|
||||
OUTPUT=""
|
||||
|
||||
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 -gt 0 ]] && OUTPUT=${OUTPUT}$(eval printf '%.0s' {1..$openfortivpn})
|
||||
|
||||
echo $OUTPUT | sed -e 's/\(.\)/\1 /g'
|
||||
[ "$openfortivpn" -gt 0 ] && OUTPUT=${OUTPUT}$(eval printf '%.0s' "{1..$openfortivpn}")
|
||||
|
||||
echo "$OUTPUT" | sed -e 's/\(.\)/\1 /g'
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
@ -18,59 +17,46 @@ ROFI="rofi -dmenu
|
||||
-width 30
|
||||
"
|
||||
|
||||
function build_rofi_menu()
|
||||
build_rofi_menu()
|
||||
{
|
||||
local menu
|
||||
local name
|
||||
local dtype
|
||||
local device
|
||||
local option
|
||||
|
||||
while read -r line
|
||||
do
|
||||
name="$(cut -d':' -f1 <<< $line)"
|
||||
dtype="$(cut -d':' -f2 <<< $line)"
|
||||
device="$(cut -d':' -f3 <<< $line)"
|
||||
name="$(echo "$line" | cut -d':' -f1)"
|
||||
dtype="$(echo "$line" | cut -d':' -f2)"
|
||||
device="$(echo "$line" | cut -d':' -f3)"
|
||||
|
||||
[[ -z $device ]] && status= || status=
|
||||
[ -z "$device" ] && status= || status=
|
||||
dtype=${dtype##*-}
|
||||
option=$(printf '%-35s | %-15s | %s\n' "$name" $dtype $status)
|
||||
option=$(printf '%-35s | %-15s | %s\n' "$name" "$dtype" $status)
|
||||
|
||||
menu="$menu # $option"
|
||||
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"
|
||||
local status=$2
|
||||
name="$1"
|
||||
status=$2
|
||||
|
||||
if [[ "$status" == "" ]]; then
|
||||
if [ "$status" = "" ]; then
|
||||
nmcli connection down "$name"
|
||||
else
|
||||
nmcli connection up "$name"
|
||||
fi
|
||||
}
|
||||
|
||||
function main()
|
||||
main()
|
||||
{
|
||||
local menu
|
||||
local choice
|
||||
local name
|
||||
local stat
|
||||
|
||||
menu=$(build_rofi_menu)
|
||||
choice=$($ROFI <<< $menu)
|
||||
[[ $? -ne 0 ]] && return 1
|
||||
choice=$(echo "$menu" | $ROFI)
|
||||
[ "$?" -ne 0 ] && return 1
|
||||
|
||||
name=$(cut -d '|' -f 1 <<< $choice | awk '{$1=$1;print}')
|
||||
stat=$(cut -d '|' -f 3 <<< $choice | awk '{$1=$1;print}')
|
||||
name=$(echo "$choice" | cut -d '|' -f 1 | awk '{$1=$1;print}')
|
||||
stat=$(echo "$choice" | cut -d '|' -f 3 | awk '{$1=$1;print}')
|
||||
|
||||
switch_connections "$name" $stat
|
||||
switch_connections "$name" "$stat"
|
||||
}
|
||||
|
||||
|
||||
main
|
||||
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
set -e
|
||||
|
||||
[[ -z $1 ]] && exit 1
|
||||
[ -z "$1" ] && exit 1
|
||||
|
||||
active_window=$(xdotool getactivewindow)
|
||||
window=$(xdotool search --name "$1")
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
[ "$?" -ne 0 ] && exit 1
|
||||
|
||||
if [[ $active_window == $window ]]; then
|
||||
xdotool windowminimize $window
|
||||
if [ "$active_window" = "$window" ]; then
|
||||
xdotool windowminimize "$window"
|
||||
else
|
||||
xdotool windowactivate $window
|
||||
xdotool windowactivate "$window"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
19
install.sh
19
install.sh
@ -2,7 +2,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
function dotfiles()
|
||||
dotfiles()
|
||||
{
|
||||
echo "[INFO] Installing dot files..."
|
||||
|
||||
@ -17,29 +17,26 @@ function dotfiles()
|
||||
echo ""
|
||||
}
|
||||
|
||||
function dconf_loader()
|
||||
dconf_loader()
|
||||
{
|
||||
local file
|
||||
local dconf_path
|
||||
|
||||
if ! which dconf > /dev/null 2>&1; then
|
||||
if ! command -v dconf > /dev/null 2>&1; then
|
||||
echo "[WARNING] dconf command not found"
|
||||
echo ""
|
||||
return 1
|
||||
else
|
||||
for file in dconf/*; do
|
||||
echo -e "[INFO] Loading $(basename $file) config..."
|
||||
dconf_path=$(egrep -m1 '^#.+dconf-path=.+$' $file | cut -f2 -d "=")
|
||||
dconf load $dconf_path < $file
|
||||
echo "[INFO] Loading $(basename "$file") config..."
|
||||
dconf_path=$(grep -E -m1 '^#.+dconf-path=.+$' "$file" | cut -f2 -d "=")
|
||||
dconf load "$dconf_path" < "$file"
|
||||
done
|
||||
fi
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
function main()
|
||||
main()
|
||||
{
|
||||
cd $(dirname $0)
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
dotfiles
|
||||
dconf_loader
|
||||
|
Loading…
Reference in New Issue
Block a user