aboutsummaryrefslogtreecommitdiff
path: root/shell/ksh
blob: 811b15b558c31e9bd7e32ef50cd0d059ea4a0d20 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# If you wish to prevent non KSH shells from running this
# [ -z "$KSH_VERSION" ] && return

# Restrict this to KSH only
if ! [ -z "$KSH_VERSION" ] ; then
	precmd() {
		typeset e=$?
	
		(( e )) && print -n "$e|"
	}
	set_ps1() {
			PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${USER_C}${USER:=$(id -un)}@$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
	${END_P} '
			export PS1;
	}
	set_root_ps1() {
	PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${HOST_C}$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
	${END_P} '
	export PS1;
	}
	# RED: 31, GREEN: 32, YELLOW: 33, BLUE: 34, MAGENTA: 35, CYAN: 36, WHITE: 37, GREY 38. and No color which is 0.
	set_prompt() {
		if [ `id -u` -eq 0 ] ; then
			# Previously
			# Red for root, and no username 
			# PS1="$(hostname) \$PWD
			echo $TERM | grep "256color$" > /dev/null 2>&1
			if [ $? -eq 0 ] ; then
				BG=""
				ACCENT_C=""
				ACCENT_P="|"
				HOST_C=""
				PATH_C=""
				END_C=""
				set_root_ps1
				END_P="#"
			else
				BG=""
				ACCENT_C=""
				ACCENT_P="|"
				HOST_C=""
				PATH_C=""
				END_P="#"
			fi
			set_root_ps1
		else	
			# Previously
			# PS1="${USER:=$(id -un)}@$(hostname) \$PWD
			echo $TERM | grep "256color$" > /dev/null 2>&1
			if [ $? -eq 0 ] ; then
				BG=""
				ACCENT_C=""
				ACCENT_P="|"
				USER_C=""
				PATH_C=""
				END_C=""
				END_P="%"
			else
				BG=""
				ACCENT_C=""
				ACCENT_P="|"
				USER_C=""
				PATH_C=""
				END_C=""
				END_P="$"
			fi
			set_ps1
		fi
	}
	set_basic_prompt() {
		if [ $(id -u) -eq 0 ] ; then
			PS1='$(precmd)'"${USER:=$(id -un)}@$(hostname) \$PWD # "
		else
			PS1='$(precmd)'"${USER:=$(id -un)}@$(hostname) \$PWD $ "
		fi
		export PS1;
	}
fi