From f4dc28b0b5096b95ff1d1860974c20ee48bfcb6b Mon Sep 17 00:00:00 2001 From: Joe Standring Date: Wed, 27 Jan 2021 11:26:05 +0000 Subject: [PATCH] Parallelize non-local processes --- bar-functions/dwm_networkmanager.sh | 6 ++---- bar-functions/dwm_weather.sh | 10 +++++----- dwm_bar.sh | 17 +++++++++++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bar-functions/dwm_networkmanager.sh b/bar-functions/dwm_networkmanager.sh index c1e20ff..db39a7e 100755 --- a/bar-functions/dwm_networkmanager.sh +++ b/bar-functions/dwm_networkmanager.sh @@ -15,13 +15,11 @@ dwm_networkmanager () { PRIVATE=$(nmcli -a | grep 'inet4 192' | awk '{print $2}') PUBLIC=$(curl -s https://ipinfo.io/ip) - printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "🌐 %s %s | %s" "$CONNAME" "$PRIVATE" "$PUBLIC" + export __DWM_BAR_NETWORKMANAGER__="${SEP1}🌐 ${CONNAME} ${PRIVATE} ${PUBLIC}${SEP2}" else - printf "NET %s %s | %s" "$CONNAME" "$PRIVATE" "$PUBLIC" + export __DWM_BAR_NETWORKMANAGER__="${SEP1}NET ${CONNAME} ${PRIVATE} ${PUBLIC}${SEP2}" fi - printf "%s\n" "$SEP2" } dwm_networkmanager diff --git a/bar-functions/dwm_weather.sh b/bar-functions/dwm_weather.sh index 6c7fd8c..8689a8d 100755 --- a/bar-functions/dwm_weather.sh +++ b/bar-functions/dwm_weather.sh @@ -8,15 +8,15 @@ # Change the value of LOCATION to match your city dwm_weather() { - LOCATION=city + LOCATION=London - printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "%s" "$(curl -s wttr.in/$LOCATION?format=1)" + DATA=$(curl -s wttr.in/$LOCATION?format=1) + export __DWM_BAR_WEATHER__="${SEP1} ${DATA} ${SEP2}" else - printf "WEA %s" "$(curl -s wttr.in/$LOCATION?format=1 | grep -o ".[0-9].*")" + DATA=$(curl -s wttr.in/$LOCATION?format=1 | grep -o ".[0-9].*") + export __DWM_BAR_WEATHER__="${SEP1} WEA ${DATA} ${SEP2}" fi - printf "%s\n" "$SEP2" } dwm_weather diff --git a/dwm_bar.sh b/dwm_bar.sh index b983b19..f22ecec 100755 --- a/dwm_bar.sh +++ b/dwm_bar.sh @@ -44,10 +44,20 @@ export SEP2="]" . "$DIR/bar-functions/dwm_loadavg.sh" . "$DIR/bar-functions/dwm_currency.sh" +parallelize() { + while true + do + printf "Running parallel processes\n" + dwm_weather & + dwm_networkmanager & + sleep 5 + done +} +parallelize & + # Update dwm status bar every second while true do - # Append results of each func one by one to a string dispstr="" dispstr="$dispstr$(dwm_connman)" @@ -63,9 +73,9 @@ do dispstr="$dispstr$(dwm_backlight)" dispstr="$dispstr$(dwm_alsa)" dispstr="$dispstr$(dwm_pulse)" - dispstr="$dispstr$(dwm_weather)" + dispstr="$dispstr${__DWM_BAR_WEATHER__}" dispstr="$dispstr$(dwm_vpn)" - dispstr="$dispstr$(dwm_networkmanager)" + dispstr="$dispstr${__DWM_BAR_NETWORKMANAGER__}" dispstr="$dispstr$(dwm_keyboard)" dispstr="$dispstr$(dwm_ccurse)" dispstr="$dispstr$(dwm_date)" @@ -74,5 +84,4 @@ do xsetroot -name "$dispstr" sleep 1 - done