-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_custom
85 lines (73 loc) · 2 KB
/
.bash_custom
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
80
81
82
83
84
85
# define colors etc
RESET="\[$(tput sgr0)\]"
BOLD="\[$(tput bold)\]"
BLUE="\[$(tput setaf 4)\]"
GREEN="\[$(tput setaf 2)\]"
CYAN="\[$(tput setaf 6)\]"
RED="\[$(tput setaf 1)\]"
YELLOW="\[$(tput setaf 3)\]" # non-bold yellow is orange ??
PURPLE="\[$(tput setaf 5)\]"
# Show the last 3 dirs from pwd
endpwd() {
DIR="$(pwd)"
end="${DIR##*/}"
# The "rest" of the working dir, with 'end' chopped off
rest="${DIR%/*}"
secondFromEnd="${rest##*/}"
# if not empty, append a /
if ! [[ -z "${secondFromEnd// }" ]]; then
secondFromEnd=$secondFromEnd/
fi
rest="${rest%/*}"
thirdFromEnd="${rest##*/}"
if ! [[ -z "${thirdFromEnd// }" ]]; then
thirdFromEnd=$thirdFromEnd/
fi
# slash to start the path - changes colour if it is root
startslash="/"
if [[ -z "${rest%/*}" ]] ; then
startslash="${CYAN}/${GREEN}"
fi
#tim/documents -> ~/documents
echo "${startslash}$thirdFromEnd$secondFromEnd$end"
}
my_date() {
if [[ -n "${PROMPT_SECS}" ]]; then
echo "$(date +'%M:%S')"
else
echo "$(date +'%M')"
fi
}
git_branch() {
branch=$(git branch 2>/dev/null | grep '^*' | colrm 1 2)
if [[ -n $branch ]]; then
branch="(${branch}) "
else
branch=""
fi
}
generate_prompt() {
if [[ ${EUID} == 0 ]] ; then # sudo prompt
PS1='\[\033[01;31m\][\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] '
else
git_branch
PS1="${BOLD}${YELLOW}[${GREEN} $(endpwd) ${YELLOW}] ${RESET}${YELLOW}$(my_date) ${RESET}${PURPLE}${BOLD}${branch}${RESET}${BOLD}${CYAN}\$ ${RESET}"
fi
}
PROMPT_COMMAND=generate_prompt
## start tmux automatically
#if hash tmux 2>/dev/null; then {
# # enable 256 color
# alias tmux="TERM=xterm-256color tmux "
# # also in .tmux.conf - set -g default-terminal "screen-256color"
#
#
# # run tmux if it is not running
# if ! { [[ $TERM =~ ^screen* ]] && [ -n "$TMUX" ]; } then
# exec tmux
# fi
#}
#else
# echo "TMUX was not found!";
#fi
#