Skip to content

Commit

Permalink
Replace LP_DISABLED_VCS_PATH with array variable
Browse files Browse the repository at this point in the history
Having a config var that stores paths as one string separated by a
specific char is a error waiting to happen. It's much safer (and easier
to read) to use a true array. This would be a breaking change, so
deprecate LP_DISABLED_VCS_PATH, and add LP_DISABLED_VCS_PATHS array. Add
a conversion function in the config file loading section.

An example config change would be:
    LP_DISABLED_VCS_PATH="/my/one/path:/my/other/path"
to
    LP_DISABLED_VCS_PATHS=("/my/one/path" "/my/other/path")
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent f434b6d commit cad6286
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 16 additions & 7 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ _lp_source_config()
LP_ENABLE_SCREEN_TITLE=${LP_ENABLE_SCREEN_TITLE:-0}
LP_ENABLE_SSH_COLORS=${LP_ENABLE_SSH_COLORS:-0}
LP_ENABLE_FQDN=${LP_ENABLE_FQDN:-0}
# LP_DISABLED_VCS_PATH="${LP_DISABLED_VCS_PATH}"
LP_DISABLED_VCS_PATHS=("${LP_DISABLED_VCS_PATHS[@]-}")
LP_ENABLE_SUDO=${LP_ENABLE_SUDO:-0}

LP_MARK_DEFAULT="${LP_MARK_DEFAULT:-$_LP_MARK_SYMBOL}"
Expand Down Expand Up @@ -417,6 +417,16 @@ _lp_source_config()
fi
done

if [[ -n "${LP_DISABLED_VCS_PATH-}" ]]; then
echo "liquidprompt: LP_DISABLED_VCS_PATH is deprecated. Update your config to use LP_DISABLED_VCS_PATHS array." >&2

$_LP_SHELL_zsh && setopt local_options && setopt sh_word_split
local path IFS=:
for path in $LP_DISABLED_VCS_PATH; do
LP_DISABLED_VCS_PATHS+=("$path")
done
fi

# Delete this code in version 1.11
if [[ -n "${LP_COLORMAP_1-}" ]]; then
echo "liquidprompt: LP_COLORMAP_x variables are deprecated. Update your theme to use LP_COLORMAP array." >&2
Expand Down Expand Up @@ -567,7 +577,7 @@ lp_activate() {
LP_COLOR_PATH="${LP_COLOR_PATH_ROOT}"
# Disable VCS info for all paths
if (( ! LP_ENABLE_VCS_ROOT )); then
LP_DISABLED_VCS_PATH=/
LP_DISABLED_VCS_PATHS=("/")
LP_MARK_DISABLED="$LP_MARK_DEFAULT"
fi
fi
Expand Down Expand Up @@ -874,12 +884,11 @@ _lp_jobcount_color() {

_lp_are_vcs_enabled()
{
[[ -z "$LP_DISABLED_VCS_PATH" ]] && return 0
$_LP_SHELL_zsh && setopt local_options && setopt sh_word_split
local path
local IFS=:
for path in $LP_DISABLED_VCS_PATH; do
[[ "$PWD" == *"$path"* ]] && return 1
for path in "${LP_DISABLED_VCS_PATHS[@]}"; do
if [[ -n "$path" && "$PWD" == "$path"* ]]; then
return 1
fi
done
return 0
}
Expand Down
6 changes: 3 additions & 3 deletions liquidpromptrc-dist
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ LP_ENABLE_SCREEN_TITLE=0
# Use different colors for the different hosts you SSH to
LP_ENABLE_SSH_COLORS=0

# Specify a list of complete and colon (":") separated paths in which, all vcs
# will be disabled
LP_DISABLED_VCS_PATH=""
# Specify an array of absolute paths in which all vcs will be disabled.
# Ex: ("/root" "/home/me/large-remove-svn-repo")
LP_DISABLED_VCS_PATHS=()

# vim: set et sts=4 sw=4 tw=120 ft=sh:

0 comments on commit cad6286

Please sign in to comment.