powermenu.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env bash
  2. ## Author : Aditya Shakya
  3. ## Mail : adi1090x@gmail.com
  4. ## Github : @adi1090x
  5. ## Twitter : @adi1090x
  6. # Available Styles
  7. # >> Created and tested on : rofi 1.6.0-1
  8. #
  9. # column_circle column_square column_rounded column_alt
  10. # card_circle card_square card_rounded card_alt
  11. # dock_circle dock_square dock_rounded dock_alt
  12. # drop_circle drop_square drop_rounded drop_alt
  13. # full_circle full_square full_rounded full_alt
  14. # row_circle row_square row_rounded row_alt
  15. theme="full_circle"
  16. dir="$HOME/.config/rofi/powermenu"
  17. # random colors
  18. styles=($(ls -p --hide="colors.rasi" $dir/styles))
  19. color="${styles[$(( $RANDOM % 8 ))]}"
  20. # comment this line to disable random colors
  21. sed -i -e "s/@import .*/@import \"$color\"/g" $dir/styles/colors.rasi
  22. # comment these lines to disable random style
  23. themes=($(ls -p --hide="powermenu.sh" --hide="styles" --hide="confirm.rasi" --hide="message.rasi" $dir))
  24. theme="${themes[$(( $RANDOM % 24 ))]}"
  25. uptime=$(uptime -p | sed -e 's/up //g')
  26. rofi_command="rofi -theme $dir/$theme"
  27. # Options
  28. shutdown=""
  29. reboot=""
  30. lock=""
  31. suspend=""
  32. logout=""
  33. # Confirmation
  34. confirm_exit() {
  35. rofi -dmenu\
  36. -i\
  37. -no-fixed-num-lines\
  38. -p "Are You Sure? : "\
  39. -theme $dir/confirm.rasi
  40. }
  41. # Message
  42. msg() {
  43. rofi -theme "$dir/message.rasi" -e "Available Options - yes / y / no / n"
  44. }
  45. # Variable passed to rofi
  46. options="$shutdown\n$reboot\n$lock\n$suspend\n$logout"
  47. chosen="$(echo -e "$options" | $rofi_command -p "Uptime: $uptime" -dmenu -selected-row 2)"
  48. case $chosen in
  49. $shutdown)
  50. ans=$(confirm_exit &)
  51. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  52. systemctl poweroff
  53. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  54. exit 0
  55. else
  56. msg
  57. fi
  58. ;;
  59. $reboot)
  60. ans=$(confirm_exit &)
  61. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  62. systemctl reboot
  63. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  64. exit 0
  65. else
  66. msg
  67. fi
  68. ;;
  69. $lock)
  70. if [[ -f /usr/bin/i3lock ]]; then
  71. i3lock
  72. elif [[ -f /usr/bin/betterlockscreen ]]; then
  73. betterlockscreen -l
  74. fi
  75. ;;
  76. $suspend)
  77. ans=$(confirm_exit &)
  78. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  79. mpc -q pause
  80. amixer set Master mute
  81. systemctl suspend
  82. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  83. exit 0
  84. else
  85. msg
  86. fi
  87. ;;
  88. $logout)
  89. ans=$(confirm_exit &)
  90. if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then
  91. if [[ "$DESKTOP_SESSION" == "Openbox" ]]; then
  92. openbox --exit
  93. elif [[ "$DESKTOP_SESSION" == "bspwm" ]]; then
  94. bspc quit
  95. elif [[ "$DESKTOP_SESSION" == "i3" ]]; then
  96. i3-msg exit
  97. fi
  98. elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then
  99. exit 0
  100. else
  101. msg
  102. fi
  103. ;;
  104. esac