From b00283d5516372a591d8fce5c0aeadacaeabc109 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Fri, 14 Jun 2019 08:25:11 +1000 Subject: [PATCH] gnome-terminal preserve working directory when opening new terminals --- .bashrc | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/.bashrc b/.bashrc index 5d2f8b2..7dd7476 100644 --- a/.bashrc +++ b/.bashrc @@ -42,6 +42,18 @@ if [ -z "${PS1}" ]; then fi +################ +# Source files # +################ + +# Debian/Ubuntu don't source this from /etc/bash.bashrc +[ -z "$BASH_COMPLETION_VERSINFO" ] && [ -r /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion + +# This isn't sourced for interactive shells on Debian/Ubuntu/Arch +# https://bugzilla.gnome.org/show_bug.cgi?id=697475 +[ -r /etc/profile.d/vte.sh ] && source /etc/profile.d/vte.sh + + ################ # bash options # ################ @@ -62,8 +74,6 @@ export HISTCONTROL='erasedups:ignoredups:ignorespace' export HISTSIZE='100000' export HISTTIMEFORMAT='%F %T ' -[ -r /etc/bash_completion ] && source /etc/bash_completion - ############### # Pager setup # @@ -185,6 +195,7 @@ alias ll='ls -hlF' alias la='ls -ha' alias l='ls -halF' + ############## # ps aliases # ############## @@ -288,9 +299,9 @@ fi [ -r ~/.bashrc_local ] && source ~/.bashrc_local -################## -# xterm titlebar # -################## +######################## +# Terminal integration # +######################## # When at a prompt display `workingdir (hostname)` function print_title_prompt { @@ -302,7 +313,18 @@ function print_title_prompt { printf '\ekbash\e\\' fi } -PROMPT_COMMAND=print_title_prompt + +# Preserve working directory when opening new terminals +# This depends on /etc/profile/vte.sh +function record_terminal_cwd { + [ "$(type -t __vte_osc7)" = "function" ] && __vte_osc7 || true +} + +function prompt_command { + print_title_prompt + record_terminal_cwd +} +PROMPT_COMMAND=prompt_command # Display the command about to be executed. This must go at the end of the # bashrc to avoid running the trap on commands in the bashrc -- 2.39.2