以下代码摘自here http://eseth.org/2010/git-in-zsh.html:
function +vi-git-st() {
local ahead behind remote
local -a gitstatus
# Are we on a remote-tracking branch?
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
if [[ -n ${remote} ]] ; then
# for git prior to 1.7
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
(( $ahead )) && gitstatus+=( "${c3}+${ahead}${c2}" )
# for git prior to 1.7
# behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
(( $behind )) && gitstatus+=( "${c4}-${behind}${c2}" )
hook_com[branch]="${hook_com[branch]} [${remote} ${(j:/:)gitstatus}]"
fi
}
我不明白最后一行。多变的gitstatus
是一个数组,那么什么是${(j:/:)gitstatus}
应该做的?我知道它输出字符串first_array_element/second_array_element
但我没有找到有关操作员的任何文档j
。这是一些特定的 zsh 功能,还是标准的 shell 编程结构?
这是连接数组元素的参数扩展标志。看(j:...:) 标志 https://zsh.sourceforge.io/Guide/zshguide05.html#l124.
在这种特定情况下,它使用以下方式连接数组中的元素/
作为分隔符。例如。
zsh% foo=(1 2 3)
zsh% echo $foo
1 2 3
zsh% echo ${(j:/:)foo}
1/2/3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)