在zsh提示符下更改当前工作目录的路径
我正试图修改一个现有的zsh提示符来使用zsh 5.0和4.3,因为这些版本是我使用的系统的版本如何使zsh脚本知道当前工作目录而不是文件所在的目录? 就上下文而言 这是脚本中的一个函数,用于检查当前是否在git目录中,并在以下情况下添加到提示:在zsh提示符下更改当前工作目录的路径,zsh,zshrc,Zsh,Zshrc,我正试图修改一个现有的zsh提示符来使用zsh 5.0和4.3,因为这些版本是我使用的系统的版本如何使zsh脚本知道当前工作目录而不是文件所在的目录? 就上下文而言 这是脚本中的一个函数,用于检查当前是否在git目录中,并在以下情况下添加到提示: # Git status. # Collect indicators, git branch and pring string. spaceship_git_status() { [[ $SPACESHIP_GIT_SHOW == false ]]
# Git status.
# Collect indicators, git branch and pring string.
spaceship_git_status() {
[[ $SPACESHIP_GIT_SHOW == false ]] && return
# Check if the current directory is in a Git repository.
command git rev-parse --is-inside-work-tree &>/dev/null || return
# Check if the current directory is in .git before running git checks.
if [[ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]]; then
# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null
# String of indicators
local indicators=''
indicators+="$(spaceship_git_uncomitted)"
indicators+="$(spaceship_git_unstaged)"
indicators+="$(spaceship_git_untracked)"
indicators+="$(spaceship_git_stashed)"
indicators+="$(spaceship_git_unpushed_unpulled)"
[ -n "${indicators}" ] && indicators=" [${indicators}]";
echo -n " %Bon%b "
echo -n "%{$fg_bold[magenta]%}"
echo -n "$(git_current_branch)"
echo -n "%{$reset_color%}"
echo -n "%{$fg_bold[red]%}"
echo -n "$indicators"
echo -n "%{$reset_color%}"
fi
}
但是,根据我的调试,函数似乎始终认为它位于脚本的源目录中。换句话说,当我更改目录时,脚本将继续引用脚本所在的目录
此处调用spaceship\u git\u status
函数:
# Build prompt line
spaceship_build_prompt() {
spaceship_host
spaceship_current_dir
spaceship_git_status
spaceship_nvm_status
spaceship_ruby_version
spaceship_venv_status
}
这是提示符
环境变量:
# Compose PROMPT
PROMPT=''
[[ $SPACESHIP_PROMPT_ADD_NEWLINE == true ]] && PROMPT="$PROMPT$NEWLINE"
PROMPT="$PROMPT $(spaceship_build_prompt) "
[[ $SPACESHIP_PROMPT_SEPARATE_LINE == true ]] && PROMPT="$PROMPT$NEWLINE"
PROMPT="$PROMPT $(spaceship_return_status) "
我认为这是zsh版本<5.2的一个问题,因为在我的另一台5.2计算机上,提示符显示得很好
完整代码: