Live data from Hacker News

Bash PS1 Generator

bashrcgenerator.com

31–40 of 146 posts

Re: Bash PS1 Generator

#31
post #14

Notes: * As an idea, this is excellent. It's intuitive to use and provides full instructions on how to implement * Putting an element in any other position than the end of the prompt is fiddly. * I'd love for the option to to be able to colour elements. * More advanced or exotic element types such as Git Branch would be excellent (Not sure if Bash supports this, but I've seen it in some shells)

For the manual approach, git provides a shell script to generate the env var __git_ps1 for this very purpose.[1]

[1]: https://git-scm.com/book/id/v2/Appendix-A%3A-Git-in-Other-En...

Re: Bash PS1 Generator

#32
post #8
post #3

Or use starship...

It's too bloated. It has all kinds of built-in stuff with ugly defaults instead of just providing a framework with plugins.

Starship is the only prompt I've used that has (a) sane defaults, (b) cross platform support as well as ease of installation, and (c) good enough speed. Powerline is much slower, and I lose my serenity everytime I have to fiddle with dotfiles.

Re: Bash PS1 Generator

#33
Here's what I'm currently rocking:

    0 0:00:00
    ~/Code/company/app$
First number is exit code of previous command, second is how long it took. Credit to https://unix.stackexchange.com/questions/252229/ps1-prompt-t... for the last part. It's a bit ratchet:

- I actually don't care about the exit code unless it was non-zero

- It calculates the delta three times

but I've been to busy to optimise it.

    prompt_command() {
      _PS1_now=$(printf '%(%s)T')
      PS1=$( printf "\n\$? \[\e%02d:%02d:%02d \n\[\033[01;34m\]\w\[\033[00m\]\$ " \
              $((  ( _PS1_now - _PS1_lastcmd ) / 3600))         \
              $(( (( _PS1_now - _PS1_lastcmd ) % 3600) / 60 )) \
              $((  ( _PS1_now - _PS1_lastcmd ) % 60))           \
          )
      _PS1_lastcmd=$_PS1_now
    }
    PROMPT_COMMAND='prompt_command'
    _PS1_lastcmd=$(printf '%(%s)T')

Re: Bash PS1 Generator

#34
post #14

Notes: * As an idea, this is excellent. It's intuitive to use and provides full instructions on how to implement * Putting an element in any other position than the end of the prompt is fiddly. * I'd love for the option to to be able to colour elements. * More advanced or exotic element types such as Git Branch would be excellent (Not sure if Bash supports this, but I've seen it in some shells)

I've shared it elsewhere too, but I made something similar a few years ago which provides what you were after:

https://dom111.github.io/bash-ps1/

Re: Bash PS1 Generator

#35
post #31
post #14

Notes: * As an idea, this is excellent. It's intuitive to use and provides full instructions on how to implement * Putting an element in any other position than the end of the prompt is fiddly. * I'd love for the option to to be able to colour elements. * More advanced or exotic element types such as Git Branch would be excellent (Not sure if Bash supports this, but I've seen it in some shells)

For the manual approach, git provides a shell script to generate the env var __git_ps1 for this very purpose.[1] [1]: https://git-scm.com/book/id/v2/Appendix-A%3A-Git-in-Other-En...

Very cool, had no idea!

Re: Bash PS1 Generator

#36
I think the drag-n-drop UI is less intuitive. Wasted a few minutes trying to click these items as "buttons" and wondering if there's something wrong because of the http-onlyness of the site (console gives a lot of warning).

Re: Bash PS1 Generator

#37
post #16
post #14

Notes: * As an idea, this is excellent. It's intuitive to use and provides full instructions on how to implement * Putting an element in any other position than the end of the prompt is fiddly. * I'd love for the option to to be able to colour elements. * More advanced or exotic element types such as Git Branch would be excellent (Not sure if Bash supports this, but I've seen it in some shells)

double click an element to change the color

Aha! Thank you!

Re: Bash PS1 Generator

#38
post #36

I think the drag-n-drop UI is less intuitive. Wasted a few minutes trying to click these items as "buttons" and wondering if there's something wrong because of the http-onlyness of the site (console gives a lot of warning).

Yea, why not just have "double-click" as "add this element to the end of input".

Re: Bash PS1 Generator

#40
current git branch is missing (helps me to avoid working on the wrong branch). (tried to do it with colors, but things got too messy). I never managed to work with colors in bash propmts; they look different on each environment.

  parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
  }

  PS1="[\u@\h \W\$(parse_git_branch)]\$ "
Post reply on HN