You are not logged in.

#101 2019-03-07 12:07:10

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

ohnonot wrote:
Bearded_Blunder wrote:

the trouble with more than one short arguments  eg

bl-exit -m -v

is that users expect to be able to supply any of
"-m -v", "-v -m", "-mv" or "-vm"
^^ Parsing that gets ugly the more possible arguments the uglier.

did you look at getopts?
It's a bash builtin and does short arguments in the manner you mention. totally sufficient for this script.

help getopts

edit:
http://wiki.bash-hackers.org/howto/getopts_tutorial

It was a deliberate choice, getopts is only half the problem anyway, having gotopts you then have to parse & make sure the opts make sense, don't conflict, etc., etc. some idiot (me testing it) would be bound to pass show 2 different dialogues, lock-session & power off all at once.. you have to handle that then.
Up front decision to follow KISS
Someone else wants to play with multiple arguments it's up to them smile yes getopts would work for something like this, it's also not needed for something this simple, pure embellishment.

Last edited by Bearded_Blunder (2019-03-07 12:11:02)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#102 2019-03-07 16:17:49

damo
....moderator....
Registered: 2015-08-20
Posts: 5,006

Re: bl-exit replacement suggestions

It is easy to add a config file, which does away with any need for script args for the gui dialogs. So if there are no commandline switches, the gui is run, else any args just run the appropriate logoutctl <action>

I have been playing with this setup for ~/.config/bbexit/bb-exitrc (using "bb-exit" as a working name!)

# bb-exitrc

# Dialog style. Choose from
#style=simple
#style=show-hibernate
#style=show-all
#style=vertical
#style=vertical-hibernate
#style=vertical-all
#style=none (default is used)
style=none
default-style=vertical-all

# Add icon to text. Boolean 0/1
icons=0

# Monospace font recommended for vertical alignment of icons+text. Enter <fontname>, or none for theme font.
font=Monospace

# Icons-only dialog. Boolean 0/1
icons-only=1
# Icon size: large/small
iconsize=small
# Icon shade: dark/light
iconshade=light

This seems to cover the options for horizontal(=simple)/vertical layouts, with/without icons, and also the bl-exit icons-only style.

No fancy arguments or config parsing is required since the values can be sourced directly by bb-exit.

ATM I've just done a minimal proof-of-concept, but if it gets a thumbs-up I will do more work on it.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#103 2019-03-07 21:29:24

damo
....moderator....
Registered: 2015-08-20
Posts: 5,006

Re: bl-exit replacement suggestions

