git-prompt + TMOUT

git-prompt + TMOUT

我最近发现 bash TMOUT,对我来说,它在正常会话中工作正常,但与 git-prompt 结合时,似乎不遵守超时规定——shell 无限期地保持打开状态。

我尝试搜索,但没有找到真正符合我描述的东西,我试过了“TMOUT” 和 “PROMPT_COMMAND”但没有符合我的问题的结果。

有什么提示我可以看看吗?

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK
$2 ls -la
total 20
drwx------  3 cschulz cschulz  4096 Oct 27 14:40 .
drwxrwxrwt 95 root    root    12288 Oct 27 14:40 ..
drwxrwxr-x  3 cschulz cschulz  4096 Oct 27 14:40 git

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK
$2 bash; echo "Bash quit"

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK
$3 TMOUT=1

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK
timed out waiting for input: auto-logout
Bash quit

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK
$2

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK/git
[master # ]$2 ls -la
total 12
drwxrwxr-x 3 cschulz cschulz 4096 Oct 27 14:40 .
drwx------ 3 cschulz cschulz 4096 Oct 27 14:40 ..
drwxrwxr-x 7 cschulz cschulz 4096 Oct 27 14:40 .git

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK/git
[master # ]$2 bash; echo "Bash quit"

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK/git
[master # ]$3 TMOUT=1

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK/git
[master # ]$3 date
Thu 27 Oct 14:43:21 CEST 2022

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK/git
[master # ]$3 date
Thu 27 Oct 14:43:24 CEST 2022

cschulz@DESKTOP-FL37PIH:/tmp/tmp.dLEDcMLmDK/git
[master # ]$3
# my PROMPT_COMMAND

cschulz@DESKTOP-FL37PIH:~
$2 echo $PROMPT_COMMAND
__git_ps1 "\n\[\033[01;32m\]\u\[\033[01;00m\]@\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\n\[\033[00m\]" "\\\$$([ $SHLVL -gt 1 ] && echo $SHLVL) " "[%s $(get_sha)]"

cschulz@DESKTOP-FL37PIH:~
$2 type get_sha
get_sha is a function
get_sha ()
{
    git rev-parse --short HEAD 2> /dev/null
}

# _git_ps1 comes from /usr/lib/git-core/git-sh-prompt, from git 1:2.34.1-1ubuntu1.4

答案1

似乎以下代码片段导致TMOUT被忽略,我将其注释掉,现在我的代码TMOUT在 git 存储库中也能按预期工作。:)

        #while read -r key value; do
        #       case "$key" in
        #       bash.showupstream)
        #               GIT_PS1_SHOWUPSTREAM="$value"
        #               if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
        #                       p=""
        #                       return
        #               fi
        #               ;;
        #       svn-remote.*.url)
        #               svn_remote[$((${#svn_remote[@]} + 1))]="$value"
        #               svn_url_pattern="$svn_url_pattern\\|$value"
        #               upstream=svn+git # default upstream is SVN if available, else git
        #               ;;
        #       esac
        #done <<< "$output"

相关内容