summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2018-06-02 18:19:51 (EDT)
committer P. J. McDermott <pj@pehjota.net>2018-06-02 19:11:12 (EDT)
commit4bde2ad478065de2887fe0d8197d418e83e822ed (patch)
tree88b91ba4ae22eb5729936d506ae967e4257fa354
parent0d78b4fb96ab986f5aa2ed4137ff07c84580b3d2 (diff)
downloadfluxbox-4bde2ad478065de2887fe0d8197d418e83e822ed.zip
fluxbox-4bde2ad478065de2887fe0d8197d418e83e822ed.tar.gz
fluxbox-4bde2ad478065de2887fe0d8197d418e83e822ed.tar.bz2
bin/xsession: New script
-rwxr-xr-x.gitignore.d/fluxbox1
-rwxr-xr-xbin/xsession97
2 files changed, 98 insertions, 0 deletions
diff --git a/.gitignore.d/fluxbox b/.gitignore.d/fluxbox
index 6585664..4d09bd6 100755
--- a/.gitignore.d/fluxbox
+++ b/.gitignore.d/fluxbox
@@ -27,6 +27,7 @@
!/bin/hwmon
!/bin/volmon
!/bin/xinput-toggle
+!/bin/xsession
!/lib/
!/lib/panel/
!/lib/panel/*
diff --git a/bin/xsession b/bin/xsession
new file mode 100755
index 0000000..3b1cf86
--- /dev/null
+++ b/bin/xsession
@@ -0,0 +1,97 @@
+#!/bin/sh
+
+set -eu
+
+actions_icons='/usr/share/icons/gnome/16x16/actions'
+
+do_logout()
+{
+ zenity --question --title='Log Out' \
+ --window-icon="${actions_icons}/system-log-out.png" \
+ --text='Are you sure you want to log out?' \
+ --ok-label='Log Out' --cancel-label='Cancel' && \
+ printf 'quit\n' >~/.xsessionmanage
+
+ return 0
+}
+
+do_shutdown()
+{
+ zenity --question --title='Shut Down' \
+ --window-icon="${actions_icons}/system-shutdown.png" \
+ --text='Are you sure you want to shut down this system?' \
+ --ok-label='Shut Down' --cancel-label='Cancel' && \
+ sudo shutdown -hP now
+
+ return 0
+}
+
+do_reboot()
+{
+ zenity --question --title='Reboot' \
+ --window-icon="${actions_icons}/system-shutdown.png" \
+ --text='Are you sure you want to reboot this system?' \
+ --ok-label='Reboot' --cancel-label='Cancel' && \
+ sudo reboot
+
+ return 0
+}
+
+do_s2mem()
+{
+ zenity --question --title='Suspend' \
+ --window-icon="${actions_icons}/media-playback-pause.png" \
+ --text='Are you sure you want to suspend this system?' \
+ --ok-label='Suspend' --cancel-label='Cancel' && \
+ sudo dd of='/sys/power/state' <<-EOF
+ mem
+ EOF
+
+ return 0
+}
+
+do_s2disk()
+{
+ zenity --question --title='Hibernate' \
+ --window-icon="${actions_icons}/media-playback-pause.png" \
+ --text='Are you sure you want to hibernate this system?' \
+ --ok-label='Hibernate' --cancel-label='Cancel' && \
+ sudo dd of='/sys/power/state' <<-EOF
+ disk
+ EOF
+
+ return 0
+}
+
+usage()
+{
+ printf 'Usage: %s {logout|shutdown|reboot|s2mem|s2disk}\n' "${0}"
+
+ return 0
+}
+
+main()
+{
+ local action=
+
+ if [ ${#} -ne 1 ]; then
+ usage 1>&2
+ return 1
+ fi
+ action="${1}"
+ shift 1
+
+ case "${action}" in
+ 'logout' | 'shutdown' | 'reboot' | 's2mem' | 's2disk')
+ "do_${action}"
+ ;;
+ *)
+ usage 1>&2
+ return 1
+ ;;
+ esac
+
+ return 0
+}
+
+main "${@}"