What "PS1 / prompt" do you use?

0 jan burg · November 7, 2014
This is what I use in linux:


PS1='#'; (( USER_ID )) && PS1='$'; [[ ${HOSTNAME:=$(ulimit -c 0; hostname -s \
    2>/dev/null)} = *([     ]|localhost) ]] && HOSTNAME=$(ulimit -c 0; hostname \
    2>/dev/null); : ${EDITOR:=/bin/ed} ${HOSTNAME:=nil} ${TERM:=vt100}
: ${MKSH:=$(whence -p mksh)}; PS4='[$EPOCHREALTIME] '; PS1=$'\001\r''${|
    local e=$?

    (( e )) && REPLY+="$e|"
    REPLY+=${USER:=$(ulimit -c 0; id -un 2>/dev/null || echo \?)}
    REPLY+=@${HOSTNAME%%.*}:

    local d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~}
    local m=${%d} n p=...; (( m > 0 )) || m=${#d}
    (( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d: (-n)} || p=
    REPLY+=$p$d

    return $e
} '"$PS1 "


This is what I use in Android(mksh shell), pretty radical:

case $KSH_VERSION {
     (*MIRBSD\ KSH*R43*)
          global NO_VAL_SUBS=1 ;;
     (*MIRBSD\ KSH*)
          global NO_VAL_SUBS=0
          set -o inherit-xtrace \
                +o pipefail ;;
     (*) return 0 ;;
}

PS4='[${EPOCHREALTIME:-}] '; PS1=$'\1\r'; \
    (( ${NO_VAL_SUBS:-1} ))  \
 && \
 {
   ###  ..(PS1) NO VALSUB..  ###
   PS1+=$'\1\e[2;41;33m\1''$(local e=$?
   (( e )) && print -n -- ${e}$'\''\1\e[0;7;2m\1'\''"|")'$'\1\e[0;7;2m\1''${ : ${USER:=$({ local x=\?; ulimit -c 0 && ulimit -e 1 && \
x="$($BBNDK id 2>/dev/null)"
x=${x#*\(}
x=${x%%\)*};} \
|| x=$USER_ID; print -n -- $x)}; print -n -- $USER_ID;}:${PWD:-?}>'$'\1\e[0m\1 '
 } \
|| \
{
   ###  ..(PS1) VALSUB..  ###
   PS1+='${|
    local e=$?
    [[ -o -x ]] && set +x && global -x XTR_DBG=1 || global -x XTR_DBG=0
#export XTR_DBG

    (( e )) && \
REPLY+=$'\''\1\e[0;30;43m\1'\''${e}$'\''\1\e[0m\1'\''$'\''\1\e[2;37;40m\1'\''"|"$'\''\1\e[0m\1'\'' && { global ERRNO ; eval export "\"ERRNO\""'\''="${e:-0}"'\'' ; } || :

 REPLY+="$(if
      [[ ${HOSTNAME:-android} = *([Aa]ndroid|localhost) ]];
                     then
       print -n -- $'\''\1\e[0;40;2;36m\1'\''\-$'\''\1\e[0m\1'\''
                      elif
   ( (( ${#HOSTNAME} > 13 )) || \
     (( ${%HOSTNAME} > 13 )) )
                  then
    print -n -- "${HOSTNAME:0:12}.."
                  else
    print -n -- ${HOSTNAME:-?}
                   fi)"

 REPLY+=\
$'\''\1\e[0;31;40m\1'\''":"$'\''\1\e[0m\1'\''

    local d=${PWD:-?} p=~
    [[ $p = ?(*/) ]] || d=${d/#$p/~}
    local m=${%d} n p=\>
    (( m > 0 )) || m=${#d}
    (( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d: (-n)} \
    || p=
  # grey: 0;40;7;1;30 # 4;0;0;140 # ;01;3;47#
    REPLY+=\
$'\''\1\e[2;37;40m\1'\''${p}$'\''\1\e[0;33;40m\1'\''${d}$'\''\1\e[0m\1'\''
    
    REPLY+=${| REPLY=\
$'\''\1\e[0;40;7;1;30m\1'\''\%$'\''\1\e[0m\1'\''
                    (( USER_ID )) \
                    && return 0 \
                    || REPLY=\#
    REPLY=\
$'\''\1\e[0;7;31;47m\1'\''${REPLY}$'\''\1\e[0m\1'\''
         return 0
         }

 (( XTR_DBG )) && set -x
    return ${e};} '
}



PS1 on PC and then Android:


http://postimg.org/image/s7q3ldr1z/


Post a Reply

Replies

Oldest  Newest  Rating
0 jan burg · November 11, 2014
http://s23.postimg.org/s7q3ldr1z/untitled.jpg
0 jan burg · November 11, 2014
+1 for zsh and +1 for tmux. Nice, I completely forgot to add a pictures.
+1 Susan Moss · November 11, 2014
zsh with oh-my-zsh and zsh-syntax-highlight;

PS1=%m %{%}:: %{%}%3~%(0?. . %? )%{%}»%{%}

/images/forum/upload/2014-11-11/db4ed0af75099cc9cf22201fa8c19822.png
  • 1

Shell Scripting

106,990 followers
About

A shell script is a computer program designed to be run by the Unix shell, a command line interpreter. The various dialects of shell scripts are considered to be scripting languages.

Links
Moderators
Bucky Roberts Administrator