错误PS1 GIT功能 - Gitbash与Cygwin之间的冲突
我正在收到以下错误,试图自定义我的PS1以获取GIT
错误:
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `get_dir)'
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `get_branch)'
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `parse_git_dirty)'
我的.bashrc
#...
function get_dir() {
[[ ${PWD} == $HOME ]] && echo '~' || echo ${PWD##*/}
}
function get_branch() {
[[ -d .git ]] && echo "$(git branch --show-current)"
}
#...
这很棘手!这首先要在我的Cygwin上完美工作,但是当我使用此语法“修复”时,在Gitbash上产生了这个错误
export PS1="${LIGHTGREEN}\t${NC} ${PINK}\$(get_dir)${NC}${LIGHTBLUE} \$(get_branch) ${NC}${RED}\$(parse_git_dirty)${NC} \n${GREEN}$ ${NC}"
,我没有错误,但没有动态工作。每次更改目录,
export PS1="${LIGHTGREEN}\t${NC} ${PINK}`get_dir`${NC}${LIGHTBLUE} `get_branch` ${NC}${RED}`parse_git_dirty`${NC} \n${GREEN}$ ${NC}"
即更改\ $(get_dir)
get_dir
I'm receiving the following error trying to customize my PS1 for git
Error:
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `get_dir)'
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `get_branch)'
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `parse_git_dirty)'
My .bashrc
#...
function get_dir() {
[[ ${PWD} == $HOME ]] && echo '~' || echo ${PWD##*/}
}
function get_branch() {
[[ -d .git ]] && echo "$(git branch --show-current)"
}
#...
Here's tricky! this first snipped worked perfectly on my Cygwin, but produce that error on Gitbash
export PS1="${LIGHTGREEN}\t${NC} ${PINK}\$(get_dir)${NC}${LIGHTBLUE} \$(get_branch) ${NC}${RED}\$(parse_git_dirty)${NC} \n${GREEN}$ ${NC}"
when I "fix it" using this syntax, I've got no error but it's NOT working dynamically. I Need to reload my .bashrc each time that I change the directory
export PS1="${LIGHTGREEN}\t${NC} ${PINK}`get_dir`${NC}${LIGHTBLUE} `get_branch` ${NC}${RED}`parse_git_dirty`${NC} \n${GREEN}$ ${NC}"
i.e. changed \$(get_dir)
to get_dir
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在尝试“修复”它时,您可以在
导出ps1
IS 执行时执行get_dir
。相反,每次生成新提示时,您都需要对其进行重新评估。也许最简单的方法是定义函数
my_prompt
,该>在调用时,计算PS1字符串,然后设置此功能,还可以使您在在提示符中激活函数之前调试函数。
In your attempt to "fix" it, you execute
get_dir
by the time theexport PS1
is executed.Instead, you need to have it reevaluated every time a new prompt is generated. The perhaps simplest way to do it is to define a function
my_prompt
which, when called, calculates the PS1 string, and then setThis also allows you to debug your function before you activate it in the prompt.