+
+##################
+# Editor aliases #
+##################
+
+if emacsclient --version &> /dev/null; then
+ export ALTERNATE_EDITOR='vim'
+ export EDITOR='emacsclient --tty'
+else
+ export EDITOR='vim'
+fi
+aliasf edit "$EDITOR"
+
+
+#########################
+# Optional local config #
+#########################
+
+[ -r ~/.bashrc_local ] && source ~/.bashrc_local
+
+
+########################
+# Terminal integration #
+########################
+
+# When at a prompt display `workingdir (hostname)`
+function print_title_prompt {
+ printf '\e]0;bash:%s (%s)\a' \
+ "${PWD/$HOME/\~}" \
+ "$(hostname -s)"
+
+ if [[ "$TERM" == screen* ]]; then
+ printf '\ekbash\e\\'
+ fi
+}
+
+# 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
+function print_title_exec {
+ [ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return
+
+ printf '\e]0;%s (%s)\a' \
+ "$(tr -cd '[:graph:] ' <<< "$BASH_COMMAND")" \
+ "$(hostname -s)"
+
+ if [[ "$TERM" == screen* ]]; then
+ printf '\ek%s\e\\' \
+ "$(sed -n -e 's/sudo //' -e 's/ .*//' -e 1p <<< "$BASH_COMMAND")"
+ fi
+}
+trap print_title_exec DEBUG
+
+