Skip to content

What is your PS1?

Mine is:

PS1='\u@\h:$pwd>'

13 Comments

  1. Mine is ever so slightly more complicated than yours:

    PROMPT=$’%(!.%F{red}.%F{blue})%D{%a %R} %B[%m:%35<..<%~%<<] %n%#%b%f '
    RPROMPT=$'%(!.%F{red}.%F{blue})<%(1j. %BJ%j%b.)%f'

    if (( $SHLVL != ${ZSHLVL:=$SHLVL} ))
    then
    RPROMPT=$RPROMPT$' %F{magenta}Z'$(( $SHLVL – $ZSHLVL ))$'%f'
    fi
    export ZSHLVL

    Friday, January 22, 2010 at 15:46 | Permalink
  2. # Set colorful PS1 only on colorful terminals
    NORMAL=”\[33[0;0m\]”
    BOLD=”\[33[1m\]”
    BLUE=”\[33[0;34m\]”
    CYAN=”\[33[0;36m\]”
    BRIGHT_CYAN=”\[33[1;36m\]”
    DIM_CYAN=”\[33[2;36m\]”
    WHITE=”\[33[1;37m\]”
    PS1=”$BLUE[$CYAN\u@\h:\w$BLUE]\n$BLUE[$CYAN\t$BLUE]$BOLD\$$NORMAL “

    Friday, January 22, 2010 at 15:48 | Permalink
  3. Robert wrote:

    PS1=”[\[33[32m\]\w]\[33[0m\]\n\[33[1;36m\]\u\[33[1;33m\] -> \[33[0m\]”

    Friday, January 22, 2010 at 16:29 | Permalink
  4. Peter Mielke wrote:

    My PS1 is different depending on the environment.

    In normal terminal session it is: \h:\w \u\$
    But within Emacs (where most of my shell work is) it is simply: [\t] \$

    Friday, January 22, 2010 at 18:50 | Permalink
  5. # This prompt has the hostname and up to two levels of directory context. Just one level often doesn’t disambiguate, and more than two is often annoying. So a session might go:
    # [mymachine ~]$ cd foo
    # [mymachine ~/foo]$ cd bar
    # [mymachine foo/bar]$ cd baz
    # [mymachine bar/baz]$

    # The actual code:
    echo ‘($H)=($ENV{HOST}=~/([^\.]+ /);s|$ENV{HOME}|~|g;s|.+/([^/]+/[^/]+)$| ${1}|g;s|^|$H |;’ > $HOME/._sp
    # Running it:
    function sp () { PS1=”[`pwd | perl -p $HOME/._sp`]\$ “; }
    # Install it into the prompt:
    # precmd is a special tcsh alias executed before every command prompt.
    # PROMPT_COMMAND is a special bash environment variable for the same purpose.
    export PROMPT_COMMAND=sp
    # Initialize it the first time:
    sp

    # alongside this, I’ve also implemented forward and back commands for directories as we are used to them in web browsers, so after the session at the beginning, I could say:
    # [mymachine bar/baz]$ b
    # [mymachine foo/bar]$ b
    # [mymachine ~/foo]$ f
    # [mymachine foo/bar]$ cd /usr/local/lib
    # [mymachine local/lib]$ b
    # [mymachine foo/bar]$

    # If anyone is interested, I’m happy to post the code for that.

    Saturday, January 23, 2010 at 00:06 | Permalink
  6. Grant wrote:

    Gregory:

    That would be nice. Thanks.

    Saturday, January 23, 2010 at 00:28 | Permalink
  7. # $HOME/._cdd_add
    echo ‘$_=$ENV{PWDx};split/:/;if($_[0]>1){$_[0]–};print(join(q{:},@_));’ > $HOME/._cdd_back
    echo ‘$_=$ENV{PWDx};split/:/;print($_[$_[0]]);’ > $HOME/._cdd_curd
    echo ‘$_=$ENV{PWDx};split/:/;if($_[0] $HOME/._cdd_forw

    function cdd () { \cd $*; export PWDx=`perl $HOME/._cdd_add “$PWD”`; }
    function b () { export PWDx=`perl $HOME/._cdd_back`; \cd “`perl $HOME/._cdd_curd`”; }
    function f () { export PWDx=`perl $HOME/._cdd_forw`; \cd “`perl $HOME/._cdd_curd`”; }
    alias cd=cdd
    fi

    #>

    # I should mention that the idea and initial implementation for the two-level command prompt were from Jason A. Haynes for tcsh:
    # “; if (“$hd:h” == “”) set prompt=”%m $pwd%# “; unset hd’
    # alias sp ‘set pwd=`dirs`; set hd=$pwd:h; set prompt=”%m ..$hd:t/$pwd:t%

    # Grem

    Saturday, January 23, 2010 at 05:54 | Permalink
  8. # Ack! Part of the Historical Directory Browsing was cut off. Let me try again:

    # $HOME/._cdd_add
    echo ‘$_=$ENV{PWDx};split/:/;if($_[0]>1){$_[0]–};print(join(q{:},@_));’ > $HOME/._cdd_back
    echo ‘$_=$ENV{PWDx};split/:/;print($_[$_[0]]);’ > $HOME/._cdd_curd
    echo ‘$_=$ENV{PWDx};split/:/;if($_[0] $HOME/._cdd_forw

    function cdd () { \cd $*; export PWDx=`perl $HOME/._cdd_add “$PWD”`; }
    function b () { export PWDx=`perl $HOME/._cdd_back`; \cd “`perl $HOME/._cdd_curd`”; }
    function f () { export PWDx=`perl $HOME/._cdd_forw`; \cd “`perl $HOME/._cdd_curd`”; }
    alias cd=cdd
    fi

    Saturday, January 23, 2010 at 05:56 | Permalink
  9. #Oh, I see, it wasn’t so much “cut off” as hidden by angle brackets.

    # historical directory browsing
    # Historical directory browsing adds `b’ and `f’ commands to your shell
    # to let you go back and forward in your directory history like you
    # go back and forward in your web page browsing history.

    # Idea and original implementation from Deniz Yuret, rewritten by Gremio
    if [ ! -n “$PWDx” ]; then
    export PWDx=”1:`pwd`”

    echo ‘$_=$ENV{PWDx};split/:/;$_[++$_[0]]=shift;splice(@_,$_[0]+1);print(join(q{:},@_));’ > $HOME/._cdd_add
    echo ‘$_=$ENV{PWDx};split/:/;if($_[0]>1){$_[0]–};print(join(q{:},@_));’ > $HOME/._cdd_back
    echo ‘$_=$ENV{PWDx};split/:/;print($_[$_[0]]);’ > $HOME/._cdd_curd
    echo ‘$_=$ENV{PWDx};split/:/;if($_[0] $HOME/._cdd_forw

    function cdd () { \cd $*; export PWDx=`perl $HOME/._cdd_add “$PWD”`; }
    function b () { export PWDx=`perl $HOME/._cdd_back`; \cd “`perl $HOME/._cdd_curd`”; }
    function f () { export PWDx=`perl $HOME/._cdd_forw`; \cd “`perl $HOME/._cdd_curd`”; }
    alias cd=cdd
    fi

    Saturday, January 23, 2010 at 05:57 | Permalink
  10. Grant wrote:

    Found that bash on Solaris doesn’t like that PS1…. here is the updated version:

    PS1=’\u@\h:\W>’

    Saturday, January 23, 2010 at 22:12 | Permalink
  11. Perhaps it’s because when I’m at an actual prompt, I’m at home, not working, I find all the stuff about current directory, user, hostname, et cetera, just extraneous. So generally my prompt is just

    PS1=’\$ ‘

    If I need to know stuff, there’s always pwd, hostname, and whoami.

    Tuesday, January 26, 2010 at 08:18 | Permalink
  12. Adrian wrote:

    I do not claim any proper code in the following lines that I’ve had for ages…

    %cat load.zsh
    #!/bin/zsh
    declare -i Up=”`uptime | awk -F: ‘{print $4}’ | cut -f1 -d’,’`”

    if [ $Up -ge 2 ]
    then
    echo ‘red’
    exit
    else
    if [ $Up -lt 1 ]
    then
    echo ‘green’
    exit
    else
    echo ‘yellow’
    exit
    fi
    fi

    %cat prompt.zsh
    autoload -U colors
    colors

    user_color=”cyan”
    user_in_color=”white”
    path_color=”green”
    percent_color=”yellow”
    date_color=”`zsh ~/.zsh/load.zsh`”

    date_format=”%H:%M”

    #start=”%U”
    date=”%{$fg[$date_color]%}%D{$date_format}”
    user=”%{$fg[$user_color]%}[%{$fg[$user_in_color]%}%n%{$fg[$user_color]%}]”
    cpath=”%B%{$fg[$path_color]%}%~%b”
    percent=”%{$fg[$percent_color]%}%%”
    end=”%{$reset_color%}”

    PS1=”$user$cpath $percent$end ”

    RPS1=”$date$end”

    Tuesday, January 26, 2010 at 09:34 | Permalink
  13. Geoff Knauth wrote:

    PS1=”[\u@\h \W]\\$ “

    Saturday, February 6, 2010 at 10:32 | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*