random bash scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.0 KiB

  1. #!/usr/bin/env bash
  2. if [[ $DEBUG == 'true' ]]; then
  3. set -euxo pipefail
  4. else
  5. set -euo pipefail
  6. fi
  7. IFS=$'\n\t'
  8. kill_polybar() {
  9. pkill polybar || true
  10. # Wait until the processes have been shut down
  11. while pgrep -x polybar >/dev/null; do sleep 1; done
  12. }
  13. move_ws() {
  14. WORKSPACE=$1
  15. DIRECTION=$2
  16. i3-msg workspace "$WORKSPACE"
  17. i3-msg move workspace to output "$DIRECTION"
  18. }
  19. set_wallpaper() {
  20. SCREEN=$1
  21. MODE=$2
  22. IMAGE=$3
  23. nitrogen --head="$SCREEN" --set-"$MODE" --save ~/pictures/wallpapers/"$IMAGE"
  24. }
  25. start_bar() {
  26. export MONITOR=$1
  27. BAR=$2
  28. polybar --reload "$BAR" </dev/null >"/var/tmp/polybar-$MONITOR.log" 2>&1 &
  29. }
  30. display() {
  31. case ${1-} in
  32. work)
  33. xrandr \
  34. --output eDP-1 --mode 1920x1080 --pos 5280x824 --rotate normal \
  35. --output HDMI-1 --off \
  36. --output DP-1 --mode 2560x1440 --pos 0x0 --rotate left \
  37. --output DP-2 --mode 3840x2160 --pos 1440x284 --rotate normal
  38. move_ws 2 left
  39. ;;
  40. *) xrandr --auto ;;
  41. esac
  42. }
  43. status_bar() {
  44. kill_polybar
  45. (
  46. flock 200
  47. case ${1-} in
  48. work)
  49. start_bar eDP-1 1080p
  50. start_bar DP-2 4k
  51. ;;
  52. *) start_bar eDP-1 1080p ;;
  53. esac
  54. ) 200>/var/tmp/polybar-launch.lock
  55. }
  56. wallpaper() {
  57. case ${1-} in
  58. work)
  59. set_wallpaper 0 scaled IMG_20190901_161515-PANO.jpg
  60. set_wallpaper 1 auto IMG_20190903_163002-EFFECTS.jpg
  61. set_wallpaper 2 zoom-fill IMG_20190730_155936-PANO.jpg
  62. ;;
  63. *) set_wallpaper 0 auto EFFECTS.jpg ;;
  64. esac
  65. }
  66. show_usage() {
  67. echo "Usage: screens [-W] [-w ENV] [-s ENV]"
  68. }
  69. cmd_args() {
  70. if [[ $# -eq 0 ]]; then
  71. display
  72. wallpaper
  73. status_bar
  74. exit
  75. fi
  76. while test $# -gt 0; do
  77. case $1 in
  78. -W | --work)
  79. display work
  80. wallpaper work
  81. status_bar work
  82. exit
  83. ;;
  84. -w | --wallpaper) wallpaper "${2-}" ;;
  85. -s | --status-bar) status_bar "${2-}" ;;
  86. --help | -h) show_usage ;;
  87. esac
  88. shift
  89. done
  90. }
  91. [ -f ~/.dotfiles/Xresources ] && xrdb -merge -I"$HOME" ~/.dotfiles/Xresources
  92. cmd_args "$@"