Note: Recent versions of Konsole now respect $PWD
. However, this solution may still be of use because it shows how to customize Konsole behavior. For instance, shells can be opened in tabs instead of new windows.
For several years, there has been no setting to make konsole
respect $PWD
. However, there is a command-line option --workdir
that can be exploited by a script to make konsole
function as desired.
Check the path to locate a user-accessible location that takes precedence over /usr/bin
by examining the output of echo $PATH
. Typical options include ~/bin/
and ~/.local/bin/
.
Create a file named ~/bin/konsole
(or ~/.local/bin/konsole
) with the following contents:
#!/usr/bin/env bash
# make konsole respect $PWD, as other terminals do
# save as ~/bin/konsole or ~/.local/bin/konsole
# catch unset or mis-set PWD
[[ -z $PWD ]] && PWD="$HOME"
[[ "$PWD" == '/' ]] && PWD="$HOME"
term_cls='konsole' # window class needed for xdotool to activate window
term_bin=`type -a -p konsole | tail -n 1` # location of original `konsole`
term_cmd=( "$term_bin" )
[[ $PWD ]] && term_cmd+=( --workdir "$PWD" )
term_tab=( "${term_cmd[@]}" --new-tab )
case $1 in
-h|--help|-v|--version|--author|--license|--list-profiles|--list-profile-properties)
"$term_bin" "$1"
;;
-p)
echo 'cannot change profile properties at this time'
;;
*)
find_app=( xdotool search --onlyvisible --class "$term_cls" windowactivate exec "${term_tab[@]}" )
"${find_app[@]}" || xdotool exec "${term_cmd[@]}"
;;
esac
Give the new script execute permissions.
chmod +x ~/bin/konsole
Now, whenever this script is run, it will process $PWD
and execute /usr/bin/konsole --workdir "$PWD"
. If put in the right folder, it will have priority over the real konsole
and usage will be transparent. Similar scripts can be created for other programs that do not behave as desired.