1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-12-22 13:31:40 +01:00

theme: fix on OS X

MacOS' sed syntax is different from GNU's. A workaround
is to use gsed (GNU sed) whenever it is available.
The multi-line prompt will be broken without gsed.
This commit is contained in:
bretello 2020-12-09 10:53:52 +01:00
parent 0e3e7cd155
commit 8a6cda547b

View File

@ -128,13 +128,25 @@ _PROMPT_PROTO='$(virtualenv_info)$(user_prompt)$(path_prompt)$(git_prompt)$(job_
function prompt_too_long(){
local zero='%([BSUbfksu]|([FK]|){*})'
local stripped="$(echo ${(S%%)_PROMPT_PROTO//$~zero/} | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" ) "
if [[ -x $commands[gsed] ]]; then # fuck darwin
sed='gsed'
elif [[ "$(uname)" == "Darwin" ]]; then
local msg="error: multi-line prompt requires GNU sed"
msg+="install with \"brew install gnu-sed\""
echo "$msg"
return
else
sed='sed'
fi
local stripped="$(echo ${(S%%)_PROMPT_PROTO//$~zero/} | $sed 's|\x1B\[[0-9;]*[a-zA-Z]||g')"
local prompt_len=${#stripped}
local max_len=$(($COLUMNS/2))
if [[ $prompt_len -ge $max_len ]]; then
echo true
fi
}
PROMPT="$(echo "$_PROMPT_PROTO")"
NEWLINE=$'\n'
PROMPT+='${$(prompt_too_long)/true/${NEWLINE}}'