scrot-exits.th.jpg
All these were produced from settings in a config file, with no script args.
(My version of @B_B's bb-exit is still a WIP though, and not for public exposure wink )

# bb-exitrc

## Dialog style. Choose from
style=simple
#style=show-hibernate
#style=show-all
#style=none (default is used)

default_style=show-all

## Orientation of dialog: horizontal | vertical
#layout=horizontal
layout=vertical

## Add icon to text. Boolean 0|1. Disregarded if BL_icons=1
icons=1

## Monospace font recommended for vertical alignment of icons+text, when using layout=vertical.
## Enter <fontname>, or none for theme font. NB Use single quotes with fontname
#font=none
#font='Monospace'
font='Roboto Mono'
#font='Terminus'

## Bunsenlabs Icons-only dialog. Boolean 0|1
BL_icons=0

## Icon size: large | small
iconsize=small
#iconsize=large

## Icon shade: dark | light
iconshade=light
#iconshade=dark

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#104 2019-03-07 23:10:29

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

I'm still playing with mine too, and it's not like you couldn't pick your layout there by simply changing the value to which I set OP_MODE in the script. tongue

Reason I'm providing arguments for the GUI in as much as I decided to is I can reply to users like this with:
Open the menu editor, find the bl-exit entry, append --argument save. wink

They whined about opening a config file.

Last edited by Bearded_Blunder (2019-03-07 23:12:15)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#105 2019-03-07 23:39:50

damo
....moderator....
Registered: 2015-08-20
Posts: 5,006

Re: bl-exit replacement suggestions

^ I feel your pain big_smile

I thought I'd try the approach that the current bl-exit is using. Let's see what the community would like.....


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#106 2019-03-08 01:59:16

hhh
Meep!
Registered: 2015-09-17
Posts: 8,059
Website

Re: bl-exit replacement suggestions

damo wrote:

https://cdn.scrot.moe/images/2019/03/07/scrot-exits.th.jpg
All these were produced from settings in a config file, with no script args.
(My version of @B_B's bb-exit is still a WIP though, and not for public exposure wink )

# bb-exitrc

## Dialog style. Choose from
style=simple
#style=show-hibernate
#style=show-all
#style=none (default is used)

default_style=show-all

## Orientation of dialog: horizontal | vertical
#layout=horizontal
layout=vertical

## Add icon to text. Boolean 0|1. Disregarded if BL_icons=1
icons=1

## Monospace font recommended for vertical alignment of icons+text, when using layout=vertical.
## Enter <fontname>, or none for theme font. NB Use single quotes with fontname
#font=none
#font='Monospace'
font='Roboto Mono'
#font='Terminus'

## Bunsenlabs Icons-only dialog. Boolean 0|1
BL_icons=0

## Icon size: large | small
iconsize=small
#iconsize=large

## Icon shade: dark | light
iconshade=light
#iconshade=dark

@dmo, Oh, My Debian!

Monospace font for the vertical menu I've been using, I can't wait to try it! Genius, my friend.

Offline

#107 2019-03-08 02:49:50

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 5,575
Website

Re: bl-exit replacement suggestions

damo wrote:

It is easy to add a config file, which does away with any need for script args for the gui dialogs. So if there are no commandline switches, the gui is run, else any args just run the appropriate logoutctl <action>

I have been playing with this setup for ~/.config/bbexit/bb-exitrc (using "bb-exit" as a working name!)

# bb-exitrc

# Dialog style. Choose from
#style=simple
#style=show-hibernate
#style=show-all
#style=vertical
#style=vertical-hibernate
#style=vertical-all
#style=none (default is used)
style=none
default-style=vertical-all

# Add icon to text. Boolean 0/1
icons=0

# Monospace font recommended for vertical alignment of icons+text. Enter <fontname>, or none for theme font.
font=Monospace

# Icons-only dialog. Boolean 0/1
icons-only=1
# Icon size: large/small
iconsize=small
# Icon shade: dark/light
iconshade=light

This seems to cover the options for horizontal(=simple)/vertical layouts, with/without icons, and also the bl-exit icons-only style.

No fancy arguments or config parsing is required since the values can be sourced directly by bb-exit.

ATM I've just done a minimal proof-of-concept, but if it gets a thumbs-up I will do more work on it.

Gets a thumbs-up from here anyway! Optional config files let people who want to tweak do so, and those who are happy with the default can just do nothing. smile


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#108 2019-03-08 02:58:06

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

Working on one also, mine's slightly less friendly though..... well I'm beginning to think so.
I also have a glitch, posted elsewhere (or will be soon), the glitch that is.


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#109 2019-03-09 23:19:14

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

OK next iteration you guys missed out v 0.3, 0.4 for your examination. This one handles config files, just copy the block at the start of the file minus the shebang & boilerplate & paste into a file at any of the locations stated in the explanatory block, that obviously won't be needed in a package, presumably a file will get installed.

Excuse my embarrassing code.

#!/usr/bin/env bash

########################################################################
##                                                                    ##
## Init and desktop agnostic "yad" based Logout/Exit dialogue.        ##
##                                                                    ##
## Written in response to the seeimingly widely held belief that      ##
## 'systemctl' is what you _have_ to use for power operations if you  ##
## have systemd, regardless that dbus calls are arguably superior.    ##
##                                                                    ##
## Since systemd users like systemd specific commands so much, here's ##
## a system exit dialogue that uses systemd's calls for every power   ##
## or session control action, while remaining compatible with         ##
## non-systemd systems.                                               ##
##                                                                    ##
## Originally written for Bunsenlabs "Lithium" by Bearded_Blunder     ##
## <init.choice@mxstuff.org> February 2019                            ##
##                                                                    ##
## Copyright © 2019 MXStuff.org <init.choice@mxstuff.org>             ##
##                                                                    ##
## This program is free software. It comes without any warranty, to   ##
## the extent permitted by applicable law. You can redistribute it    ##
## and/or modify it under the terms of the Do What The Fuck You Want  ##
## To Public License, Version 2, as published by Sam Hocevar. See     ##
## http://www.wtfpl.net/ for more details.                            ##
##                                                                    ##
########################################################################

########################################################################
#       Config block begins. Copy & paste block to config file.        #
#       Parser expects a file in any of these locations:               #
#       Vendor: Config added by "vendors" (eg BL).                     #
#              /usr/share/bunsen/conf.d/bl-exit.conf                   #
#       Local Administrator: Settings added by sysadmins               #
#              /etc/bl-exit/bl-exit.conf                               #
#       User Settings: Individual preferences.                         #
#              ~/.config/bunsen/bl-exit.conf                           #
#                                                                      #
#  NOTE: These files are not needed for operation, though at least one #
#        is required to edit settings with the --config-system or      #
#        --config arguments, when present they are read in the order   #
#        listed, and settings from the last file read take precedence, #
#        the resulting behaviour is the cumulative total of changes in #
#        each file in order, relative to the defaults in this script.  #
#                                                                      #
#        --configure-system                                            #
#            Will open /etc/bl-exit/bl-exit.conf if present or copy    #
#            /usr/share/bunsen/conf.d/bl-exit.conf to /etc/bl-exit/    #
#            then open it. If neither exist it will fail.              #
#                                                                      #
#        --configure                                                   #
#            Will check if ~/.config/bl-exit/bl-exit.conf exists and   #
#            open it for editing. If it does not it will try to copy   #
#            first /etc/bl-exit/bl-exit.conf then                      #
#            /usr/share/bunsen/conf.d/bl-exit.conf and open the copy   #
#            for editing. If no file exists it will fail.              #
#                                                                      #
########################################################################

# Default interface with no arguments see `bl-exit --help` for options.
# Specifying a non-graphical option such as --reboot here is silly.
DEFAULT_MODE="--vertical"

## Strings and Icons - These blocks make local translation easier ##

# Globally, except "icon" interface, button text/keyboard accelerators leading _underscore defines alt+key accelerator.
# Default accelerators except for "Cancel" correspond with the short command line arguments for that specific action.
# Colours and fonts can be specified. Example:
# For BL-Moonlight obconf tells me things are using "Sans" `fc-match Sans` says "Noto Sans" so I've specified
# 'Noto Sans Mono Bold' for buttons and 'Noto Sans Mono' for tooltips, the foreground colour I've picked up from the icons.
# The background from the windows themselves.
# CUSTOM Uncomment and comment out "DEFAULT" to enable and use.
#<identifier>  <push text field bg away from icons> <set font & button bg colours> text and _accelerators </span>
#TXT_CANCELYAD="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> _Cancel    </span>"
#TXT_LOGOUT_PC="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> _Log out   </span>"
#TXT_LOCK_SCRN="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> Loc_k      </span>"
#TXT_SLEEP_RAM="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> _Sleep     </span>"
#TXT_RESTARTPC="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> Re_boot    </span>"
#TXT_SHUT_DOWN="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> _Power off </span>"
#TXT_HIBERNATE="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> H_ibernate </span>"
#TXT_HYBRIDZZZ="<span font='Noto Sans Mono'> </span><span font='Noto Sans Mono Bold' foreground='#78909C' background='#152126'> H_yb Sleep </span>"
# NOTE: Text alignment will be unpredictablep without a monospace font and matching field lengths.
# `yad --font` and `yad --color` are useful for selection.

# DEFAULT
TXT_CANCELYAD="<span font='Noto Sans Mono'> _Cancel   </span>"
TXT_LOGOUT_PC="<span font='Noto Sans Mono'> _Log out  </span>"
TXT_LOCK_SCRN="<span font='Noto Sans Mono'> Loc_k     </span>"
TXT_SLEEP_RAM="<span font='Noto Sans Mono'> _Sleep    </span>"
TXT_RESTARTPC="<span font='Noto Sans Mono'> Re_boot   </span>"
TXT_SHUT_DOWN="<span font='Noto Sans Mono'> _Power off</span>"
TXT_HIBERNATE="<span font='Noto Sans Mono'> H_ibernate</span>"
TXT_HYBRIDZZZ="<span font='Noto Sans Mono'> H_yb Sleep</span>"

# Globally, tooltips.  I've just bunged in something for now :P
# Colours can be set too, Custom 'BL-Moonlight" example:
# CUSTOM Uncomment and comment out "DEFAULT" to enable and use.
#TIP_CANCELYAD="<span font='Noto Sans Mono' foreground='#78909C' background='#152126'> Cancel and close window. </span>"
#TIP_LOGOUT_PC="<span font='Noto Sans Mono' foreground='#78909C' background='#152126'> Log out from current session. </span>"
#TIP_LOCK_SCRN="<span font='Noto Sans Mono' foreground='#78909C' background='#152126'> Lock current session. </span>"
#TIP_SLEEP_RAM="<span font='Noto Sans Mono' foreground='#78909C' background='#152126'> Suspend computer. </span>"
#TIP_RESTARTPC="<span font='Noto Sans Mono' foreground='#78909C' background='#152126'> Restart computer. </span>"
#TIP_SHUT_DOWN="<span font='Noto Sans Mono' foreground='#78909C' background='#152126'> Shut down and power off. </span>"
#TIP_HIBERNATE="<span font='Noto Sans Mono' foreground='#78909C' background='#152126'> Save computer state and power off. </span>"
#TIP_HYBRIDZZZ="<span font='Noto Sans Mono' background='#152126'> Put in hybrid sleep mode. </span>"

# DEFAULT
TIP_CANCELYAD="Cancel and close window."
TIP_LOGOUT_PC="Log out from current session."
TIP_LOCK_SCRN="Lock current session."
TIP_SLEEP_RAM="Suspend computer."
TIP_RESTARTPC="Restart computer."
TIP_SHUT_DOWN="Shut down and power off."
TIP_HIBERNATE="Save computer state and power off."
TIP_HYBRIDZZZ="Put in hybrid sleep mode."

# Icons for normal buttons, for no icons in non-icon interfaces, set ""
ICO_CANCELYAD="gtk-close"
ICO_LOCK_SCRN="gnome-lockscreen"
ICO_LOGOUT_PC="gnome-logout"
ICO_SLEEP_RAM="system-suspend"
ICO_HIBERNATE="system-hibernate"
ICO_HYBRIDZZZ="system-suspend-hibernate"
ICO_RESTARTPC="system-reboot"
ICO_SHUT_DOWN="system-shutdown"
# TODO: Create NO_ICONS= key so these can be left set when disabling button icons
# Trivial to clear these values when NO_ICONS="true"

# Icon interface images directory.
# This can be set to a custom icon set in a folder of your choice.
# Note: trailing / is required.
IMAGE_PATH="/usr/share/images/bunsen/exit/light/"
# Button image files.
BTN_CANCELYAD="cancel-sm.png"
BTN_LOGOUT_PC="logout-sm.png"
# CURRENTLY NO FILE for BTN_LOCK_SCRN="$IMAGE_PATH/lock.png"
# Using cancel[-sm].png ../dark/ renamed & copied [or reverse].
BTN_LOCK_SCRN="lock-sm.png"
BTN_SLEEP_RAM="sleep-sm.png"
BTN_RESTARTPC="reboot-sm.png"
BTN_SHUT_DOWN="poweroff-sm.png"
BTN_HIBERNATE="hibernate-sm.png"
# CURRENTLY NO FILE BTN_HYBRIDZZZ="$IMAGE_PATH/hybrid.png"
# Using hibernate[-sm].png ../dark/ renamed & copied [or reverse].
BTN_HYBRIDZZZ="hybrid-sm.png"

# YAD tweaks
BORDERS_STD=7
BORDERS_ICON=20
# TODO: See about re-enabling the text & image on top.

# Troubleshooting :
# Some screen locking software does not listen for logind calls,
# screen locking then fails, for such screen lockers set
# LOCK_SCREEN_COMMAND="what-locks-screen  --now"
LOCK_SCREEN_COMMAND=""
# Known tested examples: "i3lock", "slock", "xsceeensaver-command -lock"

# May be useful if dialogue fails to launch because graphical session
# is detected as a TTY typically when no display manager is installed.
TTY_DETECT_OVERRIDE="false"
# When set to "true" TTY use with no arguments will break as a
# graphical user interface will be called.

########################################################################
#       Config block ends. Copy & paste block to config file.          #
########################################################################

# Usage: parse_config_vars <file>
# No arrays, just read variables individually.
# Preexisting variables will be overwritten.
parse_config_vars(){
    [[ -f $1 ]] || { echo "$1 is not a file." >&2;return 1;}
    local line key value entry_regex
    entry_regex="^[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*('[^']+'|\"[^\"]+\"|[^#]+)"
    while read -r line
    do
        [[ -n $line ]] || continue
        [[ $line =~ $entry_regex ]] || continue
        key=${BASH_REMATCH[1]}
        value=${BASH_REMATCH[2]#[\'\"]} # strip quotes
        value=${value%[\'\"]}
        value=${value%${value##*[![:blank:]]}} # strip trailing spaces
        declare -g "${key}"="${value}"
    done < "$1"
}
export -f parse_config_vars

# Load config from files, if present, otherwise use settings in head of this file.
for conffile in /usr/share/bunsen/conf.d/bl-exit.conf /etc/bl-exit/bl-exit.conf ~/.config/bl-exit/bl-exit.conf
    do
        [[ -f $conffile ]] && parse_config_vars $conffile
    done

### Usage ###
USAGE="\nbl-exit [OPTION]\n\n\
With no arguments default yad (GUI) or text menu at a TTY\n\n\
Only one argument is read, they cannot be combined\n\
-h --help\tShow this help\n\
-k --lock\tLock session\tDoes not work for a tty session\n\
-l --logout\tLogout\t\tAlso works for tty.\n\
-s --suspend\tSuspend\tState determined by ACPI S0 S1 or S3\n\
-i --hibernate\tSuspend to Disk\tRequires enough swap to store RAM\n\
-y --hybrid\tHybrid Sleep\tACPI must support sleep state S3\n\
-b --reboot\tReboot\n\
-p --poweroff\tShut down\n\n\
GUI Options\n\
-m --simple\t\t(GUI) Yad dialogue\n\
-M --simple-hibernate\t(GUI) Adds hibernate option\n\
   --simpl-all\t\t(GUI) Adds hibernate and hybrid-sleep\n\
-v --vertical\t\t(GUI) Yad stacked buttons\n\
-V --vertical-hibernate (GUI) Stacked, including hibernate\n\
   --vertical-all\t(GUI) Stacked, all available options\n
-n --icon\t\t(GUI) Row of icons\n\
-N --icon-hibernate\t(GUI) Row of icons, including hibernate\n\
   --icon-all\t\t(GUI) Row of icons, all available options\n
-c --icon-vert\t\t(GUI) Icons stacked vertically\n\
-C --icon-vert-hibernate\t(GUI) Icons stacked vertically, inc hibernate\n\
   --icon-vert-all\t\t(GUI) Icons stacked vertically, all available\n
Config options\n\
   --configure\t\tEdit config settings, set defaults etc.\n\
   --configure-system\tSystemwide settings and defaults (requires sudo)\n"

export LOCK_SCREEN_COMMAND=$LOCK_SCREEN_COMMAND

########################################################################
#                  Compatibility function details                      #
#                                                                      #
# logoutctl() takes the following `systemctl` arguments:               #
#                                                                      #
# poweroff reboot suspend hibernate hybrid-sleep                       #
# ? suspend-then-hibernate                                             #
#                                                                      #
# elogind supports it (documented), undocumented for systemd. It does  #
# _something_ on my systemd systems YMMV. Not implimented in the main  #
# script owing to not being documented by systemctl --help.            #
#                                                                      #
# Other systemctl arguments are not transferred to the elogind project #
# and will break if a similar systemctl || loginctl approach is used.  #
#                                                                      #
# Also takes $LOCK_SCREEN_COMMAND if defined in config to handle       #
# screen lockers which don't respond to `loginctl lock-session`        #
#                                                                      #
# loginctl lock-/terminate-session is handled here both to provide     #
# central yad closing and for non-standard screen-lock compatibiliy.   #
#                                                                      #
########################################################################
logoutctl(){
    if [[ ! -z $YAD_PID ]]; then
        kill -SIGUSR1 $YAD_PID
    fi
    case $1 in
        cancel )
            echo -e "\ncancelled"
            exit 0 ;;
        lock-session )
            echo -e "\n$1"
            [[ ! -z "$LOCK_SCREEN_COMMAND" ]] && $LOCK_SCREEN_COMMAND || loginctl $1 $XDG_SESSION_ID
            exit $? ;;
        terminate-session | lock-session )
            echo  -e "\n$1"
            loginctl $1 $XDG_SESSION_ID
            exit $? ;;
        suspend | hibernate | hybrid-sleep | suspend-then-hibernate | reboot | poweroff )
            echo -e "\n$1"
            # The systemd or elogind compatibility magic.   #
            [[ $(command -v systemctl) ]] && systemctl "$1" || loginctl "$1"
            exit $? ;;
    esac
}
export -f logoutctl

# Skip tty test if config option set
if [[ "$TTY_DETECT_OVERRIDE" != "true" ]]; then
    # If a yad picker or "lock" was chosen, test we're not at a TTY.
    if [[ -z $@ ]] || [[ $1 =~ (-m|--simple|-M|--simple-hibernate|--simple-all|-v|--vertical|-V|--vertical-hibernate|--vertical-all|-n|--icon|-N|--icon-hibernate|--icon-all|-c|--icon-vert|-C|--icon-vert-hibernate|--icon-vert-all|-k|--lock)$ ]]; then
        # Probably better ways, but: "Using systemd" :P Chops out 'x11;' in most DE's 'wayland;' in gnome and 'tty;' at a TTY or with no DM
        if [[ $(loginctl session-status | grep Service: | cut -d " " -f5) = 'tty;' ]]; then
            # We're at a TTY - Are we being asked to lock a TTY?
            if [[ $1 =~ (-k|--lock)$ ]]; then
                echo -e "Error: Graphical environment needed for screen locking."
                echo -e "It can be done with the vlock package installed, using the"
                echo -e "command 'vlock'. This script does not handle that case."
                echo -e "If you have a graphical environment running the probable cause"
                echo -e "of seeing this message is that no display manager is installed."
                exit 1
            fi
            # TTY exit menu.
            clear
            TTY_EXIT="Please choose an option "
            select option in Logout Sleep Hibernate Hybrid-Sleep Reboot Power-Off Quit-Dialogue
            do
                case $option in
                    Logout)        logoutctl terminate-session;;
                    Sleep)         logoutctl suspend;;
                    Hibernate)     logoutctl hibernate;;
                    Hybrid-Sleep)  logoutctl hybrid-sleep;;
                    Reboot)        logoutctl reboot;;
                    Power-Off)     logoutctl poweroff;;
                    Quit-Dialogue) break;;
                esac
            done
        fi
    fi
