From 2fef0252f25fab78d168ddbf5ed13cc2a86865fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Torres?= Date: Thu, 17 Dec 2020 17:24:00 +0000 Subject: [PATCH 1/2] Fix -w option #30 --- yakuake-session | 158 ++++++++++++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 65 deletions(-) diff --git a/yakuake-session b/yakuake-session index 12e1047..a16cfce 100755 --- a/yakuake-session +++ b/yakuake-session @@ -27,22 +27,52 @@ function show_help() { Usage: $PROGRAM_NAME [options] [args] Options: - --help Show help about options. + -e Command to execute. This option will catch all following arguments, so use it as the last option. -h, --homedir Set the working directory of the new tab to the user's home. - -w, --workdir Set the working directory of the new tab to 'dir' - --hold, --noclose Do not close the session automatically when the command ends. -p Change the value of a profile property (only for KDE 4). - -q Do not open yakuake window. - -t Set the title of the new tab - -e <cmd> Command to execute. This option will catch all following arguments, so use it as the last option. + -q, --quiet Do not open yakuake window. + -t, --title <title> Set the title of the new tab. + -w, --workdir <dir> Set the working directory of the new tab to 'dir'. --fish | --nofish Override default shell autodetection to enable or disable the fish shell support. - --debug Show yakuake_session debug information. + --hold, --noclose Do not close the session automatically when the command ends. + + --help Show help about options. + -d, --debug Show yakuake_session debug information. Arguments: args Arguments passed to command (for use with -e). EOF } +# Parse command line options +function getopts() { + local option + local options=("$@") + local optind=0 + + for optind in ${!options[@]}; do + if [ "${options[$optind]}" == '-e' ]; then + break + fi + done + optind=$((optind + 1)) + + getopt \ + --name "$PROGRAM_NAME" \ + --options "hep:qt:w:d" \ + --longoptions "homedir" \ + --longoptions "quiet" \ + --longoptions "title:" \ + --longoptions "workdir:" \ + --longoptions "fish" \ + --longoptions "nofish" \ + --longoptions "hold" \ + --longoptions "noclose" \ + --longoptions "help" \ + --longoptions "debug" \ + -- "${options[@]::$optind}" '--' "${options[@]:$optind}" +} + # Functions to show error and warning messages if type -P kdialog &> /dev/null; then @@ -213,75 +243,73 @@ function yakuake_session() { local cwd="$PWD" local title='' local cmd='' + local execute=0 local hold=0 local show=1 + local options # Parse command line options - local option='' - local OPTIND=1 - local OPTARG='' - - while getopts ":-:t:p:w:he:q" option; do - case $option in - -) - case "$OPTARG" in - help) - show_help - exit 0 - ;; - homedir) - cwd="$HOME" - ;; - workdir) - cwd="${!OPTIND}" - [[ "$cwd" == -* ]] && - error_exit 1 "missing argument for option '$OPTARG'." - OPTIND=$(($OPTIND + 1)) - ;; - workdir=*) - cwd="${OPTARG#*=}" - ;; - hold|noclose) - hold=1; - ;; - fish) - FISH_SHELL=1 - ;; - nofish) - FISH_SHELL=0 - ;; - debug) - DEBUG=1 - ;; - *) - error_exit 1 "unkshown option '$OPTARG'." - ;; - esac + options=$(getopts "$@") + test "$?" -eq 0 || exit 1 + eval set -- "$options" + + while true; do + case "$1" in + '-e') + execute=1 + shift ;; - p) - add_profile_setting "$OPTARG" + '-h'|'--homedir') + cwd="$HOME" + shift ;; - e) - shift $((OPTIND-2)) - cmd=$(printf '%q ' "$@") - break + '-p') + add_profile_setting "$2" + shift 2 + ;; + '-q'|'--quiet') + show=0 + shift ;; - t) - title="$OPTARG" + '-t'|'--title') + title="$2" + shift 2 ;; - h) - cwd="$HOME" + '-w'|'--workdir') + cwd="$2" + shift 2 ;; - q) - show=0 + '--fish') + FISH_SHELL=1 + shift ;; - \?) - error_exit 1 "unkshown option '$OPTARG'." + '--nofish') + FISH_SHELL=0 + shift + ;; + '--hold'|'--noclose') + hold=1; + shift + ;; + '--help') + show_help + exit 0 + ;; + '-d'|'--debug') + DEBUG=1 + shift + ;; + '--') + shift + if [[ "$execute" == 1 && "$#" -gt 0 ]]; then + cmd=$(printf '%q ' "$@") + fi + break ;; - :) - error_exit 1 "missing argument for option '$OPTARG'." + *) + error_exit 1 'getopt internal error.' ;; - esac + esac done debug <<-EOF @@ -359,7 +387,7 @@ function yakuake_session() { } # Detect if the script was called with a different user who logged in -logged_user=$(logname) +logged_user=$(logname 2> /dev/null ) if [[ "$UID" == 0 && "$logged_user" != "$USER" ]]; then su "$logged_user" -c '"$0" "$@"' -- "$0" "$@" else From 69ae109629a750460f72db47c629b042855a22db Mon Sep 17 00:00:00 2001 From: Michael Wiebusch <stratomaster@gmx.net> Date: Thu, 24 Jun 2021 17:08:57 +0200 Subject: [PATCH 2/2] requires qdebus on my newest system Ubuntu/Mint 20 qdbus-qt5 is not installed by default and yakuake-session does nothing of value without it --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6fb52e7..de903fb 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ breaks the command `qdbus` in Kubuntu 13.04/13.10. It can be fixed installing * Requires wmctrl to change focus if yakuake is already open. Get it from the repo e.g. `apt install wmctrl` + * Requires qdbus-qt5 to connect to running yakuake. Install it, e.g. `apt install qdbus-qt5` + * Fish is not a POSIX compliant shell, so yakuake_session detects if it is the user default shell and applies some fixes. If the autodetection doesn't work properly, open the script and set the variable FISH_SHELL in the first lines to