rice/scripts/picom.sh

68 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2021-07-28 23:54:53 -07:00
#!/bin/bash
# script to launch a new instance of picom in the background
set -Euo pipefail
# set -Eeuo pipefail
# remove the e argument so that it does not stop on any command failure
# e.g. having no picom running and having line 15 return non 0 return code
verbose=0
justKillIt=0
# if [[ $# -gt 0 && $1 == "-v" ]]; then
# verbose=1
# fi
while getopts "vk" arg; do
case $arg in
2021-10-29 13:14:44 -07:00
v) verbose=1 ;;
k) justKillIt=1 ;;
2021-07-28 23:54:53 -07:00
esac
done
if [[ $justKillIt -eq 1 ]]; then
if [[ $verbose -eq 1 ]]; then
echo 'Searching for running picom instance'
fi
if [[ $(pgrep -x "picom") != '' ]]; then
PID=$(pidof "picom")
if [[ $verbose -eq 1 ]]; then
echo 'Found running instance of picom with pid '$PID
echo 'Killing instance'
fi
kill -9 $PID
if [[ $verbose -eq 1 ]]; then
echo 'Killed picom instance with pid' $PID
fi
exit 0
else
if [[ $verbose -eq 1 ]]; then
echo 'No running instance of picom found'
fi
exit 1
fi
fi
res=$(pgrep -x picom)
2021-10-29 13:14:44 -07:00
if [[ $res != '' ]]; then
2021-07-28 23:54:53 -07:00
pid=$(pidof picom)
2021-10-29 13:14:44 -07:00
if [[ $verbose -eq 1 ]]; then
2021-07-28 23:54:53 -07:00
echo 'killing process pid '$pid
fi
kill -9 $pid
2021-10-29 13:14:44 -07:00
while pgrep -x picom >/dev/null; do
sleep 1
2021-07-28 23:54:53 -07:00
done
fi
if [[ $verbose -eq 1 ]]; then
2021-10-29 13:14:44 -07:00
picom --config ~/.config/picom/picom.conf &
2021-07-28 23:54:53 -07:00
else
2021-10-29 13:14:44 -07:00
picom --config ~/.config/picom/picom.conf &>/dev/null &
2021-07-28 23:54:53 -07:00
fi
2021-10-29 13:14:44 -07:00
if [[ $verbose -eq 1 ]]; then
2021-07-28 23:54:53 -07:00
pid=$(pidof picom)
echo 'launched new instance of picom with pid '$pid
fi