Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/omb-prompt-base: Set a timeout on git commands #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/omb-prompt-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SCM_GIT_BEHIND_CHAR="↓"
SCM_GIT_UNTRACKED_CHAR="?:"
SCM_GIT_UNSTAGED_CHAR="U:"
SCM_GIT_STAGED_CHAR="S:"
SCM_GIT_TIMEOUT="0.2"

SCM_HG='hg'
SCM_HG_CHAR='☿'
Expand Down Expand Up @@ -105,9 +106,27 @@ function _omb_prompt_format {
}

function _omb_prompt_git {
command git "$@"
_omb_prompt_timeout "$SCM_GIT_TIMEOUT" command git "$@"
}

## @fn _omb_prompt_timeout
## Runs the given command with the given timeout
## @param $1 Timeout in seconds
## @param $@ Command to be executed.
if _omb_util_command_exists timeout; then
function _omb_prompt_timeout {
timeout "$@"
}
elif _omb_util_command_exists gtimeout; then
function _omb_prompt_timeout {
gtimeout "$@"
}
else
function _omb_prompt_timeout {
"${@:2}"
}
fi

function scm {
if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE
elif [[ -f .git/HEAD ]]; then SCM=$SCM_GIT
Expand Down
Loading