Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 554086 - app-shells/bash: make PS1 setup more amenable to window title customization
Summary: app-shells/bash: make PS1 setup more amenable to window title customization
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Unspecified (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo's Team for Core System packages
Depends on:
Reported: 2015-07-06 17:00 UTC by Kerin Millar
Modified: 2015-09-03 07:26 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---

bash-window-title.patch (bash-window-title.patch,1.56 KB, patch)
2015-07-06 17:00 UTC, Kerin Millar
Details | Diff
bash-window-title.patch (amended) (bash-window-title.patch,1.56 KB, patch)
2015-07-06 17:09 UTC, Kerin Millar
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kerin Millar 2015-07-06 17:00:28 UTC
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/". 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 "" (which sets PROMPT_COMMAND instead).
Comment 1 Kerin Millar 2015-07-06 17:09:43 UTC
Created attachment 406264 [details, diff]
bash-window-title.patch (amended)

Same thing but prepends to PS1 as described, as opposed to appending.