powermenu.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env bash
  2. ## Author : Aditya Shakya
  3. ## Mail : adi1090x@gmail.com
  4. ## Github : @adi1090x
  5. ## Twitter : @adi1090x
  6. style="$($HOME/.config/rofi/applets/menu/style.sh)"
  7. dir="$HOME/.config/rofi/applets/menu/configs/$style"
  8. rofi_command="rofi -theme $dir/powermenu.rasi"
  9. uptime=$(uptime -p | sed -e 's/up //g')
  10. cpu=$($HOME/.config/rofi/bin/usedcpu)
  11. memory=$($HOME/.config/rofi/bin/usedram)
  12. # Options
  13. shutdown=""
  14. reboot=""
  15. lock=""
  16. suspend=""
  17. logout=""
  18. # Confirmation
  19. confirm_exit() {
  20. rofi -dmenu\
  21. -i\
  22. -no-fixed-num-lines\
  23. -p "Are You Sure? : "\
  24. -theme $HOME/.config/rofi/applets/styles/confirm.rasi
  25. }
  26. # Message
  27. msg() {
  28. rofi -theme "$HOME/.config/rofi/applets/styles/message.rasi" -e "Available Options - yes / y / no / n"
  29. }
  30. # Variable passed to rofi
  31. options="$shutdown\n$reboot\n$lock\n$suspend\n$logout"
  32. chosen="$(echo -e "$options" | $rofi_command -p "祥 $uptime |  $cpu | ﬙ $memory " -dmenu -selected-row 2)"
  33. case $chosen in
  34. $shutdown)
  35. ans=$(confirm_exit &)
  36. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  37. systemctl poweroff
  38. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  39. exit 0
  40. else
  41. msg
  42. fi
  43. ;;
  44. $reboot)
  45. ans=$(confirm_exit &)
  46. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  47. systemctl reboot
  48. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  49. exit 0
  50. else
  51. msg
  52. fi
  53. ;;
  54. $lock)
  55. if [[ -f /usr/bin/i3lock ]]; then
  56. i3lock
  57. elif [[ -f /usr/bin/betterlockscreen ]]; then
  58. betterlockscreen -l
  59. fi
  60. ;;
  61. $suspend)
  62. ans=$(confirm_exit &)
  63. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  64. mpc -q pause
  65. amixer set Master mute
  66. systemctl suspend
  67. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  68. exit 0
  69. else
  70. msg
  71. fi
  72. ;;
  73. $logout)
  74. ans=$(confirm_exit &)
  75. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  76. if [[ "$DESKTOP_SESSION" == "Openbox" ]]; then
  77. openbox --exit
  78. elif [[ "$DESKTOP_SESSION" == "bspwm" ]]; then
  79. bspc quit
  80. elif [[ "$DESKTOP_SESSION" == "i3" ]]; then
  81. i3-msg exit
  82. fi
  83. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  84. exit 0
  85. else
  86. msg
  87. fi
  88. ;;
  89. esac