From 080365dd22b967274833f50a5cd0cccc0790a658 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Sat, 11 Apr 2020 10:03:33 -0400 Subject: [PATCH] pgrep is a little slow, slower than ps | grep --- .local/bin/cron/newsup | 2 +- .local/bin/displayselect | 2 +- .local/bin/launch_polybar | 2 +- .local/bin/td-toggle | 2 +- .local/bin/torwrap | 2 +- .local/bin/transadd | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.local/bin/cron/newsup b/.local/bin/cron/newsup index bfdd2f5..bf8898e 100755 --- a/.local/bin/cron/newsup +++ b/.local/bin/cron/newsup @@ -7,7 +7,7 @@ ping -q -c 1 1.1.1.1 > /dev/null || exit /usr/bin/notify-send "📰 Updating RSS feeds..." -pgrep -x newsboat >/dev/null && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name newsboat)" R && exit +ps ax | grep -q newsboat$ && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name newsboat)" R && exit echo 🔃 > /tmp/newsupdate pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}" diff --git a/.local/bin/displayselect b/.local/bin/displayselect index c0e3479..b2e0075 100755 --- a/.local/bin/displayselect +++ b/.local/bin/displayselect @@ -69,4 +69,4 @@ esac setbg # Fix background if screen size/arangement has changed. remaps # Re-remap keys if keyboard added (for laptop bases) -pgrep -x dunst >/dev/null && killall dunst && setsid dunst & # Restart dunst to ensure proper location on screen +{ killall dunst ; setsid dunst & } >/dev/null 2>&1 # Restart dunst to ensure proper location on screen diff --git a/.local/bin/launch_polybar b/.local/bin/launch_polybar index 291d183..0af1579 100755 --- a/.local/bin/launch_polybar +++ b/.local/bin/launch_polybar @@ -4,7 +4,7 @@ killall -q polybar # Wait until the processes have been shut down -while pgrep -x polybar >/dev/null; do sleep 1; done +while ps ax | grep -q "\spolybar$"; do sleep 1; done for i in $(polybar -m | awk -F: '{print $1}'); do MONITOR=$i polybar default & done diff --git a/.local/bin/td-toggle b/.local/bin/td-toggle index 46bb183..fb8620f 100755 --- a/.local/bin/td-toggle +++ b/.local/bin/td-toggle @@ -1,7 +1,7 @@ #!/bin/sh # If transmission-daemon is running, will ask to kill, else will ask to start. -if pgrep -x transmission-da >/dev/null ; +if ps ax | grep -q "\stransmission-daemon$" ; then [ "$(printf "No\\nYes" | dmenu -i -p "Kill transmission-daemon?")" = "Yes" ] && killall transmission-da && notify-send "transmission-daemon killed." else diff --git a/.local/bin/torwrap b/.local/bin/torwrap index 2e42c87..82a268a 100755 --- a/.local/bin/torwrap +++ b/.local/bin/torwrap @@ -2,6 +2,6 @@ ifinstalled tremc transmission-cli || exit -! pgrep -x transmission-da >/dev/null && transmission-daemon && notify-send "Starting torrent daemon..." && sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" +! ps ax | grep -q "\stransmission-daemon$" && transmission-daemon && notify-send "Starting torrent daemon..." && sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" & $TERMINAL -e tremc diff --git a/.local/bin/transadd b/.local/bin/transadd index 97ffafc..a2e080d 100755 --- a/.local/bin/transadd +++ b/.local/bin/transadd @@ -2,8 +2,8 @@ # Mimeapp script for adding torrent to transmission-daemon, but will also start the daemon first if not running. -# transmission-daemon sometimes fails to take remote requests in its first moments. +# transmission-daemon sometimes fails to take remote requests in its first moments, hence the sleep. -pgrep -x transmission-da || (transmission-daemon && notify-send "Starting transmission daemon..." && sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}") +ps ax | grep -q "\stransmission-daemon$" || (transmission-daemon && notify-send "Starting transmission daemon..." && sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}") & transmission-remote -a "$@" && notify-send "🔽 Torrent added."