hashbangcode / vlad

Vlad - Vagrant LAMP Ansible Drupal
173 stars 53 forks source link

Improved bash prompt hints #346

Closed christopher-hopper closed 8 years ago

christopher-hopper commented 8 years ago

For your consideration: improved bash prompt "bling" that is consistent, useful and colourful.

These changes configure and enable drush and git hints in the bash prompt and terminal title bar that work with all currently supported drush and git versions. They can be disabled using the existing Vlad variable bling_shell_prompt.

So far tested with:

  1. Ubuntu 14
    • drush 7.x
    • drush 8.x

Yet to be tested:

  1. Ubuntu 14
    • drush 6.x
  2. Centos
    • drush 6.x
    • drush 7.x
    • drush 8.x
dixhuit commented 8 years ago

Thanks for this.

At first glance, without testing, this looks very promising and I've already been considering some of the features you've included here. That said, I think it's less useful to lose the boxname in the prompt - this was always very handy for establishing which box you were SSHd into in which terminal window. Also, it's gonna be hard to depart from the wrapping "✝" symbols as these were a handy way of very quickly spotting what's a Vlad box and what's not - they're also kinda "on-brand" as it were.

Either way, there's bound to be things I'm missing here without testing so I'll give it a whirl and get back to you again here :)

Relates to: #338

dixhuit commented 8 years ago

Aaah, just thought, depending on when you started using Vlad it's possible that you never saw the previous bash prompt before #338 clobbered it. With that in mind, some of my previous comment might not make any sense - apologies if that's the case :)

dixhuit commented 8 years ago

Once again, thanks for submitting this. I've now briefly tested it. Feedback:

So, with all that in mind, may I suggest we tweak things so that this (output as of this PR):

[vagrant@nosferatu /var/www/site/docroot (master *=) (drush_prompt)]
$

changes to:

✝ nosferatu ✝ /var/www/site/docroot (drush_prompt)
$

This of course depends on what the drush prompt prints and whether it also has any performance impact to consider. Believe me, if the git prompt didn't knacker the performance as much I'd suggest keeping it but as it stands I just don't think it's a good trade.

dixhuit commented 8 years ago

BTW, for anyone following along that can't/won't test this PR, here's what my prompt looks like with the PR merged:

2__vagrant__var_www_site_docroot__dev____

christopher-hopper commented 8 years ago

@danbohea Love the feedback. I'll make some adjustments and push another one for testing.

dixhuit commented 8 years ago

@christopher-hopper Good stuff. I look forward to it :)

christopher-hopper commented 8 years ago

@danbohea I've pushed some changes to incorporate your feedback.

  1. Restored the Apotropaic power into the bash prompt
  2. Display the hostname rather than the user in the terminal title bar
  3. Turned off git upstream checks and hints in the prompt to improve performance

Path hint
The current prompt uses a character limit of 25 for the path hint. What limit do you think we should increase that to?

User hint
I'd like to keep the user in the prompt as it does provide some value when you switch to a shell as the root user. Try this for an example of how that works and you may be surprised and hopefully delighted:

# Open shell as root
sudo -s

drush hint
The drush prompt hint was introduced a while back. I'd like to say in drush-6.x somewhere but definitely since drush-7.x. The only thing it does for now is tell you which drush site-alias you're using. To see it in action yourself try switching to a site-alias with drush use.

# List defined site aliases
drush site-alias

# Use a site-alias that will persist for the current session
drush use @site-alias-name

# Unset the site-alias
drush use @none
drush use

git hint I've added a new variable bling_shell_prompt_git_upstream that can be overridden in Vlad settings to turn off git upstream checks in the prompt hint. This improves the performance considerably. The variable can be set to 'true' or 'false' or a valid value defined for GIT_PS1_UPSTREAM. If accepted I'm happy to document this behaviour in the Vlad documentation.

As well as a relying on the global setting for bling_shell_prompt_git_upstream, git allows you to override this for individual repositories by using the git config setting bash.showupstream.

Valid values for GIT_PS1_UPSTREAM and bash.showupstream can be a comma separated string containing one or more of these:

See the git-prompt.sh code for details.

dixhuit commented 8 years ago

@christopher-hopper You da man. This makes me smile hard:

local APOT='✝'; # apotropaic symbol

Will test ASAP and get back to you. Smells like a merge to me....

dixhuit commented 8 years ago

Looks good! I have some tweaks but I'm happy to merge first - tweak later. The main issue is that I believe we should disable the git hint by default - the "out of the box" experience is important and this does effect that.

Thanks for the contributions of late, they all been very thorough and very much appreciated :)

dixhuit commented 8 years ago

This is now merged and I have since added some very minor tweaks:

It would appear that bling_shell_prompt_git_upstream is not having the desired effect (at least not when it still defaults to false). Would you mind taking a look at this when you get time?

Over to you on the docs update as suggested, please make sure you use the dev branch of the docs.

christopher-hopper commented 8 years ago

bling_shell_prompt_git_upstream won't turn off the git hint altogether. It just stops it from doing the expensive job or comparing the local changes to the upstream remote and showing you whether it matches, is ahead, behind, etc.

I'll look at adding full control over both the git and drush promt hints and push that as another new PR for you. Also happy to add documentation.

dixhuit commented 8 years ago

Aaaaah, with you now. All good :)