_lp_shorten_path: clean variable usage inside (( ))
This commit is contained in:
parent
ddac1d8ec5
commit
2da0c12fd1
12
liquidprompt
12
liquidprompt
@ -579,13 +579,13 @@ _lp_shorten_path()
|
|||||||
|
|
||||||
local p="$(_lp_get_home_tilde_collapsed)"
|
local p="$(_lp_get_home_tilde_collapsed)"
|
||||||
local mask="${LP_MARK_SHORTEN_PATH}"
|
local mask="${LP_MARK_SHORTEN_PATH}"
|
||||||
local -i max_len=$(( ${COLUMNS:-80} * $LP_PATH_LENGTH / 100 ))
|
local -i max_len=$(( ${COLUMNS:-80} * LP_PATH_LENGTH / 100 ))
|
||||||
|
|
||||||
if [[ ${LP_PATH_KEEP} == -1 ]]; then
|
if [[ ${LP_PATH_KEEP} == -1 ]]; then
|
||||||
# only show the current directory, excluding any parent dirs
|
# only show the current directory, excluding any parent dirs
|
||||||
ret="${p##*/}" # discard everything up to and including the last slash
|
ret="${p##*/}" # discard everything up to and including the last slash
|
||||||
[[ "${ret}" == "" ]] && ret="/" # if in root directory
|
[[ "${ret}" == "" ]] && ret="/" # if in root directory
|
||||||
elif (( ${#p} <= ${max_len} )); then
|
elif (( ${#p} <= max_len )); then
|
||||||
ret="${p}"
|
ret="${p}"
|
||||||
elif [[ ${LP_PATH_KEEP} == 0 ]]; then
|
elif [[ ${LP_PATH_KEEP} == 0 ]]; then
|
||||||
# len is over max len, show as much of the tail as is allowed
|
# len is over max len, show as much of the tail as is allowed
|
||||||
@ -598,8 +598,8 @@ _lp_shorten_path()
|
|||||||
local tmp=${p//\//}
|
local tmp=${p//\//}
|
||||||
local -i delims=$(( ${#p} - ${#tmp} ))
|
local -i delims=$(( ${#p} - ${#tmp} ))
|
||||||
|
|
||||||
for (( dir=0; dir < ${LP_PATH_KEEP}; dir++ )); do
|
for (( dir=0; dir < LP_PATH_KEEP; dir++ )); do
|
||||||
(( ${dir} == ${delims} )) && break
|
(( dir == delims )) && break
|
||||||
|
|
||||||
local left="${p#*/}"
|
local left="${p#*/}"
|
||||||
local name="${p:0:${#p} - ${#left}}"
|
local name="${p:0:${#p} - ${#left}}"
|
||||||
@ -607,7 +607,7 @@ _lp_shorten_path()
|
|||||||
ret="${ret}${name%/}/"
|
ret="${ret}${name%/}/"
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( ${delims} <= ${LP_PATH_KEEP} )); then
|
if (( delims <= LP_PATH_KEEP )); then
|
||||||
# no dirs between LP_PATH_KEEP leading dirs and current dir
|
# no dirs between LP_PATH_KEEP leading dirs and current dir
|
||||||
ret="${ret}${p##*/}"
|
ret="${ret}${p##*/}"
|
||||||
else
|
else
|
||||||
@ -617,7 +617,7 @@ _lp_shorten_path()
|
|||||||
|
|
||||||
[[ ${ret} != "/" ]] && ret="${ret%/}" # strip trailing slash
|
[[ ${ret} != "/" ]] && ret="${ret%/}" # strip trailing slash
|
||||||
|
|
||||||
local -i len_left=$(( ${max_len} - ${#ret} - ${#base} - ${#mask} ))
|
local -i len_left=$(( max_len - ${#ret} - ${#base} - ${#mask} ))
|
||||||
|
|
||||||
ret="${ret}${mask}${p:${#p} - ${len_left}}${base}"
|
ret="${ret}${mask}${p:${#p} - ${len_left}}${base}"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user