optimisation : less operation

This commit is contained in:
François Schmidts 2013-01-10 10:56:13 +01:00
parent 977fca59fb
commit dfea80c397

View File

@ -497,22 +497,18 @@ _lp_shorten_path()
_lp_get_dirtrim() { _lp_get_dirtrim() {
[[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] && echo 0 && return [[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] && echo 0 && return
local tot local p="${PWD/$HOME/~}"
[[ "$PWD" == *$HOME* ]] && tot="$((${#PWD}-${#HOME}+1))" || tot="${#PWD}" local len=${#p}
local max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100)) local max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100))
local PROMPT_DIRTRIM=0 local PROMPT_DIRTRIM=0
if [[ "$((tot))" -gt "$((max_len))" ]]; then if [[ "$((len))" -gt "$((max_len))" ]]; then
local i local i
local len=0
local p="$(echo $PWD | rev)"
local IFS="/" for ((i=$len;i>=0;i--))
for i in $p
do do
len="$((len+${#i}))" [[ $(($len-$i)) -gt $max_len ]] && break
[[ "$((len))" -gt "$((max_len))" ]] && break [[ "${p:i:1}" == "/" ]] && PROMPT_DIRTRIM=$((PROMPT_DIRTRIM+1))
PROMPT_DIRTRIM=$((PROMPT_DIRTRIM+1))
done done
[[ "$((PROMPT_DIRTRIM))" -eq 0 ]] && PROMPT_DIRTRIM=1 [[ "$((PROMPT_DIRTRIM))" -eq 0 ]] && PROMPT_DIRTRIM=1
fi fi