|
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_ |
3 | 4 |
|
4 |
| -targetdir="$BASH_IT/themes/liquidprompt/liquidprompt" |
5 | 5 | gray="\[\e[1;90m\]"
|
6 | 6 |
|
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 |
13 | 20 | 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 |
31 | 21 |
|
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}" |
35 | 30 |
|
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 |
39 | 34 |
|
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' |
42 | 45 |
|
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 |
44 | 51 |
|
45 |
| - local commit branch ret |
| 52 | +function _lp_git_branch() { |
| 53 | + ((${LP_ENABLE_GIT:-0})) || return |
46 | 54 |
|
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 |
48 | 56 |
|
| 57 | + local branch |
49 | 58 | # Recent versions of Git support the --short option for symbolic-ref, but
|
50 | 59 | # 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/}" |
54 | 62 | else
|
55 | 63 | # In detached head state, use commit instead
|
56 | 64 | # No escape needed
|
57 |
| - lp_vcs_branch="$commit" |
| 65 | + command git rev-parse --short -q HEAD 2> /dev/null |
58 | 66 | fi
|
59 |
| - _lp_legacy && echo $lp_vcs_branch || return 0 |
60 | 67 | }
|
61 | 68 |
|
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?}" |
65 | 72 | else
|
66 | 73 | LP_TIME=""
|
67 | 74 | fi
|
68 | 75 | }
|
69 | 76 |
|
70 | 77 | # Implementation using lm-sensors
|
71 |
| -_lp_temp_sensors() { |
| 78 | +function _lp_temp_sensors() { |
72 | 79 | local -i i
|
73 | 80 | for i in $(sensors -u \
|
74 | 81 | | 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 |
76 | 83 | done
|
77 | 84 | }
|
78 | 85 |
|
79 | 86 | # Implementation using 'acpi -t'
|
80 |
| -_lp_temp_acpi() { |
| 87 | +function _lp_temp_acpi() { |
81 | 88 | local -i i
|
82 | 89 | for i in $(LANG=C acpi -t \
|
83 | 90 | | 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 |
85 | 92 | done
|
86 | 93 | }
|
| 94 | + |
| 95 | +unset "${!__bash_it_theme_liquidprompt_@}" |
0 commit comments