summarylogtreecommitdiffstats
path: root/kube-ps1.pacman
blob: 08892f49eac1339d36a9da7973344f9ec5cd8287 (plain)
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
KUBE_PS1_PATH="/opt/kube-ps1"
BASHRC_FILE="$HOME/.bashrc"
ZSHRC_FILE="$HOME/.zshrc"

LINE_SOURCE="source '$KUBE_PS1_PATH/kube-ps1.sh'"
LINE_PS1_BASH="PS1='[\u@\h \W "'$(kube_ps1)'"]\$ '"
LINE_PS1_ZSH="PROMPT='"'$(kube_ps1)'"'"'$PROMPT'

post_install() {
	echo '################################################################################'

	if [ -f "$BASHRC_FILE" ]; then
		TMP_FILE=$(mktemp)
		grep -vF "$LINE_SOURCE" "$BASHRC_FILE" | grep -vF "$LINE_PS1_BASH" > "$TMP_FILE"

		echo "$LINE_SOURCE" >> "$TMP_FILE"
		echo "$LINE_PS1_BASH" >> "$TMP_FILE"

		mv "$TMP_FILE" "$BASHRC_FILE"

		echo "$BASHRC_FILE file has been modified."
	fi

	if [ -f "$ZSHRC_FILE" ]; then
		TMP_FILE=$(mktemp)
		grep -vF "$LINE_SOURCE" "$ZSHRC_FILE" | grep -vF "$LINE_PS1_ZSH" > "$TMP_FILE"

		echo "$LINE_SOURCE" >> "$TMP_FILE"
		echo "$LINE_PS1_ZSH" >> "$TMP_FILE"

		mv "$TMP_FILE" "$ZSHRC_FILE"

		echo "$ZSHRC_FILE file has been modified."=
	fi

	echo 'More information at https://github.com/jonmosco/kube-ps1'
	echo '################################################################################'
	echo "Add the following lines to another user's bashrc file if needed:"
	echo "$LINE_SOURCE"
	echo "$LINE_PS1_BASH"
	echo '################################################################################'
	echo "Add the following lines to another user's zshrc file if needed:"
	echo "$LINE_SOURCE"
	echo "$LINE_PS1_ZSH"
	echo '################################################################################'
}

post_remove() {
	if [ -f "$BASHRC_FILE" ]; then
		TMP_FILE=$(mktemp)
		grep -vF "$LINE_SOURCE" "$BASHRC_FILE" | grep -vF "$LINE_PS1_BASH" > "$TMP_FILE"
		mv "$TMP_FILE" "$BASHRC_FILE"
	fi

	if [ -f "$ZSHRC_FILE" ]; then
		TMP_FILE=$(mktemp)
		grep -vF "$LINE_SOURCE" "$ZSHRC_FILE" | grep -vF "$LINE_PS1_ZSH" > "$TMP_FILE"
		mv "$TMP_FILE" "$ZSHRC_FILE"
	fi
}