From 2e927c89e74e502e6b4df60583bcab0acec72d2b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 7 Nov 2019 14:56:08 +0100 Subject: [PATCH] [UPDATE][SCRIPT] Use expansion for PROMPT_COMMAND It seems like the idiomatic way to update $PROMPT_COMMAND is to use variable expansion to add a semi-colon and a space before the command we're adding. I also switched from prepending my commands to appending them, which allows overriding behaviour, such as terminal titles which could be set from system files. --- scripts/localrc | 2 +- scripts/term-title | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/localrc b/scripts/localrc index cc5b0ef..1455604 100755 --- a/scripts/localrc +++ b/scripts/localrc @@ -110,7 +110,7 @@ function __source_localrc_files() { # Execute this command every time if [ -n "$BASH_VERSION" ]; then [ -n "${DEBUG_LOCALRC+set}" ] && echo "Loaded Bash" - PROMPT_COMMAND="__source_localrc_files; $PROMPT_COMMAND" + PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }__source_localrc_files" elif [ -n "$ZSH_VERSION" ]; then [ -n "${DEBUG_LOCALRC+set}" ] && echo "Loaded Zsh" precmd_functions+=( __source_localrc_files) diff --git a/scripts/term-title b/scripts/term-title index 3e47aa8..a7b6846 100644 --- a/scripts/term-title +++ b/scripts/term-title @@ -36,7 +36,7 @@ __term_title_prompt_command() { case "$TERM" in xterm*|term_title*) - [ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__term_title_prompt_command;$PROMPT_COMMAND" + [ -n "$BASH_VERSION" ] && PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }__term_title_prompt_command" [ -n "$ZSH_VERSION" ] && precmd_functions+=(__term_title_prompt_command) ;; esac