summaryrefslogtreecommitdiffstats
path: root/ksh/conf/prompt.ksh
blob: b4a513453b967e8d401255c02cd133784f281d6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
PS1='$(
	# set _cwd to $PWD, replacing $HOME with ~
	case "$PWD/" in
	("$HOME"/*)
		_cwd="~${PWD#"${HOME}"}"
		;;
	(*)
		_cwd="$PWD"
		;;
	esac

	# 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"
	else
		_color="1;33m"
	fi

	_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"      # 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