pangeo-docker-images icon indicating copy to clipboard operation
pangeo-docker-images copied to clipboard

Colorize terminals even when home is overridden

Open consideRatio opened this issue 1 year ago • 3 comments

Fixes #574.

The first commit accomplishes this when this image is used in for example JupyterHub deployments where the home folder is overridden and doesn't come with /etc/skel copied files .profile and .bashrc:

Before After
image image

This PR is also bundled with an opinionated change in another a second commit. It makes an opinionated adjustment of the terminal title and prompt. The title is set to the current working directory of the terminal, and the prompt is slimmed to not include the @hostname part.

Before After
image image

consideRatio avatar Aug 21 '24 21:08 consideRatio

Binder :point_left: Try on Mybinder.org!

github-actions[bot] avatar Aug 21 '24 21:08 github-actions[bot]

Some thoughts after making this.

  1. Removing the @hostname from the prompt seemed reasonable, but I think it could be controversial - remove that change?
  2. Trickery needs to be involved if the terminal title is to be retained as Terminal 1 etc, because its overridden by /etc/skel files, so I think stripping those from username@hostname: makes sense to include in this PR.
  3. To apply or not apply the /etc/skel.bashrc stuff if a .bashrc file was found or not isn't obvious. I can imagine users are happy with colors, and then unhappy after defining a .bashrc file with some unrelated thing. Should it be applied no matter what?
  4. Similarly as point 3, should we apply the /etc/skel stuff no matter what?
  5. Should we apply /etc/skel files conditionally based on some environment variable, allowing this behavior to be opt-out or opt-in?
  6. The current form of changes is quite conservative, not doing stuff if files are found in the home dir - so maybe leaving things as the PR is ok as a starting point? At the same time... the colorizing of terminals becomes fragile, making people end up in a rabbit hole to figure out why its colored for one person but not another or similar.

consideRatio avatar Aug 22 '24 20:08 consideRatio

Sorry to have missed this @consideRatio ! Agreed colors are nice and this is better than the default! I don't really have a strong preferences regarding your questions, but an alternative is maybe just pointing to 2i2c docs to customize the terminal (since hubs might use custom images not coming from here)?

For what it's worth I've gotten quite used to copy and paste from stack overflow into ~/.bashrc whenever I log into a jupyterhub and don't find it too onerous :)

# Colors and prompt customization
# https://unix.stackexchange.com/questions/148/colorizing-your-terminal-and-shell-environment
PS1='\e[34;1m\u@\h: \e[36m\W\e[0m\$ '

#export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33'
LS_COLORS=$LS_COLORS:'di=1;35:' ; export LS_COLORS
export LS_OPTIONS='--color=auto'
alias ls='ls $LS_OPTIONS' 

scottyhq avatar Sep 05 '24 13:09 scottyhq