-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaudi.theme.bash
executable file
·105 lines (86 loc) · 3.85 KB
/
gaudi.theme.bash
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# shellcheck disable=SC1091,SC2034
GAUDI_FIRST_RUN=${GAUDI_FIRST_RUN:=true}
GAUDI_ROOT="${GAUDI_BASH}/components/themes/gaudi"
source "$GAUDI_ROOT/gaudi.configs.bash"
source "$GAUDI_ROOT/lib/utils.bash"
source "$GAUDI_ROOT/lib/colors.bash"
source "$GAUDI_ROOT/lib/scm.bash"
# Do not load if not an interactive shell
# Reference: https://github.com/nojhan/liquidprompt/issues/161
test -z "$TERM" -o "x$TERM" = xdumb && return
# Check for recent enough version of bash.
if test -n "${BASH_VERSION-}" -a -n "$PS1" ; then
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if (( bmajor < 4 || ( bmajor == 4 && bminor < 0 ) )); then
echo "The current bash version ${bash} is not supported by Gaudi [[ 4.0+ ]]"
unset bash bmajor bminor
return
fi
fi
gaudi::prompt () {
# Must be the very first line in all entry prompt functions, or the value
# will be overridden by a different command execution - do not move this line!
RETVAL=$?
[[ $GAUDI_FIRST_RUN == true ]] && RETVAL=0
# Terminal runs something like login -pfl your-username /bin/bash -c exec -la bash <bash path>
# when you create a new shell which lacks the -q flag. The problem is that when opening a new tab
# with "Same Working Directory" enabled, the current directory is searched for .hushlogin.
# Unless you put a .hushlogin in every single directory, it will only see ~/.hushlogin if you open a new tab when you're in ~.
# This is in direct conflict with the feature of preserving the current working directory
# This checks if we are using the MacOSX Terminal app and clear the screen before that
if [[ $TERM_PROGRAM == "Apple_Terminal" ]] && [[ $GAUDI_FIRST_RUN == true ]] && [[ $GAUDI_ENABLE_HUSHLOGIN == true ]]; then
# Clears and reset the lines printed in the terminal
unset GAUDI_FIRST_RUN
fi
# Check and kill any irreelvant background jobs
# Outdated background jobs are any gaudi::async_render executed on folders
# other than the current working directory $PWD
gaudi::kill_outdated_asyncRender
local PROMPT_CHAR
local COMPENSATE
local LEFT_PROMPT
local RIGHT_PROMPT
PROMPT_CHAR="${GREEN}>>${NC} "
COMPENSATE=58
LEFT_PROMPT="$(gaudi::render_prompt GAUDI_PROMPT_LEFT[@])"
RIGHT_PROMPT="$(gaudi::render_prompt GAUDI_PROMPT_RIGHT[@])"
# Check if we need to activate the two side theme split (LEFT_PROMPT ------ RIGHT RIGHT)
# Or we need to have the whole prompt in one line where (RIGHT_PROMPT LEFT_PROMPT)
if [[ $GAUDI_SPLIT_PROMPT == false ]]; then
PS1=$(printf "\n%b%b\n\n%b" "$RIGHT_PROMPT" "$LEFT_PROMPT" "$PROMPT_CHAR")
else
if [[ "$TERM" =~ "screen".* ]]; then
tmux set-option -g default-command bash
COMPENSATE=45
fi
[[ $GAUDI_SPLIT_PROMPT_TWO_LINES == true ]] && line_separator="\n" || line_separator="\r"
PS1=$(printf "\n%*b%s%b\n\n%b" "$(($(tput cols) + "$COMPENSATE"))" "$RIGHT_PROMPT" "$line_separator" "$LEFT_PROMPT" "$PROMPT_CHAR")
fi;
# Render the async part of the prompt .. lazy lazy
gaudi::render_async () {
local ASYNC_PROMPT
ASYNC_PROMPT="$(gaudi::render_prompt GAUDI_PROMPT_ASYNC[@])"
tput sc && tput cuu1 && tput cuu1
if [[ $GAUDI_SPLIT_PROMPT == false ]]; then
printf "\r%b%b%b" "$RIGHT_PROMPT" "$LEFT_PROMPT" "$ASYNC_PROMPT"
else
printf "\r%b%b" "$LEFT_PROMPT" "$ASYNC_PROMPT"
fi;
tput rc
}
# Load the PS2 continuation bash configuration
source "$GAUDI_ROOT/segments/continuation.bash"
# PS2 – Continuation interactive prompt
PS2=$(gaudi_continuation)
# The PS4 defined below in the ps4.sh has the following two codes:
# $0 – indicates the name of script
# $LINENO – displays the current line number within the script
PS4='$0.$LINENO+ '
# Check the async side of the prompt if available
set +m
gaudi::render_async &
## cleanup
unset LEFT_PROMPT RIGHT_PROMPT ASYNC_PROMPT
}
PROMPT_COMMAND=gaudi::prompt