종료자 창 크기를 조정할 때 zsh를 다시 로드하십시오.

종료자 창 크기를 조정할 때 zsh를 다시 로드하십시오.

항원과 함께 zsh와 함께 터미네이터를 사용하고 있습니다. 내가 사용하고 있는 테마(af-magic의 수정된 버전)는 현재 창 너비를 검색하고 =별도의 입력에 대한 기호로 구성된 막대를 인쇄합니다.

# af-magic.zsh-theme
# Repo: https://github.com/andyfleming/oh-my-zsh
# Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme

if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"

# primary prompt

BAR=$(printf '=%.0s' {1..$(tput cols)})

PROMPT='$FG[237]$BAR%{$reset_color%}
$FG[032]%~\
$(git_prompt_info) \
$FG[105]%(!.#.»)%{$reset_color%} '
PROMPT2='%{$fg[red]%}\ %{$reset_color%}'
RPS1='${return_code}'


# color vars
eval my_gray='$FG[237]'
eval my_orange='$FG[214]'

# right prompt
if type "virtualenv_prompt_info" > /dev/null
then
    RPROMPT='$(virtualenv_prompt_info)$my_gray%n@%m%{$reset_color%}%'
else
    RPROMPT='$my_gray%n@%m%{$reset_color%}%'
fi

# git settings
ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075](branch:"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
# af-magic.zsh-theme
# Repo: https://github.com/andyfleming/oh-my-zsh
# Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme

if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"

# primary prompt

BAR=$(printf '=%.0s' {1..$(tput cols)})

PROMPT='$FG[237]$BAR%{$reset_color%}
$FG[032]%~\
$(git_prompt_info) \
$FG[105]%(!.#.»)%{$reset_color%} '
PROMPT2='%{$fg[red]%}\ %{$reset_color%}'
RPS1='${return_code}'


# color vars
eval my_gray='$FG[237]'
eval my_orange='$FG[214]'

# right prompt
if type "virtualenv_prompt_info" > /dev/null
then
    RPROMPT='$(virtualenv_prompt_info)$my_gray%n@%m%{$reset_color%}%'
else
    RPROMPT='$my_gray%n@%m%{$reset_color%}%'
fi

# git settings
ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075](branch:"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"

이것은 꽤 잘 작동하지만 창 크기를 조정할 때 BAR업데이트되지 않으므로 너무 짧거나 길어서 여러 줄이 필요합니다. 예:

|==================================================================|
|~ »                                                               |

된다

|==================================================| 
|================                                  | <- window border
|~ »                                               |

창 크기를 조정할 때 zsh 또는 터미네이터가 테마를 다시 로드하도록 하는 방법이 있습니까?

답변1

터미널의 크기가 조정되면 쉘은시그윈치신호. 따라서 BAR트랩에서 업데이트하십시오. zsh에서는 해당 항목을 정의할 수 있습니다.트랩 기능:

TRAPWINCH () {
  BAR=$(printf '=%.0s' {1..$COLUMNS})
}

tputzsh는 터미널의 열 수를 추적하므로 호출할 필요가 없습니다.COLUMNS변하기 쉬운.

반드시 켜주세요.prompt_subst옵션( setopt prompt_subst)을 사용 $PROMPT하여 표시될 때마다 재평가됩니다. 또는 업데이트도 가능 PROMPT합니다 TRAPWINCH.

이상한 방식으로 전화를 걸기보다는 다음을 printf사용할 수 있습니다.매개변수 확장패딩된 문자열을 얻으려면. 매개변수 확장은 일반적으로 변수 값에서 작동하지만 대신 문자열(이 경우 빈 문자열)에서 작업할 수 있습니다. 이렇게 하면 트랩이 전혀 필요하지 않습니다.${:-STRING}

setopt prompt_subst
PROMPT='$FG[237]${(l:$COLUMNS::=:):-}%{$reset_color%}

답변2

인용하려면이 답변:

다음을 확인하세요.prompt_subst 옵션켜져 있습니다. 필요한 경우 다음 줄을 다음 줄에 추가하세요 ~/.zshrc.

setopt prompt_subst

이는 zsh가 프롬프트를 표시할 때마다 프롬프트 문자열을 재평가하도록 지시합니다..

답변3

$BAR을 함수로 바꿔야 합니다.

function bar {
    echo `printf '=%.0s' {1..$(tput cols)}`
}

관련 정보