toggler.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! /bin/bash
  2. ##### This is my (demuredemeanor) toggler script
  3. # Source Code: https://notabug.org/demure/scripts/src/master/toggler.sh
  4. #
  5. # This script is intended to be a scaleable invoker of various quick toggles I code.
  6. # The inspiration was an AWK 'oneliner' that wasn't playing well with i3wm's bindsym+exec due to quotes/pipe.
  7. NAME=$(basename "$0")
  8. ## Try to keep these strings up to date with the cases below
  9. TOG_LIST="powersave, xss-lock, redshift"
  10. BAR_LIST="polybar, utc, ip"
  11. HELP="${NAME}: usage: [TOGGLE_NAME]\n\toptions: ${TOG_LIST}\n\tdemure's bar: ${BAR_LIST}"
  12. if [[ $# -eq 1 ]]; then
  13. AUG="$1"
  14. case $AUG in
  15. ps|powersave)
  16. ## This is a little awk to toggle between having the screen power saving on/off. Helps keep music going through my external speakers when docked.¬
  17. xset q | awk 'BEGIN {C="xset -display :0.0"} /DPMS is/ {match($0,/DPMS is (.*)/,m)} END {if(m[1]=="Enabled"){D="-dpms";S="off";B="noblank"} else {D="dpms";S="on";B="blank"}} END {system(C" "D);system(C" s "S);system(C" s "B)}'
  18. ;;
  19. xl|xss-lock)
  20. ## kills xss-lock, or starts it
  21. pkill xss-lock || xss-lock -- i3block -e -c 2E3436 &
  22. ;;
  23. rs|redshift)
  24. ## Toggles redshift red mode
  25. pkill -USR1 redshift
  26. ;;
  27. ## polybar related section
  28. pb|polybar)
  29. ## Kill and restart polybar.
  30. $HOME/.config/polybar/scripts/start_polybar.sh
  31. ;;
  32. utc|UTC)
  33. ## A little toggle to go between local TZ and UTC in my fancy polybar
  34. awk -v TEMP=/tmp/i3_polybar_utc_${USER} 'BEGIN {{FILE=getline < TEMP < 0 ? "0" : "1"} {if($0==1){STATE=1} else {STATE=0}} {if(STATE==0){system("echo 1 > "TEMP)} else {system("echo 0 > "TEMP)}} }'
  35. ;;
  36. ip)
  37. ## A little trinary switch for toggling between showing/hiding the ip in my polybar
  38. awk -v TEMP=/tmp/i3_polybar_ip_toggle_${USER} 'BEGIN {{FILE=getline < TEMP < 0 ? "0" : "1"} {if($0==1){STATE=1} else {STATE=0}} {if(STATE==0){system("echo 1 > "TEMP)} else {system("echo 0 > "TEMP)}} }'
  39. ;;
  40. *)
  41. echo "Bad augment."
  42. echo -e "${HELP}"
  43. ;;
  44. esac
  45. elif [[ $# -gt 1 ]]; then
  46. echo "Too many augments!"
  47. echo -e "${HELP}"
  48. else
  49. echo -e "${HELP}"
  50. fi