Skip to content

Commit 6e7b291

Browse files
authored
Merge pull request #2048 from gaelicWizard/theme/liquidprompt
2 parents c68eca0 + 720d3a8 commit 6e7b291

File tree

3 files changed

+61
-49
lines changed

3 files changed

+61
-49
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ tmp/
2222
profiles/*
2323
# apart from the default one
2424
!profiles/default.bash_it
25+
26+
/vendor/github.com/nojhan/liquidprompt

clean_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ themes/githelpers.theme.bash
6565
themes/gitline
6666
themes/inretio
6767
themes/lambda
68+
themes/liquidprompt
6869
themes/modern
6970
themes/norbu
7071
themes/oh-my-posh
Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,95 @@
1-
#!/usr/bin/env bash
2-
# Wrapper to use liquidprompt with bashit
1+
# shellcheck shell=bash
2+
# shellcheck disable=SC2034 # expected behavior for themes
3+
# Wrapper to use liquidprompt with _Bash It_
34

4-
targetdir="$BASH_IT/themes/liquidprompt/liquidprompt"
55
gray="\[\e[1;90m\]"
66

7-
cwd="$PWD"
8-
if cd "$targetdir" &> /dev/null && git rev-parse --is-inside-work-tree &> /dev/null; then
9-
true
10-
else
11-
git clone https://github.com/nojhan/liquidprompt.git "$targetdir" \
12-
&& echo -e "Successfully cloned liquidprompt!\n More configuration in '$targetdir/liquid.theme'."
7+
## Download repository if needed
8+
__bash_it_theme_liquidprompt_path="github.com/nojhan/liquidprompt"
9+
__bash_it_theme_liquidprompt_dir="${BASH_IT?}/vendor/${__bash_it_theme_liquidprompt_path}"
10+
if [[ ! -d "${__bash_it_theme_liquidprompt_dir}" ]]; then
11+
if git clone --branch stable "https://${__bash_it_theme_liquidprompt_path}" "${__bash_it_theme_liquidprompt_dir}"; then
12+
__bash_it_theme_liquidprompt_lqprc="${XDG_CONFIG_HOME:-"$HOME/.config"}/liquidpromptrc"
13+
__bash_it_theme_liquidprompt_tilde='~'
14+
if [[ ! -e "${__bash_it_theme_liquidprompt_lqprc}" ]]; then
15+
# shellcheck disable=SC2016 disable=SC1003
16+
sed -e 's/^LP_/#LP_/g' -e 's;#LOCAL_RCFILE=$HOME/.liquidpromptrc.local;LOCAL_RCFILE=${BASH_SOURCE[0]}.local;g' -e 's/#\[ -f "$LOCAL_RCFILE" \] && source "$LOCAL_RCFILE"/if [[ -s $LOCAL_RCFILE ]]; then\'$'\n\t''source "$LOCAL_RCFILE"\'$'\n''fi/g' < "${__bash_it_theme_liquidprompt_dir}/liquidpromptrc-dist" > "${__bash_it_theme_liquidprompt_lqprc}"
17+
fi
18+
echo -e "Successfully cloned liquidprompt!\n More configuration in '${__bash_it_theme_liquidprompt_lqprc//$HOME/$__bash_it_theme_liquidprompt_tilde}' (or '${__bash_it_theme_liquidprompt_lqprc//$HOME/$__bash_it_theme_liquidprompt_tilde}.local')."
19+
fi
1320
fi
14-
cd "$cwd"
15-
16-
export LP_ENABLE_TIME=1
17-
export LP_HOSTNAME_ALWAYS=1
18-
export LP_USER_ALWAYS=1
19-
export LP_MARK_LOAD="📈 "
20-
export LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75}
21-
export LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60}
22-
export LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-80}
23-
24-
unset _lp_legacy _lp_escape __lp_escape
25-
source "$targetdir/liquidprompt"
26-
prompt() { true; }
27-
export PS2=""
28-
export LP_PS1_PREFIX="┌─"
29-
export LP_PS1_POSTFIX="\n└▪ "
30-
export LP_ENABLE_RUNTIME=0
3121

32-
_lp_legacy() {
33-
type -t _lp_escape &> /dev/null
34-
}
22+
## Configure theme
23+
LP_MARK_LOAD="📈 "
24+
: "${LP_ENABLE_TIME:=1}"
25+
: "${LP_HOSTNAME_ALWAYS:=1}"
26+
: "${LP_USER_ALWAYS:=1}"
27+
: "${LP_BATTERY_THRESHOLD:=75}"
28+
: "${LP_LOAD_THRESHOLD:=60}"
29+
: "${LP_TEMP_THRESHOLD:=80}"
3530

36-
_lp_legacy && __lp_escape() {
37-
ret="$(_lp_escape "$@")"
38-
}
31+
## Load theme, but don't activate
32+
# shellcheck source-path=SCRIPTDIR/../../vendor/github.com/nojhan/liquidprompt
33+
source "${__bash_it_theme_liquidprompt_dir}/liquidprompt" --no-activate
3934

40-
_lp_git_branch() {
41-
((LP_ENABLE_GIT)) || return
35+
## Activate theme, without clobbering `bash-preexec`
36+
LP_OLD_PS1="${PROMPT:-${PS1:-\$ }}"
37+
LP_OLD_PROMPT_COMMAND=""
38+
function prompt_on() { :; }
39+
function prompt_off() { :; }
40+
function prompt_OFF() { :; }
41+
# shellcheck disable=SC2119
42+
TERM_PROGRAM=not_apple_terminal LP_ENABLE_RUNTIME=0 LP_ENABLE_RUNTIME_BELL=0 lp_activate
43+
safe_append_preexec '__lp_runtime_before'
44+
safe_append_prompt_command '__lp_set_prompt'
4245

43-
\git rev-parse --is-inside-work-tree > /dev/null 2>&1 || return
46+
## Override upstream defaults
47+
PS2=""
48+
LP_PS1_PREFIX="┌─"
49+
LP_PS1_POSTFIX="\n└▪ "
50+
LP_ENABLE_RUNTIME=0
4451

45-
local commit branch ret
52+
function _lp_git_branch() {
53+
((${LP_ENABLE_GIT:-0})) || return
4654

47-
commit="$(\git rev-parse --short -q HEAD 2> /dev/null)"
55+
command git rev-parse --is-inside-work-tree > /dev/null 2>&1 || return
4856

57+
local branch
4958
# Recent versions of Git support the --short option for symbolic-ref, but
5059
# not 1.7.9 (Ubuntu 12.04)
51-
if branch="$(\git symbolic-ref -q HEAD)"; then
52-
__lp_escape "$commit:${branch#refs/heads/}"
53-
lp_vcs_branch="$ret"
60+
if branch="$(command git symbolic-ref -q HEAD)"; then
61+
_lp_escape "$(command git rev-parse --short=5 -q HEAD 2> /dev/null):${branch#refs/heads/}"
5462
else
5563
# In detached head state, use commit instead
5664
# No escape needed
57-
lp_vcs_branch="$commit"
65+
command git rev-parse --short -q HEAD 2> /dev/null
5866
fi
59-
_lp_legacy && echo $lp_vcs_branch || return 0
6067
}
6168

62-
_lp_time() {
63-
if ((LP_ENABLE_TIME)) && ((!LP_TIME_ANALOG)); then
64-
LP_TIME="${gray}$(date +%d-%H:%M)${normal}"
69+
function _lp_time() {
70+
if ((LP_ENABLE_TIME)) && ((!${LP_TIME_ANALOG:-0})); then
71+
LP_TIME="${gray?}\D{${THEME_CLOCK_FORMAT:-"%d-%H:%M"}}${normal?}"
6572
else
6673
LP_TIME=""
6774
fi
6875
}
6976

7077
# Implementation using lm-sensors
71-
_lp_temp_sensors() {
78+
function _lp_temp_sensors() {
7279
local -i i
7380
for i in $(sensors -u \
7481
| sed -n 's/^ temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do
75-
(($i > ${temperature:-0})) && (($i != 127)) && temperature=i
82+
((i > ${temperature:-0})) && ((i != 127)) && temperature=i
7683
done
7784
}
7885

7986
# Implementation using 'acpi -t'
80-
_lp_temp_acpi() {
87+
function _lp_temp_acpi() {
8188
local -i i
8289
for i in $(LANG=C acpi -t \
8390
| sed 's/.* \(-\?[0-9]*\)\.[0-9]* degrees C$/\1/p'); do
84-
(($i > ${temperature:-0})) && (($i != 127)) && temperature=i
91+
((i > ${temperature:-0})) && ((i != 127)) && temperature=i
8592
done
8693
}
94+
95+
unset "${!__bash_it_theme_liquidprompt_@}"

0 commit comments

Comments
 (0)