Skip to content

Make the shell prompt $PS1 distinguishable from the host shell #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AkihiroSuda opened this issue Nov 22, 2021 · 14 comments · Fixed by #433
Closed

Make the shell prompt $PS1 distinguishable from the host shell #427

AkihiroSuda opened this issue Nov 22, 2021 · 14 comments · Fixed by #433
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@AkihiroSuda
Copy link
Member

Maybe we should change the color of $PS1 by default

@AkihiroSuda AkihiroSuda added enhancement New feature or request good first issue Good for newcomers labels Nov 22, 2021
@afbjorklund
Copy link
Member

afbjorklund commented Nov 22, 2021

I themed my login shell, so when I get default one I know it is another server 🙃

Both lima and docker (et al) do set the host name, but maybe a color clue could help

@afbjorklund
Copy link
Member

Currently it is up to the Linux distribution, right ?

@AkihiroSuda
Copy link
Member Author

but maybe a color clue could help

Yes, the color should be probably lime 💚 (#268)

Currently it is up to the Linux distribution, right ?

Yes

@afbjorklund
Copy link
Member

afbjorklund commented Nov 22, 2021

For reference, the ubuntu prompt is:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

It doesn't have any special 256-color prompt.

For lima, that is the difference between "green" and "lime".

https://en.wikipedia.org/wiki/Lime_(color) says #BFFF00

It seems like color 154 would be the closest, in 256 colors ?

echo -e "\\033[38;5;154mlima\\033[0m"

See https://github.com/termstandard/colors for true color (888)

"Having an extra environment variable (separate from TERM) is not ideal:
by default it is not forwarded via sudo, ssh, etc,
and so it may still be unreliable even where support is available in programs."

@afbjorklund
Copy link
Member

afbjorklund commented Nov 22, 2021

Here is one to try:

GNOME (24-bit)

#BFFF00 "lime"

PS1='\[\033[38;2;192;255;0m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

COLORTERM=truecolor

xterm-256color

#AFFF00 "154"

PS1='\[\033[38;5;154m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

TERM=xterm-256color

xterm (16 colors)

#00FF00 "bright green"

PS1='\[\033[01;92m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

"$color_prompt" = yes

monochrome

PS1='\u@\h:\w\$ '

"$color_prompt" = no


What they look like in Ubuntu:

lima-shell-color-prompt

From default green, over to lime.

@afbjorklund
Copy link
Member

afbjorklund commented Nov 22, 2021

Apparently, one needs to change both ssh_config and sshd_config to transfer COLORTERM too:

SendEnv LANG LC_*

AcceptEnv LANG LC_*

And in the default setting, the lima vm will switch to monochrome for root (possibly a feature?)

lima-root

@jandubois
Copy link
Member

I feel like this is an issue best left to the users themselves. It is no different than configuring a shell prompt on any of your other physical or virtual machines you connect to via ssh.

And there are myriad ways to do this, including:

  • setting COLORTERM via env in your lima.yaml
  • set up something with a provisioning script
  • creating a symlink to a .profile etc. on your host
  • terminal profile switching

So any hardcoded mechanism is bound to not satisfy lots of users. I think it would be best to show some examples of setting this up in the FAQ, or in the sample config files, but leave the default prompt(s) to whatever the distro does.

@afbjorklund
Copy link
Member

afbjorklund commented Nov 23, 2021

The suggestion was just to change from Ubuntu "green" to Lima "lime", for the default distribution.

The feature to add COLORTERM to limactl shell environment is separate, but still a good idea ?


Other distros (including ubuntu.yaml) would keep their default colors ? See systemd's ANSI_COLOR

https://www.freedesktop.org/software/systemd/man/os-release.html#ANSI_COLOR= (and their PS1)

@jandubois
Copy link
Member

Replacing the default green with a lime shade is fine with me. But otherwise I'm going to stay out of this; I worry that this can turn into endless bike-shedding.

@afbjorklund
Copy link
Member

afbjorklund commented Nov 23, 2021

BTW: For alpine, you need to source /etc/profile.d/color_prompt.sh.disabled (or enable it, by renaming)

# Setup a red prompt for root and a green one for users.
# rename this file to color_prompt.sh to actually enable it

Looks like for alpine-lima, it had been renamed to /etc/profile.d/color_prompt. Still means disabled, though...

for script in /etc/profile.d/*.sh ; do
        if [ -r $script ] ; then
                . $script
        fi
done

@jandubois
Copy link
Member

Looks like for alpine-lima, it had been renamed to /etc/profile.d/color_prompt. Still means disabled, though...

I guess it is a bug in Alpine 3.13. In 3.14 it is called color_prompt.sh.disabled. I can rename it in lima-init, if we want to, or we could do the renaming in a provisioning script in examples/alpine.yaml.

I have a slight preference to do it in lima-init, but don't really care too much.

@afbjorklund
Copy link
Member

You can probably leave it as-is, it's just a version difference: https://gitlab.alpinelinux.org/alpine/aports/-/issues/6933

It's rather ugly, so I don't think you want to enable it by default ?

@afbjorklund
Copy link
Member

afbjorklund commented Nov 25, 2021

Feedback on the PR wonders if something should be done for monochrome terminals ?

lima-monochrome

Like adding something to the beginning of the prompt, or whatever. Otherwise, it "works"

lima-truecolor


There might be some usability issues with "light" theme instead of "dark" theme, here Tango:

lima-light

But I'm not sure if there is anything that can be done to detect that setting automatically ?

lima-color

Opting out of the (hardcoded) lime colors makes it legible, but the green and blue are better...

Would be interesting to know how it works with macOS Terminal.app, I think that was light too ?

@afbjorklund
Copy link
Member

afbjorklund commented Nov 28, 2021

I added some code (48db8c7), to only use the lima color when running with a dark theme:

Tango dark
lima-termtheme-dark

Tango light
lima-termtheme-light

See github.com/afbjorklund/go-termbg/pkg/termbg for the detection, ported from a rust lib...

Check terminal background color
  Term : XtermCompatible
  Color: R=3030, G=a0a, B=2424
  Theme: Dark

It works with most of the terminals. Unfortunately there are some Mac issues, needs darwin:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants