Created attachment 406262 [details, diff]
Currently, /etc/bash/bashrc primes PS1 so as to define the window title before appending portion that defines the actual prompt. This makes it impossible to customize without modifying bashrc itself. It might not be immediately obvious as to why this may be awkward so I shall explain.
I manage a heterogenous environment, typically using a jump box with tmux. I do not like the default title convention in Gentoo. Instead, I just want the title to be the hostname. Therefore, I constructed a file to be sourced from /etc/bash/bashrc.d in Gentoo, and from /etc/profile.d in Ubuntu then proceeded to deploy it en masse. My method was to set PROMPT_COMMAND, like so:
# In Ubuntu, the executing shell isn't always bash so discern the shell
shell="$(/bin/ps -p $$ -o ucomm=)"
if [ "$shell" = "bash" ] && [ "$TERM" = screen ]; then
PROMPT_COMMAND="printf '\033k$(hostname -s)\033\\'"
So there's my first concern. While this worked fine in Ubuntu, the default bashrc in Gentoo prevents this particular use case because PS1 is primed with a sequence to set the title and PROMPT_COMMAND is executed before the prompt is shown.
My second concern is that, while I could just set PS1 from under /etc/bash/bashrc.d - overriding whatever it was before - I would rather not. The reason is that I am happy for the distro to construct the prompt according to its system-wide norms. I only want to override the system-wide behaviour that sets the title. Gentoo does not disambiguate these concerns.
Hence, the only way for me to go about it in the exact way that I want is to have my Puppet recipe push out a replacement /etc/bash/bashrc specifically for my Gentoo machines (removing the bits that deal with titles). This is what bothers me. I would rather be able to stick to a pattern where configuration snippets can be deployed and supplement the standard distro behaviour.
My idea is that the opinionated parts of bashrc could be migrated to default bashrc.d snippets. The advantages would be:
* Behaviour unwanted by the user can be disabled by removing the snippet
* Behaviour the user wants to override can be done by replacing the snippet (not the whole of bashrc)
* It makes for a nicer pattern in terms of cross-distro configuration management
The attached patch demonstrates the concept. It maintains the current default behaviour but does so by prepending to PS1 in "/etc/bash/bashrc.d/00-window-title.sh". Such an approach would provide for a range of methods to override or disable the behaviour. In my case, I would then deploy my replacement "00-window-title.sh" (which sets PROMPT_COMMAND instead).
Created attachment 406264 [details, diff]
Same thing but prepends to PS1 as described, as opposed to appending.