summaryrefslogtreecommitdiffstats
path: root/ksh/conf/prompt.ksh
diff options
context:
space:
mode:
Diffstat (limited to 'ksh/conf/prompt.ksh')
-rw-r--r--ksh/conf/prompt.ksh58
1 files changed, 34 insertions, 24 deletions
diff --git a/ksh/conf/prompt.ksh b/ksh/conf/prompt.ksh
index 0d654fe..b4a5134 100644
--- a/ksh/conf/prompt.ksh
+++ b/ksh/conf/prompt.ksh
@@ -1,26 +1,30 @@
-#function _promp {
-# if [[ $(id -u) -eq 0 ]]; then
-# local SUFFIX='\w \$:'
-# else
-# local SUFFIX='\033[34m\w \033[1;33m\076\033[0m'
-# fi
-# print "$SUFFIX"
-#}
-#
-#export PS1='
-#$(_promp)'
-
PS1='$(
+ # set _cwd to $PWD, replacing $HOME with ~
case "$PWD/" in
- ("$HOME"/*)
- _cwd="~${PWD#"${HOME}"}";;
- (*)
- cwd="$PWD";;
+ ("$HOME"/*)
+ _cwd="~${PWD#"${HOME}"}"
+ ;;
+ (*)
+ _cwd="$PWD"
+ ;;
esac
- _rprompt="$_cwd"
- _cols=$((COLUMNS - ${#_rprompt}))
-
+ # set _tty to the name of tty, trim any /dev/ at the beginning
+ _tty=$(tty)
+ _tty=${_tty#/dev/}
+
+ # set _host to the host name of the machine
+ # set _title to "$_cwd - $_tty"; prefix it with "$_host:" if I am not on my laptop
+ if test -z "$SSH_CONNECTION"
+ then
+ _host=""
+ _title="$_cwd - $_tty"
+ else
+ _host="$(hostname)"
+ _title="$_host:$_cwd - $_tty"
+ fi
+
+ # set _color to red if we are root, or to white if we are a normal user
if [ $(id -u) -eq 0 ]
then
_color="1;31m"
@@ -28,14 +32,20 @@ PS1='$(
_color="1;33m"
fi
- printf "\n"
- printf "\\\\[\e[0m\\\\]\\\\[\e[s\\\\]"
+ _rprompt="$_cwd"
+ _cols=$((COLUMNS - ${#_rprompt}))
+
+ # return prompt
+ printf "\n" # print blank line before prompt
+ printf "\\\\[\e[0m\\\\]\\\\[\e[s\\\\]" # clear formatting
+ printf "\\\\[\e]0;%s\a\\\\]" "$_title" # set window title
printf "\\\\[\e[%sG\\\\]" "$_cols"
printf "%s" "$_rprompt"
printf "\\\\[\e[u\\\\]"
- printf "\\\\[\e[%s\\\\]" "$_color"
- printf "> "
- printf "\\\\[\e[0m\\\\]"
+ printf "\\\\[\e[%s\\\\]" "$_color" # set color to red if root, white otherwise
+ printf "%s> " "$_host" # set left prompt
+ printf "\\\\[\e[0m\\\\]" # clear formatting
)'
+# print previous command's non-zero exit status, bold and red, after it exits
trap 'printf "\e[1;31mEXIT: %s\e[0m\n" "$?"' ERR
Un proyecto texto-plano.xyz