From e59268441a9f46f806e74c9bc8ddc9a0b224c60d Mon Sep 17 00:00:00 2001 From: B Stack Date: Tue, 10 Mar 2020 22:05:48 -0400 Subject: add DRYRUN and bash_completion to lm-helper --- src/Makefile | 9 ++++-- src/etc/bash_completion.d/logout-manager | 12 ++++++++ src/usr/libexec/logout-manager/lm-helper | 52 +++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 src/etc/bash_completion.d/logout-manager (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 6af4efb..9fdad77 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,6 +29,7 @@ LIBEXECDIR = $(DESTDIR)$(prefix)/libexec DOCDIR = $(SHAREDIR)/doc/$(APPNAME) APPDIR = $(SHAREDIR)/$(APPNAME) APPSDIR = $(SHAREDIR)/applications +BASHCDIR = $(SYSCONFDIR)/bash_completion.d awkbin :=$(shell which awk) cpbin :=$(shell which cp) @@ -36,12 +37,13 @@ echobin :=$(shell which echo) findbin :=$(shell which find) grepbin :=$(shell which grep) installbin :=$(shell which install) +lnbin :=$(shell which ln) rmbin :=$(shell which rm) sedbin :=$(shell which sed) sortbin :=$(shell which sort) truebin :=$(shell which true) +uniqbin :=$(shell which uniq) xargsbin :=$(shell which xargs) -lnbin :=$(shell which ln) all: ${echobin} "No compilation in this package." @@ -53,7 +55,7 @@ list: deplist: @if test -z "$(DISTRO)" ; then ${echobin} "Please run \`make deplist\` with DISTRO= one of: `make deplist_opts 2>&1 1>/dev/null | ${xargsbin}`. Aborted." ; exit 1 ; fi - @${grepbin} -h --exclude='Makefile' -A5 -riIE dependencies $(SRCDIR) | awk -v 'distro=$(DISTRO)' 'tolower($$0) ~ distro {$$1="";$$2="";print}' | sort | uniq | xargs + @${grepbin} -h --exclude='Makefile' --exclude-dir='doc' -A5 -riIE dependencies $(SRCDIR) | ${awkbin} -v 'distro=$(DISTRO)' 'tolower($$0) ~ distro {$$1="";$$2="";print}' | ${sortbin} | ${uniqbin} | ${xargsbin} deplist_opts: @${echobin} "el7" 1>&2 @@ -61,8 +63,9 @@ deplist_opts: install: @${echobin} Installing files to ${DESTDIR} - ${installbin} -d ${SYSCONFDIR} ${DEFAULTDIR} ${BINDIR} ${APPSDIR} ${APPDIR} ${DOCDIR} + ${installbin} -d ${SYSCONFDIR} ${DEFAULTDIR} ${BINDIR} ${APPSDIR} ${APPDIR} ${DOCDIR} ${BASHCDIR} ${cpbin} -pr ${SRCDIR}/etc/*.* ${SYSCONFDIR} + ${cpbin} -pr ${SRCDIR}/etc/bash_completion.d/* ${BASHCDIR} ${cpbin} -pr ${SRCDIR}/etc/sysconfig/* ${DEFAULTDIR} ${cpbin} -pr ${SRCDIR}/usr/bin/* ${BINDIR} ${cpbin} -pr ${SRCDIR}/usr/share/applications/* ${APPSDIR} diff --git a/src/etc/bash_completion.d/logout-manager b/src/etc/bash_completion.d/logout-manager new file mode 100644 index 0000000..fd1267f --- /dev/null +++ b/src/etc/bash_completion.d/logout-manager @@ -0,0 +1,12 @@ +# File: /etc/bash_completion.d/logout-manager +# Reference: +# bgscripts-core: /usr/bin/bp +# man complete + +_lm_helper() { + local cur prev words cword; + _init_completion || return + COMPREPLY=($( compgen -W "$( ~/dev/logout-manager/src/usr/libexec/logout-manager/lm-helper options )" -- "$cur" )) + return 0 +} && \ +complete -F _lm_helper -o bashdefault lm-helper diff --git a/src/usr/libexec/logout-manager/lm-helper b/src/usr/libexec/logout-manager/lm-helper index c5e37f1..e791f28 100755 --- a/src/usr/libexec/logout-manager/lm-helper +++ b/src/usr/libexec/logout-manager/lm-helper @@ -1,4 +1,6 @@ #!/bin/sh +# Dependencies: +# Devuan: wmctrl case "${1}" in help) # show this help screen { @@ -10,24 +12,58 @@ case "${1}" in } ;; options) # used by bash_completion function HIDDEN - grep -E '^\s{3}[A-Za-z]+\)' "${0}" | tr -dc '[A-Za-z\n]' | grep -vE 'options|help' + grep -E '^\s{3}[A-Za-z]+\)' "${0}" | awk '{print $1}' | tr -dc '[A-Za-z\n]' | grep -vE 'options|help' ;; lock) # lock the current screen - xscreensaver --locknow + if test -z "${DRYRUN}" ; + then + xscreensaver --locknow + else + echo "xscreensaver --locknow" + fi ;; logout) # log out the current user of the graphical session - echo "Gotta say unh! Feature not yet implemented." 1>&2 - exit 1 + # determine DE/WM and act accordingly + _wm="$( wmctrl -m | awk '/Name:/{$1="";print;}' | xargs )" + case "${_wm}" in + Fluxbox) + if test -z "${DRYRUN}" ; + then + fluxbox-remote exit + else + echo "fluxbox-remote exit" + fi + ;; + *) + echo "Gotta say unh! Feature not yet implemented for \"${_wm}\"" 1>&2 + exit 1 + ;; + esac ;; hibernate) # save system state to disk and power off - # linux only - printf 'disk' | tee /sys/power/state + # this method is linux only + if test -z "${DRYRUN}" ; + then + printf 'disk' | tee /sys/power/state + else + echo "printf 'disk' | tee /sys/power/state" + fi ;; shutdown) # power off - shutdown -h now + if test -z "${DRYRUN}" ; + then + shutdown -h now + else + echo "shutdown -h now" + fi ;; reboot) # restart the system - shutdown -r now + if test -z "${DRYRUN}" ; + then + shutdown -r now + else + echo "shutdown -r now" + fi ;; *) # HIDE echo "invalid choice: ${1}" 1>&2 -- cgit