fi

# Default setting
if [[ -z $@ ]];then
    OP_MODE="$DEFAULT_MODE"
else
    OP_MODE=$1
fi

# switch to icons if selected
if [[ $OP_MODE =~ (-n|--icon|-N|--icon-hibernate|--icon-all|-c|--icon-vert|-C|--icon-vert-hibernate|--icon-vert-all)$ ]]; then
    # clear button text
    TXT_CANCELYAD=""
    TXT_LOGOUT_PC=""
    TXT_LOCK_SCRN=""
    TXT_SLEEP_RAM=""
    TXT_RESTARTPC=""
    TXT_SHUT_DOWN=""
    TXT_HIBERNATE=""
    TXT_HYBRIDZZZ=""
    # Switch icon set
    ICO_CANCELYAD="$IMAGE_PATH$BTN_CANCELYAD"
    ICO_LOGOUT_PC="$IMAGE_PATH$BTN_LOGOUT_PC"
    ICO_LOCK_SCRN="$IMAGE_PATH$BTN_LOCK_SCRN"
    ICO_SLEEP_RAM="$IMAGE_PATH$BTN_SLEEP_RAM"
    ICO_RESTARTPC="$IMAGE_PATH$BTN_RESTARTPC"
    ICO_SHUT_DOWN="$IMAGE_PATH$BTN_SHUT_DOWN"
    ICO_HIBERNATE="$IMAGE_PATH$BTN_HIBERNATE"
    ICO_HYBRIDZZZ="$IMAGE_PATH$BTN_HYBRIDZZZ"
