From 8a6cda547b0c954d5321a4f8001a3b414440faa6 Mon Sep 17 00:00:00 2001 From: bretello Date: Wed, 9 Dec 2020 10:53:52 +0100 Subject: [PATCH] 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. --- themes/brethil.zsh-theme | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/themes/brethil.zsh-theme b/themes/brethil.zsh-theme index c0557e4..11445f8 100644 --- a/themes/brethil.zsh-theme +++ b/themes/brethil.zsh-theme @@ -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}}'