How to custom display prompt in KornShell to show hostname and current directory?

前端 未结 7 758
一个人的身影
一个人的身影 2021-02-04 09:59

I am using KornShell (ksh) on Solaris and currently my PS1 env var is:

PS1=\"${HOSTNAME}:\\${PWD} \\$ \"

And the prompt displays: hostname:/fu

相关标签:
7条回答
  • 2021-02-04 10:54

    ENV=~/.kshrc, and then in your .kshrc:

    function _cd {
      \cd "$@"
      PS1=$(
        print -n "$LOGNAME@$HOSTNAME:"
        if [[ "${PWD#$HOME}" != "$PWD" ]]; then
          print -n "~${PWD#$HOME}"
        else
          print -n "$PWD"
        fi
        print "$ "
      )
    }
    
    alias cd=_cd
    
    cd "$PWD"
    

    Brad

    0 讨论(0)
提交回复
热议问题