fi

case $OP_MODE in
    # command line use
    -h|--help)
        echo -e "$USAGE"
        exit 0
        ;;
    -k|--lock)         logoutctl lock-session;;
    -l|--logout)       logoutctl terminate-session;;
    -s|--suspend)      logoutctl suspend;;
    -i|--hibernate)    logoutctl hibernate;;
    -y|--hybrid)       logoutctl hybrid-sleep;;
    -b|--reboot)       logoutctl reboot;;
    -p|--poweroff)     logoutctl poweroff;;
    ####################################################################
    #            GUI sections "yad hacking" starts here                #
    ####################################################################
    # TODO: Figure out producing all these from one block when done it #
    #       should be possible to enable or disable whatever buttons   #
    #       are desired in the config file.                            #
    ####################################################################
    # GUI
    -m|--simple|-v|--vertical|-n|--icon|-c|--icon-vert)
        COLUMNS=6
        BORDERS="$BORDERS_STD"
        [[ -z $TXT_ALIGN ]] && TXT_ALIGN="center"
        [[ $OP_MODE =~ (-n|--icon)$ ]] && BORDERS=$BORDERS_ICON
        [[ $OP_MODE =~ (-v|--vertical|-c|--icon-vert)$ ]] && COLUMNS=1
        yad --form --columns=$COLUMNS --borders=$BORDERS --class=WmanExit \
            --no-buttons --undecorated --center --on-top --skip-taskbar \
            --field="$TXT_CANCELYAD!$ICO_CANCELYAD!$TIP_CANCELYAD":fbtn 'bash -c "logoutctl cancel"' \
            --field="$TXT_LOCK_SCRN!$ICO_LOCK_SCRN!$TIP_LOCK_SCRN":fbtn 'bash -c "logoutctl lock-session"' \
            --field="$TXT_LOGOUT_PC!$ICO_LOGOUT_PC!$TIP_LOGOUT_PC":fbtn 'bash -c "logoutctl terminate-session"' \
            --field="$TXT_SLEEP_RAM!$ICO_SLEEP_RAM!$TIP_SLEEP_RAM":fbtn 'bash -c "logoutctl suspend"' \
            --field="$TXT_RESTARTPC!$ICO_RESTARTPC!$TIP_RESTARTPC":fbtn 'bash -c "logoutctl reboot"' \
            --field="$TXT_SHUT_DOWN!$ICO_SHUT_DOWN!$TIP_SHUT_DOWN":fbtn 'bash -c "logoutctl poweroff"' \
            | grep -v "|" &
        exit 0
        ;;
    # GUI with hibernate
    -M|--simple-hibernate|-V|--vertical-hibernate|-N|--icon-hibernate|-C|--icon-vert-hibernate)
        COLUMNS=7
        BORDERS="$BORDERS_STD"
        [[ -z $TXT_ALIGN ]] && TXT_ALIGN="center"
        [[ $OP_MODE =~ (-N|--icon-hibernate)$ ]] && BORDERS=$BORDERS_ICON
        [[ $OP_MODE =~ (-V|--vertical-hibernate|-C|--icon-vert-hibernate)$ ]] && COLUMNS=1
        yad --form --columns=$COLUMNS --borders=$BORDERS --class=WmanExit \
            --no-buttons --undecorated --center --on-top --skip-taskbar \
            --field="$TXT_CANCELYAD!$ICO_CANCELYAD!$TIP_CANCELYAD":fbtn 'bash -c "logoutctl cancel"' \
            --field="$TXT_LOCK_SCRN!$ICO_LOCK_SCRN!$TIP_LOCK_SCRN":fbtn 'bash -c "logoutctl lock-session"' \
            --field="$TXT_LOGOUT_PC!$ICO_LOGOUT_PC!$TIP_LOGOUT_PC":fbtn 'bash -c "logoutctl terminate-session"' \
            --field="$TXT_SLEEP_RAM!$ICO_SLEEP_RAM!$TIP_SLEEP_RAM":fbtn 'bash -c "logoutctl suspend"' \
            --field="$TXT_HIBERNATE!$ICO_HIBERNATE!$TIP_HIBERNATE":fbtn 'bash -c "logoutctl hibernate"' \
            --field="$TXT_RESTARTPC!$ICO_RESTARTPC!$TIP_RESTARTPC":fbtn 'bash -c "logoutctl reboot"' \
            --field="$TXT_SHUT_DOWN!$ICO_SHUT_DOWN!$TIP_SHUT_DOWN":fbtn 'bash -c "logoutctl poweroff"' \
            | grep -v "|" &
        exit 0
        ;;
    # GUI all available buttons
    --simple-all|--vertical-all|--icon-all|--icon-vert-all)
        COLUMNS=8
        BORDERS="$BORDERS_STD"
        [[ -z $TXT_ALIGN ]] && TXT_ALIGN="center"
        [[ $OP_MODE =~ (--icon-all)$ ]] && BORDERS=$BORDERS_ICON
        [[ $OP_MODE =~ (--vertical-all|--icon-vert-all)$ ]] && COLUMNS=1
        yad --form --columns=$COLUMNS --borders=$BORDERS --class=WmanExit \
            --no-buttons --undecorated --center --on-top --skip-taskbar \
            --field="$TXT_CANCELYAD!$ICO_CANCELYAD!$TIP_CANCELYAD":fbtn 'bash -c "logoutctl cancel"' \
            --field="$TXT_LOCK_SCRN!$ICO_LOCK_SCRN!$TIP_LOCK_SCRN":fbtn 'bash -c "logoutctl lock-session"' \
            --field="$TXT_LOGOUT_PC!$ICO_LOGOUT_PC!$TIP_LOGOUT_PC":fbtn 'bash -c "logoutctl terminate-session"' \
            --field="$TXT_SLEEP_RAM!$ICO_SLEEP_RAM!$TIP_SLEEP_RAM":fbtn 'bash -c "logoutctl suspend"' \
            --field="$TXT_HYBRIDZZZ!$ICO_HYBRIDZZZ!$TIP_HYBRIDZZZ":fbtn 'bash -c "logoutctl hybrid-sleep"' \
            --field="$TXT_HIBERNATE!$ICO_HIBERNATE!$TIP_HIBERNATE":fbtn 'bash -c "logoutctl hibernate"' \
            --field="$TXT_RESTARTPC!$ICO_RESTARTPC!$TIP_RESTARTPC":fbtn 'bash -c "logoutctl reboot"' \
            --field="$TXT_SHUT_DOWN!$ICO_SHUT_DOWN!$TIP_SHUT_DOWN":fbtn 'bash -c "logoutctl poweroff"'\
            | grep -v "|" &
        exit 0
        ;;
    # Config handling
    --configure)
        # First see if we have a config file under ~ already, edit it if we have
        if [[ ! -f ~/.config/bl-exit/bl-exit.conf ]]; then
            # We don't have one already, check for one to copy:
            if [[ -f /etc/bl-exit/bl-exit.conf ]]; then
                # Copy the local admin one:
                cp /etc/bl-exit/bl-exit.conf ~/.config/bl-exit/bl-exit.conf
            # On failure try the distro one:
            elif [[ -f /usr/share/bunsen/conf.d/bl-exit.conf ]]; then
                # Copy that one instead:
                cp /usr/share/bunsen/conf.d/bl-exit.conf ~/.config/bl-exit/bl-exit.conf
            # On failure, we don't have one to copy:
            else
                # I could make this write one, but it'd mean storing
                # that in the script too and working around quotation
                # marks and $VARIABLES as the thing gets `cat` to its
                # new home, dunnit before but YUK!
                echo "Error, no baseline config file exists!"
                echo "Using internal defaults."
                exit 1
            fi
        fi
        # We either have a user config file now, or bombed out.
        USEREDIT="Please choose editor: "
            select option in nano Geany Quit
            do
                case $option in
                    nano)  nano -Swl ~/.config/bl-exit/bl-exit.conf;;
                    Geany) geany ~/.config/bl-exit/bl-exit.conf && break;;
                    Quit) break;;
                esac
            done
        exit 0
        ;;
    # Config system
    --configure-system)
        # See if we already have a file create if not
        if [[ ! -f /etc/bl-exit/bl-exit.conf ]]; then
            # See if there's a distro file
            echo "No config file found, attempting to copy distribution"
            echo "settings, if found you will be asked for your password."
            if [[ -f /usr/share/bunsen/conf.d/bl-exit.conf ]]; then
                # In case the parent directory is not present
                [[ -d /etc/bl-exit ]] || sudo mkdir -p /etc/bl-exit
                sudo cp /usr/share/bunsen/conf.d/bl-exit.conf /etc/bl-exit/bl-exit.conf
            else
                # I could make this write one, but it'd mean storing
                # that in the script too and working around quotation
                # marks and $VARIABLES as the thing gets `cat` to its
                # new home, dunnit before but YUK!
                echo "Error, no baseline config file exists!"
                echo "Using internal defaults."
               exit 1
            fi
        fi
        # We found or created /etc/bunsen/bl-exit.conf edit it
        ADMINEDIT="Please choose editor, you may be asked for your password:"
            select option in nano Geany Quit
            do
                case $option in
                    nano)  sudo nano -Swl /etc/bl-exit/bl-exit.conf;;
                    Geany) pkexec bl-text-editor /etc/bl-exit/bl-exit.conf && break;;
                    Quit) break;;
                esac
            done
        exit 0
        ;;
    # typo land
    *)
        echo -e "\nUnknown operation $1"
        echo -e "$USAGE"
        exit 1
        ;;
