]> code.delx.au - dotfiles/commitdiff
gnome-terminal preserve working directory when opening new terminals
authorJames Bunton <jamesbunton@delx.net.au>
Thu, 13 Jun 2019 22:25:11 +0000 (08:25 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Thu, 13 Jun 2019 22:31:15 +0000 (08:31 +1000)
.bashrc

diff --git a/.bashrc b/.bashrc
index 5d2f8b203b112da43f56619898298518ab135034..7dd74762632fdf079866b1038550533be43c7dbd 100644 (file)
--- 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