From 9af664f4cbaffd17327e145657f04ea9780b0ac6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 18 Jan 2022 14:50:27 -0800 Subject: [PATCH] theme/liquidprompt: `shellcheck` --- clean_files.txt | 1 + themes/liquidprompt/liquidprompt.theme.bash | 96 ++++++++++----------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 9c4f530174..40cf4576cf 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -151,6 +151,7 @@ themes/candy themes/command_duration.theme.bash themes/easy themes/essential +themes/liquidprompt themes/modern themes/powerline themes/pure diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 0a271e1b4d..4bbae46014 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -1,78 +1,76 @@ # shellcheck shell=bash -# Wrapper to use liquidprompt with bashit +# shellcheck disable=SC2034 # expected behavior for themes +# Wrapper to use liquidprompt with _Bash It_ gray="\[\e[1;90m\]" +## Download repository if needed _bash_it_theme_liquidprompt_path="github.com/nojhan/liquidprompt" _bash_it_theme_liquidprompt_dir="${BASH_IT?}/vendor/${_bash_it_theme_liquidprompt_path}" -if pushd "${_bash_it_theme_liquidprompt_dir}" &>/dev/null || return; then - if git rev-parse --is-inside-work-tree &>/dev/null; then - true - else - git clone "https://${_bash_it_theme_liquidprompt_path}" "${_bash_it_theme_liquidprompt_dir}" && \ - echo -e "Successfully cloned liquidprompt!\n More configuration in '$_bash_it_theme_liquidprompt_dir/liquid.theme'." - fi - popd "$cwd" || return +if [[ ! -d "${_bash_it_theme_liquidprompt_dir}" ]]; then + git clone "https://${_bash_it_theme_liquidprompt_path}" "${_bash_it_theme_liquidprompt_dir}" \ + && echo -e "Successfully cloned liquidprompt!\n More configuration in '$_bash_it_theme_liquidprompt_dir/liquid.theme'." fi unset "${!_bash_it_theme_liquidprompt_@}" -LP_ENABLE_TIME=1 -LP_HOSTNAME_ALWAYS=1 -LP_USER_ALWAYS=1 +## Configure theme LP_MARK_LOAD="šŸ“ˆ " -LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75} -LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60} -LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-80} +: "${LP_ENABLE_TIME:=1}" +: "${LP_HOSTNAME_ALWAYS:=1}" +: "${LP_USER_ALWAYS:=1}" +: "${LP_BATTERY_THRESHOLD:=75}" +: "${LP_LOAD_THRESHOLD:=60}" +: "${LP_TEMP_THRESHOLD:=80}" +## Load theme # shellcheck source-path=SCRIPTDIR/../../vendor/github.com/nojhan/liquidprompt source "${_bash_it_theme_liquidprompt_dir}/liquidprompt" + +## Override upstream defaults PS2=" ā”ƒ " LP_PS1_PREFIX="ā”Œā”€" LP_PS1_POSTFIX="\nā””ā–Ŗ " LP_ENABLE_RUNTIME=0 -_lp_git_branch() -{ - (( LP_ENABLE_GIT )) || return +function _lp_git_branch() { + ((${LP_ENABLE_GIT:-0})) || return - command git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return + command git rev-parse --is-inside-work-tree > /dev/null 2>&1 || return - local branch - # Recent versions of Git support the --short option for symbolic-ref, but - # not 1.7.9 (Ubuntu 12.04) - if branch="$(command git symbolic-ref -q HEAD)"; then - _lp_escape "$(command git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" - else - # In detached head state, use commit instead - # No escape needed - command git rev-parse --short -q HEAD 2>/dev/null - fi + local branch + # Recent versions of Git support the --short option for symbolic-ref, but + # not 1.7.9 (Ubuntu 12.04) + if branch="$(command git symbolic-ref -q HEAD)"; then + _lp_escape "$(command git rev-parse --short=5 -q HEAD 2> /dev/null):${branch#refs/heads/}" + else + # In detached head state, use commit instead + # No escape needed + command git rev-parse --short -q HEAD 2> /dev/null + fi } -_lp_time() { - if (( LP_ENABLE_TIME )) && (( ! LP_TIME_ANALOG )); then - LP_TIME="${gray?}\D{${THEME_CLOCK_FORMAT:-"%d-%H:%M"}}${normal?}" - else - LP_TIME="" - fi +function _lp_time() { + if ((LP_ENABLE_TIME)) && ((!${LP_TIME_ANALOG:-0})); then + LP_TIME="${gray?}\D{${THEME_CLOCK_FORMAT:-"%d-%H:%M"}}${normal?}" + else + LP_TIME="" + fi } # Implementation using lm-sensors -_lp_temp_sensors() -{ - local -i i - for i in $(sensors -u | - sed -n 's/^ temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do - (( i > ${temperature:-0} )) && (( i != 127 )) && temperature=i - done +function _lp_temp_sensors() { + local -i i + for i in $(sensors -u \ + | sed -n 's/^ temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do + ((i > ${temperature:-0})) && ((i != 127)) && temperature=i + done } # Implementation using 'acpi -t' -_lp_temp_acpi() -{ - local -i i - for i in $(LANG=C acpi -t | - sed 's/.* \(-\?[0-9]*\)\.[0-9]* degrees C$/\1/p'); do - (( i > ${temperature:-0} )) && (( i != 127 )) && temperature=i - done +function _lp_temp_acpi() { + local -i i + for i in $(LANG=C acpi -t \ + | sed 's/.* \(-\?[0-9]*\)\.[0-9]* degrees C$/\1/p'); do + ((i > ${temperature:-0})) && ((i != 127)) && temperature=i + done }