esac

########################################################################
##                                                                    ##
## Version: 0.4~alpha-1                                               ##
##                                                                    ##
## Depends: bash,systemd | elogind,policykit-1                        ##
##                                                                    ##
## Recommends: yad,light-locker,x-display-manager                     ##
##                                                                    ##
## Note: re "Depends:" `systemctl` requires root or sudo unless       ##
##       policykit-1 is silently providing it.                        ##
##       yad not a hard depend because command line use is possible   ##
##       without it.                                                  ##
##                                                                    ##
## KNOWN ISSUES: "Icon" interface has no available icons for          ##
##               lock-session or hybrid-sleep.                        ##
##                                                                    ##
## BUGS: Probably.                                                    ##
##                                                                    ##
## Customization: Copy to ~/bin Then hack away `man yad` is more use  ##
##                than any help file or manual page I could write.    ##
##                                                                    ##
## Dedicated to: Debian Ecosystem Init Diversity Team                 ##
##               <debian-init-diversity@chiark.greenend.org.uk>       ##
##               May their efforts meet with every success.           ##
##                                                                    ##
########################################################################

########################################################################
#                                                                      #
#                             Change Log                               #
#                                                                      #
########################################################################
#                                                                      #
# Version: 0.4~alpha-1                                                 #
#          Added vertical icons GUI, GUI options now doubled since 0.2 #
#          Added config parser to read external config files.          #
#          Added command line options to edit .conf config files.      #
#                bl-exit.conf chosen so as not to clash with bl-exitrc #
#                for testing.                                          #
#          Updated hard-coded config to include guidance and an        #
#              example of customized settings, so it can be copied to  #
#              a file in an appropriate location as a block.           #
#                                                                      #
# Version: 0.3~alpha-1                                                 #
#          Place config options together.                              #
#          Config for option for previously troublesome lockers.       #
#              (slock i3lock and xscreenaver)                          #
#          Override for TTY detection for no display manager.          #
#          Reduce code repetition.                                     #
#          Provide icon-only interface options.                        #
#          Rationalize command-line arguments only long arguments to   #
#              show hybrid-sleep GUI options. Who uses that?           #
#          Removed text and image from yad header. Causing issues.     #
#              (May revisit)                                           #
#                                                                      #
# Version: 0.2~alpha-1                                                 #
#          Added keyboard accelerators.                                #
#          Fixed typo on one button.                                   #
#                                                                      #
# Version: 0.1~alpha-1                                                 #
#          Initial script.                                             #
#                                                                      #
########################################################################

