Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
158 changes: 93 additions & 65 deletions yakuake-session
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,52 @@ function show_help() {
Usage: $PROGRAM_NAME [options] [args]

Options:
--help Show help about options.
-e <cmd> 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 <dir> Set the working directory of the new tab to 'dir'
--hold, --noclose Do not close the session automatically when the command ends.
-p <property=value> Change the value of a profile property (only for KDE 4).
-q Do not open yakuake window.
-t <title> 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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down