Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Best Bash Prompt Code
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Best Bash Prompt Code

So what PS1 codes do you use use for your VPS? Since I've got a bunch of VPS around the world, I need something to remind me which one I'm in and what system is loaded:

PS1='[\e]0;\w | \u@\h\a][[\e[1;31m]\[email protected](Cent5.10-32bit) [\e[33m]\W[\e[0m]]# '

Looks like this (pretend there are red and yellow colors...):

[[email protected](Cent5.10-32bit) ~]#

Any other 'cool' thing you do in yours?

Comments

  • BruceBruce Member

    nice

    I've grown used to root@vps1 :) time for a change though

  • BotoXBotoX Member

    ZSH + Powerline anyone? :3

  • nunimnunim Member

    Shouldn't you be able to tell by the hostname? If not maybe you should revisit your naming scheme.

    Thanked by 1linuxthefish
  • wychwych Member

    @nunim said:
    Shouldn't you be able to tell by the hostname? If not maybe you should revisit your naming scheme.

    This, all my boxes have the server location/name in them so I know what box im on.

  • geodirkgeodirk Member
    edited April 2014

    @nunim said:
    Shouldn't you be able to tell by the hostname? If not maybe you should revisit your naming scheme.

    Good idea...I actually don't use the hostname for anything as I do everything off the IP address on all my boxes.

  • Nifty stuff in there

  • udkudk Member
    edited April 2014

    Dev boxes (green):

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

    Production boxes (red):

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

  • ScionScion Member

    I use this, which is the default Gentoo prompt plus some code I borrowed and modified from a blog some time ago to show the current git branch and whether it's clean or dirty. I think it was this article but apparently I didn't document the URL at the time.

    The default Gentoo prompt is nice because it's green when you're a regular user and red when you become root.

    The git branch turns yellow if it's dirty or cyan if it's clean. If you're not in a git branch, the indicator goes away so it just looks like the default Gentoo prompt again.

    # Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
    if [[ -f ~/.dir_colors ]]; then
            eval `dircolors -b ~/.dir_colors`
    else
            eval `dircolors -b /etc/DIR_COLORS`
    fi
    
    # Change the window title of X terminals 
    case ${TERM} in
            xterm*|rxvt*|Eterm|aterm|kterm|gnome)
                    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
                    ;;
            screen)
                    PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
                    ;;
    esac
    
    # Configure colors, if available.
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
      c_bracket='\[\e[1;34m\]'
      c_reset='\[\e[0m\]'
      c_user='\[\e[1;32m\]'
      c_path='\[\e[1;34m\]'
      c_git_clean='\[\e[0;36m\]'
      c_git_dirty='\[\e[0;33m\]'
    else
      c_bracket=
      c_reset=
      c_user=
      c_path=
      c_git_clean=
      c_git_dirty=
    fi
    
    # Function to assemble the Git parsingart of our prompt.
    git_prompt ()
    {
      if ! git rev-parse --git-dir > /dev/null 2>&1; then
        return 0
      fi
      git_branch=$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p')
      if git diff --quiet 2>/dev/null >&2; then
        git_color="$c_git_clean"
      else
        git_color="$c_git_dirty"
      fi
      echo "${c_bracket}[${c_reset}$git_color$git_branch${c_reset}${c_bracket}]${c_reset}"
    }
    
    # Thy holy prompt.
    PROMPT_COMMAND='PS1="${c_user}\u@\h${c_reset} ${c_path}\w${c_reset}$(git_prompt) ${c_path}\$${c_reset} "'
    
    Thanked by 1linuxthefish
  • BruceBruce Member

    excellent link. thanks

  • @BotoX said:

    ZSH + Powerline anyone? :3

    can you please share your zshrc with us? :3

    thank you

  • BotoXBotoX Member

    https://github.com/robbyrussell/oh-my-zsh

    https://github.com/robbyrussell/oh-my-zsh/wiki/themes <- agnoster

    You need to use one of these fonts https://github.com/Lokaltog/powerline-fonts to get it working.

    My zshrc (nothing special, oh-my-zsh does all the fancy stuff) https://files.botox.bz/dotfiles/zshrc

Sign In or Register to comment.