You still get to pick your interface with "exactly one argument", so no parsing those required tongue

Last edited by Bearded_Blunder (2019-03-09 23:30:22)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#110 2019-03-09 23:29:11

Sector11
The Tpyo Knig Mod
From: 77345 ¡#
Registered: 2015-08-20
Posts: 5,443

Re: bl-exit replacement suggestions

Well, that's KISS! roll

Just pullin' yur le...beard B_B

Keep It Short n Simple


BunsenLabs Forum Rules ---== I'm a Conky 1.9'er ==---
System:    Host: d67 Kernel: 4.9.0-9-amd64 x86_64 (64 bit gcc: 6.3.0)
Desktop: Openbox 3.6.1 Distro: Debian GNU/Linux 9 (stretch)

Offline

#111 2019-03-09 23:31:35

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

Hey.. the minimal version i posted up the ways *works* tongue, it's having choices that complicates it.


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#112 2019-03-09 23:35:26

damo
....moderator....
Registered: 2015-08-20
Posts: 5,006

Re: bl-exit replacement suggestions

Nice idea. You could also source the font so you don't have the code repetition. It also means the user only has to change it in one place, eg

FONT="'Noto Sans Mono'"

then

TXT_CANCELYAD="<span font=$FONT> _Cancel   </span>"
etc

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#113 2019-03-09 23:37:15

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

I could, but then I might want logout & lock in italic and other buttons not, if i source the font....
Similar for colours.. I might want the power ones with red text ...

