Skip to content
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

Show the PHP version in the CLI prompt #2650

Open
tomjn opened this issue Jan 3, 2023 · 12 comments
Open

Show the PHP version in the CLI prompt #2650

tomjn opened this issue Jan 3, 2023 · 12 comments

Comments

@tomjn
Copy link
Member

tomjn commented Jan 3, 2023

We should show the PHP version in the terminal prompt when you SSH into the VM so it's clear which version is being used. This also avoids confusion when people go to their site and expect PHP to be the version from the config.yml file and for the version to have automatically switched ( we don't have anything that does that currently ).

I use starship locally which does this and also prints out info on ruby/node etc depending on the current project folder, and some basic git info. Perhaps that would be a useful addition?

@pentatonicfunk
Copy link
Contributor

+1 for this,
its useful for me personally

  • optional
  • configurable

@tomjn
Copy link
Member Author

tomjn commented Jan 4, 2023

@pentatonicfunk is this a vote for starship or a vote for the PHP version in the prompt specifically? I've been hesitant to suggest changes to the prompt in the past as it's something very personal to each developer, but I realise there are usability concerns unique to VVV

@Mte90
Copy link
Member

Mte90 commented Jan 4, 2023

We already print some data on Vagrant to help debugging and I don't see an issue on the message at the login similar.
Some VPS and hostings already do that.

Maybe it's the case to do a recap of what is enabled like for the extensions?

maybe it's a text message that we can generate on provisioning to simplify it.

@tomjn
Copy link
Member Author

tomjn commented Jan 4, 2023

true, but what prompted this was that someone changed into a site that used PHP 8 and expected that php --version would print 8.0 not 7.4 in that folder. There was nothing to indicate the current PHP version, or that it had not changed.

Starship has this prompt for me locally:

Screenshot 2023-01-04 at 13 06 06

We could use that project, or we could use something else to achieve the same goal, but it is helpful to see the current PHP version inside PHP project folders

@tomjn
Copy link
Member Author

tomjn commented Jan 4, 2023

It may even be helpful to indicate the current site, e.g. if you go into /srv/www/wordpress-one/public_html to see that you're in wordpress-one, though that is a little out of scope of this issue

@tomjn
Copy link
Member Author

tomjn commented Jan 4, 2023

https://starship.rs/

If we did use starship, I'd suggest the no nerd font preset or the plaintext symbols:

https://starship.rs/presets/no-nerd-font.html

https://starship.rs/presets/plain-text.html

Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, Tcsh, Elvish, Nu, Xonsh, Cmd, and Powershell.
Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, Tcsh, Elvish, Nu, Xonsh, Cmd, and Powershell.

@Mte90
Copy link
Member

Mte90 commented Jan 4, 2023

Ahhh ok you were talking about the statusline/prompt in the bash terminal not on the hello message by SSH.

I use on my workstation this https://github.com/petobens/trueline (pure bash) loaded on my bashrc with custom settings. Maybe we can use this or similar as they simplify a lot of things and put our script to generate the text like php version.

GitHub
Fast and extensible bash powerline prompt with true color and fancy icon support - GitHub - petobens/trueline: Fast and extensible bash powerline prompt with true color and fancy icon support

@tomjn
Copy link
Member Author

tomjn commented Jan 4, 2023

Starship has a powerline style prompt too, perhaps we should provide this as a default and allow configuration via config.yml?

shell:
  prompt: starship

or

shell:
  prompt: trueline

This also puts a place we can have options for the welcome message e.g. if people would prefer not to have one, or want a slimmed down message.

Would we want to install them all and have script files that set up the prompt, then in .bashrc include those conditionally based on the config value? e.g. source /srv/provision/core/prompts/starship.sh etc

@tomjn
Copy link
Member Author

tomjn commented Jan 4, 2023

We might also want to add a secondary folder to check for so that users can add their own via extensions, then we'd only need to bundle a single option in VVV core

@Mte90
Copy link
Member

Mte90 commented Jan 4, 2023

Maybe this can be an extension and not native in VVV?
In this way can be customized?

About shartship or trueline to me the solution is not a problem. The important part that is easy to update as we want just to show the php version and the git branch.

Because it is possible to share the host user .bashrc with ssh https://serverfault.com/questions/400522/how-to-use-a-custom-bashrc-file-on-ssh-login so I don't think that we want to complicate things too much.

Server Fault
I've found that with the new company I'm working with I often have to access linux servers with relatively short lifetimes. On each of these servers I have an account, but whenever a new one is cre...

@tomjn
Copy link
Member Author

tomjn commented Jan 4, 2023

Because it is possible to share the host user .bashrc with ssh https://serverfault.com/questions/400522/how-to-use-a-custom-bashrc-file-on-ssh-login so I don't think that we want to complicate things too much.

That just copies bashrc into the remote server which wouldn't work if it's including other files. It would also replace any VVV specific things we have. Additionally, vagrant ssh may not be using the ssh command as it uses netssh internally so you're using an interactive ruby shell.

I mention starship or another similar prompt as it's a package that does everything out of the box and maintained by other people. The alternative is we modify the prompt we already have but then we have a bespoke prompt that we need to maintain ourselves.

The other problem is that any extension would need to reach into the .bashrc file and insert its own code to override the prompt, which sounds pretty terrible. I don't like the idea of provisioners doing string manipulation on .bashrc or .bash_profile and appending lines then trying to remove or replace them. We already have the problem that a starship extension has no way to cleanup and uninstall itself if the user decided they didn't like it, so there needs to be some sort of system

@tomjn
Copy link
Member Author

tomjn commented May 10, 2023

Noting that auto-switching PHP version via direnv might be doable in the standard custom template repo, might be worth exploring the tradeoffs or if it can be added via the VVV core site provisioner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants