Users browsing this thread: 7 Guest(s)
seninha
Long time nixers
I use a left and right PS1 on ksh.
The left prompt indicates whether I'm root (it becomes red when I'm root), and, if a command fails, it prints the exit code returned by the last command between square brackets.
The right prompt indicates where I am.

[Image: scrot-2020-11-09-110943.png]

Here's how I set it:
Code:
promptcmd() {
    _exit=$?
    _dir=$(echo "$PWD" | sed "s,^$HOME,~,")
    _tty=$(tty)
    _tty=${_tty#/dev/}

    printf "%s" "\[\e]0;$_tty: $_dir\a\]"           # set window title

    echo                                            # blank line

    [ "$_exit" -gt 0 ] && printf "%s" "\[\e[1;31m\] [$_exit]"
    printf "%s" "\[\e[0m\]"
    printf "%s" "\[\e[s\]"                          # save cursor position
    printf "%s" "\[\e[$((COLUMNS - ${#_dir}))G\]"   # go to right
    printf "%s" "$_dir"                             # print pwd
    printf "%s" "\[\e[u\]"                          # restore cursor position
    if [ $(id -u) -eq 0 ]
    then
        printf "%s" "\[\e[1;31m\]"
    else
        printf "%s" "\[\e[1m\]"
    fi
    printf "%s" " ❯ "
    printf "%s" "\[\e[0m\]"
}
PS1='`promptcmd`'


Messages In This Thread
Your PROMPT - by venam - 24-10-2012, 12:34 PM
RE: Your PROMPT - by simon - 24-10-2012, 12:56 PM
RE: Your PROMPT - by fb0x - 24-10-2012, 01:04 PM
RE: Your PROMPT - by crshd - 24-10-2012, 02:09 PM
RE: Your PROMPT - by Mafia - 24-10-2012, 02:10 PM
RE: Your PROMPT - by bash - 20-11-2012, 05:18 PM
RE: Your PROMPT - by Mafia - 21-11-2012, 07:28 PM
RE: Your PROMPT - by gurhush - 20-11-2012, 06:10 PM
RE: Your PROMPT - by zygotb - 21-11-2012, 01:21 AM
RE: Your PROMPT - by crshd - 21-11-2012, 11:11 PM
RE: Your PROMPT - by gurhush - 09-12-2012, 05:30 AM
RE: Your PROMPT - by TheHotBot - 09-12-2012, 08:22 AM
RE: Your PROMPT - by yrmt - 09-12-2012, 09:50 AM
RE: Your PROMPT - by gurhush - 24-12-2012, 02:57 PM
RE: Your PROMPT - by yrmt - 24-12-2012, 05:07 PM
RE: Your PROMPT - by crshd - 09-12-2012, 11:27 AM
RE: Your PROMPT - by yrmt - 09-12-2012, 12:26 PM
RE: Your PROMPT - by yrmt - 13-12-2012, 03:14 PM
RE: Your PROMPT - by crshd - 14-12-2012, 06:31 AM
RE: Your PROMPT - by gurhush - 25-12-2012, 11:37 PM
RE: Your PROMPT - by gurhush - 09-01-2013, 06:05 AM
RE: Your PROMPT - by Ivyl - 12-01-2013, 12:41 PM
RE: Your PROMPT - by crshd - 14-01-2013, 11:07 AM
RE: Your PROMPT - by yrmt - 14-01-2013, 03:14 PM
RE: Your PROMPT - by Mafia - 14-01-2013, 06:05 PM
RE: Your PROMPT - by eye - 18-01-2013, 02:02 PM
RE: Your PROMPT - by darthlukan - 04-10-2015, 09:53 AM
RE: Your PROMPT - by ashen - 04-10-2015, 12:10 PM
RE: Your PROMPT - by Mafia - 04-10-2015, 10:46 PM
RE: Your PROMPT - by josuah - 03-04-2016, 11:28 PM
RE: Your PROMPT - by ninjacharlie - 04-04-2016, 03:49 PM
RE: Your PROMPT - by neeasade - 04-04-2016, 04:01 PM
RE: Your PROMPT - by Adrift - 04-04-2016, 11:24 PM
RE: Your PROMPT - by venam - 05-04-2016, 12:51 AM
RE: Your PROMPT - by neeasade - 05-04-2016, 09:12 AM
RE: Your PROMPT - by rocx - 05-04-2016, 09:41 AM
RE: Your PROMPT - by venam - 09-11-2020, 04:04 AM
RE: Your PROMPT - by jkl - 09-11-2020, 04:43 AM
RE: Your PROMPT - by pyratebeard - 09-11-2020, 06:27 AM
RE: Your PROMPT - by eye - 09-11-2020, 10:18 AM
RE: Your PROMPT - by seninha - 09-11-2020, 11:13 AM
RE: Your PROMPT - by pfr - 10-11-2020, 09:25 AM
RE: Your PROMPT - by opfez - 10-11-2020, 10:58 AM
RE: Your PROMPT - by jolia - 10-11-2020, 05:58 PM
RE: Your PROMPT - by sulami - 11-11-2020, 07:11 AM
RE: Your PROMPT - by s0kx - 11-11-2020, 09:11 AM
RE: Your PROMPT - by jolia - 11-11-2020, 09:37 AM
RE: Your PROMPT - by jkl - 11-11-2020, 01:20 PM
RE: Your PROMPT - by neeasade - 11-11-2020, 02:41 PM
RE: Your PROMPT - by sulami - 11-11-2020, 04:57 PM