Last edited by Bearded_Blunder (2019-03-09 23:39:04)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#114 2019-03-09 23:45:02

Sector11
The Tpyo Knig Mod
From: 77345 ¡#
Registered: 2015-08-20
Posts: 5,443

Re: bl-exit replacement suggestions

Bearded_Blunder wrote:

Hey.. the minimal version i posted up the ways *works* tongue, it's having choices that complicates it.

Yes I'll give you that ... that's why I said:

Just pullin' yur le...beard B_B


BunsenLabs Forum Rules ---== I'm a Conky 1.9'er ==---
System:    Host: d67 Kernel: 4.9.0-9-amd64 x86_64 (64 bit gcc: 6.3.0)
Desktop: Openbox 3.6.1 Distro: Debian GNU/Linux 9 (stretch)

Offline

#115 2019-03-09 23:49:03

damo
....moderator....
Registered: 2015-08-20
Posts: 5,006

Re: bl-exit replacement suggestions

So you could have FONT_1, FONT_2, FONT_3 etc, then like in a conky change the font on the fly when needed

FONT="$FONT_1"
TXT_CANCELYAD="<span font=$FONT> _Cancel   </span>"

FONT="$FONT_2"

Same for colours


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#116 2019-03-09 23:49:20

hhh
Meep!
Registered: 2015-09-17
Posts: 8,059
Website

Re: bl-exit replacement suggestions

A question about the original script... I wanted it to open faster, so I commented out this section...

####Commented out by hhh
# If a yad picker or "lock" was chosen, test we're not at a TTY.
#if [[ -z $@ ]] || [[ $1 =~ (-m|--simple|-d|--show-hibernate|-a|--show-all|-v|--vertical|-D|--vertical-hibernate|-A|--vertical-all|-k|--#lock)$ ]]; then
    # Probably better ways, but: "Using systemd" :P Chops out 'x11;' in most DE's 'wayland;' in gnome and 'tty;' at a TTY or with no DM
#    if [[ $(loginctl session-status | grep Service: | cut -d " " -f5) = 'tty;' ]]; then
#         # We're at a TTY - Are we being asked to lock a TTY?
#         if [[ $1 =~ (-k|--lock)$ ]]; then
#             echo -e "Error: Graphical environment needed for screen locking."
#             echo -e "It can be done with the vlock package installed, using the"
#             echo -e "command 'vlock'. This script does not handle that case."
#             echo -e "If you have a graphical environment a possible cause of seeing"
#             echo -e "this message is that no Display Manager is installed."
#             exit 1
#         fi
#         # TTY exit menu.
#         clear
#         TTY_EXIT="Please choose an option "
#         select option in Logout Sleep Hibernate Hybrid-Sleep Reboot Power-Off Quit-Dialogue
#         do
#         case $option in
#             Logout)        logoutctl terminate-session;;
#             Sleep)         logoutctl suspend;;
#             Hibernate)     logoutctl hibernate;;
#             Hybrid-Sleep)  logoutctl hybrid-sleep;;
#             Reboot)        logoutctl reboot;;
#             Power-Off)     logoutctl poweroff;;
#             Quit-Dialogue) break;;
#         esac
#    done
#    fi
#fi

This indeed does make it start noticeably faster on my desktop, opening the window nearly instantly now. What exactly have I commented out? I rarely switch to TTY, and I only either switch back to the DM or sudo reboot from it, so I'm all good leaving this out, yes?

Offline

#117 2019-03-09 23:55:24

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

So I could, thing is, I suspect most users will be content with just changing the default mode & maybe uncommenting those example blocks, be interested in @hhh's verdict on how that loooks / performs, I suspect the Canel line will get removed in that particular case from the yad blocks...

The ones that aren't content, well that code repetition isn't as bad as it looks ctrl+v is less keystrokes than $FONT tongue


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#118 2019-03-09 23:55:27

damo
....moderator....
Registered: 2015-08-20
Posts: 5,006

Re: bl-exit replacement suggestions

There are a lot of unecessary echo calls, although whether that will affect the speed much I don't know. You can do it with just one:

TEXT='Error: Graphical environment needed for screen locking.
It can be done with the vlock package installed, using the
command 'vlock'. This script does not handle that case.
If you have a graphical environment a possible cause of seeing
this message is that no Display Manager is installed.'

echo "$TEXT"

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#119 2019-03-09 23:58:26

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

@hhh You've commented out a test for a corner case, someone with no DM installed.
It's completely irrelevant for users with the default setup.

You should be able to achieve the same in the new script by setting:
TTY_DETECT_OVERRIDE="true"

Last edited by Bearded_Blunder (2019-03-10 00:00:18)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#120 2019-03-09 23:59:08

hhh
Meep!
Registered: 2015-09-17
Posts: 8,059
Website

Re: bl-exit replacement suggestions

I gather then that in my user-case that block is unneeded. Config noted (nice), thanks BB!

Offline

#121 2019-03-10 00:02:12

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

It's only there for the likes of HoaS who rip out lightdm, it's unneeded in 90%+ cases, I like covering corner cases though.
TTY_DETECT_OVERRIDE="true" might be set per default to speed things up.

I basically enclosed the same block in an if ;then to bypass it.

It'll be the actual test taking the time finding out if the session is described as x11; or tty; anyone not wanting to use the tty menu ( pretty much everyone) doesn't really need it. Corner cases.. real tiny minorities.

Heck, it could be removed, current bl-exit performs no such test, I've seen no complaints that calling it with no arguments at a tty without x running breaks.. it's *that* small a minority I'm covering.

*adds rename key to DISABLE_TTY_MENU  && update # Comment: To "TODO:" & makes note to set it "true" per default*
Plus as noted in comments # Probably better ways to do this... (paraphrase)
parsing `loginctl session-status` isn't *fast* because of the parsing or the output being parsed I couldn't say, nor am I interested enough to interpose `time` for each to find out.... was an exercise in "using systemd", hence specifically slow as a result of systemd bloat && mission creep...

Last edited by Bearded_Blunder (2019-03-10 01:52:33)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#122 2019-03-10 03:29:30

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

I'm actually quite happy for whatever @damo produces to be adopted, just so long as the elogind compatibility is included, oddly I really do dislike systemd, and I need no more "technical" reason for that than a 6yo requires for disliking broccoli or brussels-sprouts!


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#123 2019-03-11 00:40:37

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

hhh wrote:

A question about the original script... I wanted it to open faster, so I commented out this section...

