diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-09 14:19:10 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-09 14:19:10 +1200 |
commit | dba9fd867350c9203bf93ef485c89e0dcc5197d2 (patch) | |
tree | b2bb1ad7357f66b8c47e22c84be333e3751e5cc9 | |
parent | Use two more history options (diff) | |
download | dotfiles-dba9fd867350c9203bf93ef485c89e0dcc5197d2.tar.gz dotfiles-dba9fd867350c9203bf93ef485c89e0dcc5197d2.zip |
Allow PROMPT_PREFIX and PROMPT_SUFFIX
Also break the prompt definition into multiple lines for readability
-rw-r--r-- | README.markdown | 3 | ||||
-rw-r--r-- | bash/bashrc.d/prompt.bash | 13 |
2 files changed, 14 insertions, 2 deletions
diff --git a/README.markdown b/README.markdown index db9c3d0c..4f50e384 100644 --- a/README.markdown +++ b/README.markdown @@ -141,6 +141,9 @@ It expands based on context to include these elements in this order: * The number of running background jobs, if non-zero * The exit status of the last command, if non-zero +You can set `PROMPT_PREFIX` and/or `PROMPT_SUFFIX` too, which do about what +you’d expect. + This is all managed within the `prompt` function. There’s some mildly hacky logic on `tput` codes included such that it should work correctly for most common terminals using both `termcap(5)` and `terminfo(5)`, including \*BSD diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 7b12a2a2..68c8eb37 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -12,9 +12,18 @@ prompt() { # Turn complex, colored PS1 and debugging PS4 prompts on on) - # Set up pre-prompt command and prompt format + # Set up pre-prompt command PROMPT_COMMAND='declare -i PROMPT_RETURN=$? ; history -a' - PS1='[\u@\h:\w]$(prompt job)$(prompt vcs)$(prompt ret)\$' + + # Set up prompt, including optional PROMPT_PREFIX and PROMPT_SUFFIX + # variables + PS1='[\u@\h:\w]' + PS1=$PS1'$(prompt job)' + PS1=$PS1'$(prompt vcs)' + PS1=$PS1'$(prompt ret)' + PS1='$PROMPT_PREFIX'$PS1 + PS1=$PS1'$PROMPT_SUFFIX' + PS1=$PS1'\$' # If Bash 4.0 is available, trim very long paths in prompt if ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} >= 4)) ; then |