####Commented out by hhh
# If a yad picker or "lock" was chosen, test we're not at a TTY.
#if [[ -z $@ ]] || [[ $1 =~ (-m|--simple|-d|--show-hibernate|-a|--show-all|-v|--vertical|-D|--vertical-hibernate|-A|--vertical-all|-k|--#lock)$ ]]; then
    # Probably better ways, but: "Using systemd" :P Chops out 'x11;' in most DE's 'wayland;' in gnome and 'tty;' at a TTY or with no DM
#    if [[ $(loginctl session-status | grep Service: | cut -d " " -f5) = 'tty;' ]]; then
#         # We're at a TTY - Are we being asked to lock a TTY?
#         if [[ $1 =~ (-k|--lock)$ ]]; then
#             echo -e "Error: Graphical environment needed for screen locking."
#             echo -e "It can be done with the vlock package installed, using the"
#             echo -e "command 'vlock'. This script does not handle that case."
#             echo -e "If you have a graphical environment a possible cause of seeing"
#             echo -e "this message is that no Display Manager is installed."
#             exit 1
#         fi
#         # TTY exit menu.
#         clear
#         TTY_EXIT="Please choose an option "
#         select option in Logout Sleep Hibernate Hybrid-Sleep Reboot Power-Off Quit-Dialogue
#         do
#         case $option in
#             Logout)        logoutctl terminate-session;;
#             Sleep)         logoutctl suspend;;
#             Hibernate)     logoutctl hibernate;;
#             Hybrid-Sleep)  logoutctl hybrid-sleep;;
#             Reboot)        logoutctl reboot;;
#             Power-Off)     logoutctl poweroff;;
#             Quit-Dialogue) break;;
#         esac
#    done
#    fi
#fi

This indeed does make it start noticeably faster on my desktop, opening the window nearly instantly now. What exactly have I commented out? I rarely switch to TTY, and I only either switch back to the DM or sudo reboot from it, so I'm all good leaving this out, yes?

That section could be tweaked, and actually needs a very minor addition., I've already given an option to bypass it.
I did say "# Probably better ways, but: "Using systemd""
So here's how it would look without spawning loginctl, grep & cut which ought to speed it up
i.e. one of the better ways:

        # Probably better ways, but: "Using systemd" :P Chops out 'x11;' in most DE's 'wayland;' in gnome and 'tty;' at a TTY or with no DM
        if [[ $(loginctl session-status | grep Service: | cut -d " " -f5) = 'tty;' ]]; then

Becomes:

          # $XDG_SESSION_TYPE is unset at a tty (or with no DM)
          if [[ -z $XDG_SESSION_TYPE ]]; then

Also.... BUGFIX

                    Quit-Dialogue) break;;
                esac
            done
        fi

Becomes:

                    Quit-Dialogue) break;;
                esac
            done
            exit 0
        fi

Else we end up trying to spawn yad at a tty after some options.
At least the (verbose) comments allowed you to identify a section you didn't really need :-) that whole chunk is pure embellishment.

Last edited by Bearded_Blunder (2019-03-11 01:05:28)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#124 2019-03-13 02:15:03

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 5,575
Website

Re: bl-exit replacement suggestions

Following this thread with great interest.

Bearded_Blunder wrote:

It's only there for the likes of HoaS who rip out lightdm, it's unneeded in 90%+ cases, I like covering corner cases though.
TTY_DETECT_OVERRIDE="true" might be set per default to speed things up.

I basically enclosed the same block in an if ;then to bypass it.

It'll be the actual test taking the time finding out if the session is described as x11; or tty; anyone not wanting to use the tty menu ( pretty much everyone) doesn't really need it.

How would it be to just exit with your informative error message if there's no X session running? (At least when bl-exit is called with no tty-consistent arguments.) The most popular way to test for an X session is to look at $DISPLAY, though that variable can sometimes be incorrectly set. (Another one is $XAUTHORITY. Both those tests are independent of systemd.) Your test with loginctl runs fast enough for me (9ms) - I guess that was indeed the reason for the delay hhh got?

Last edited by johnraff (2019-03-13 02:59:02)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#125 2019-03-15 00:57:25

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 730

Re: bl-exit replacement suggestions

I've no feedback with regards to if it's my loginctl test or the long-string-of-goods-wagons I'm checking from @hhh as to which is the cause of the delay in their case, I'm certainly not wedded to any particular test with regards to if an X or Wayland session is running, If it's the test of command arguments that's causing the delay i.e.

if [[ -z $@ ]] || [[ $1 =~ (-m|--simple|-d|--show-hibernate|-a|--show-all|-v|--vertical|-D|--vertical-hibernate|-A|--vertical-all|-k|--#lock)$ ]]; then

I'm willing to edit to make a short test a subcase of casse $1 == *

I've also looked into trying to make a reduction in arguments possible, and more options possible as bl-exit.conf options, for example enabling or disabling e.g cancel (use esc or alt+f4 buttons instead) and or sleep/lock buttons config.file options, though doing so at *my level* of skills with bash/yad might involve increased code duplication.

Basically I'm willing to put some effort into further refining this with regards to my own efforts, but I'd appreciate more feedback.

I'm not seeing much difference in speed in my own VM testing with regards to how an X/Wayland session is determined, versus ignoring that one isn't available for yad, so I'm relying on @hhh who's commented on that difference for some feedback.

What practical difference is there for instance with regards to various methods in determining in a graphical session is running, and what would be ($DISPPLAY $XDG_SESSION_TYPE $OTHER_TEST), and  the *ideal* other options to have available??? I note @hhh's screen-shots always seem to indicate @hhh deletes the yad line generating the "Cancel" button (something *MY* skills would involve increasing code repetition to allow. I *have* noted @damo's comment regarding font specification, and whilst I put a case against it, I'm again not wedded to that, I really only care with regard to being init-agnostic...

I *do* have a strategy in mind which would make eg cancel, lock. and other "on-essential" buttons optional, but my testing indicates that it would make the script longer with more "mostly identical but longer/shorter" yad blocks....

I'm happy to put in more work into *my version* of this, but I'm reluctant to *guess* as far as what might be preferred is concerned.

I have little idea with regards to the packaging or dealing with conflicts with the old package, else I might be persuaded to maintain the entire thing as the maintainer of the old package seems unwilling to do, I wish I felt my skills were up to it and much respect for @johnraff that he can.

Last edited by Bearded_Blunder (2019-03-15 01:34:41)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

Board footer

Powered by FluxBB