global: Use "command" to run "git" and "svn"

This commit is contained in:
Koichi Murase
2022-02-22 17:49:25 +09:00
parent d3e6411f54
commit 897876eae1
11 changed files with 37 additions and 37 deletions

View File

@@ -79,7 +79,7 @@ function _svn_grcut()
function _svn_info() function _svn_info()
{ {
local what=$1 line= local what=$1 line=
LANG=C LC_MESSAGES=C svn info --non-interactive 2> /dev/null | \ LANG=C LC_MESSAGES=C command svn info --non-interactive 2> /dev/null | \
while read line ; do while read line ; do
[[ $line == *"$what: "* ]] && echo ${line#*: } [[ $line == *"$what: "* ]] && echo ${line#*: }
done done
@@ -689,7 +689,7 @@ _svn()
# build status command and options # build status command and options
# "--quiet" removes 'unknown' files # "--quiet" removes 'unknown' files
local status='svn status --non-interactive' local status='command svn status --non-interactive'
[[ $SVN_BASH_COMPL_EXT == *recurse* ]] || \ [[ $SVN_BASH_COMPL_EXT == *recurse* ]] || \
status="$status --non-recursive" status="$status --non-recursive"

View File

@@ -82,7 +82,7 @@ function git_current_branch() {
# Gets the number of commits ahead from remote # Gets the number of commits ahead from remote
function git_commits_ahead() { function git_commits_ahead() {
if command git rev-parse --git-dir &>/dev/null; then if command git rev-parse --git-dir &>/dev/null; then
local commits="$(git rev-list --count @{upstream}..HEAD)" local commits="$(command git rev-list --count @{upstream}..HEAD)"
if [[ "$commits" != 0 ]]; then if [[ "$commits" != 0 ]]; then
echo "$OSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$OSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" echo "$OSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$OSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
fi fi
@@ -92,7 +92,7 @@ function git_commits_ahead() {
# Gets the number of commits behind remote # Gets the number of commits behind remote
function git_commits_behind() { function git_commits_behind() {
if command git rev-parse --git-dir &>/dev/null; then if command git rev-parse --git-dir &>/dev/null; then
local commits="$(git rev-list --count HEAD..@{upstream})" local commits="$(command git rev-list --count HEAD..@{upstream})"
if [[ "$commits" != 0 ]]; then if [[ "$commits" != 0 ]]; then
echo "$OSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$OSH_THEME_GIT_COMMITS_BEHIND_SUFFIX" echo "$OSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$OSH_THEME_GIT_COMMITS_BEHIND_SUFFIX"
fi fi

View File

@@ -329,8 +329,8 @@ function svn_prompt_vars {
fi fi
SCM_PREFIX=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_PREFIX=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} SCM_SUFFIX=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
SCM_BRANCH=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return SCM_BRANCH=$(command svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return
SCM_CHANGE=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) SCM_CHANGE=$(command svn info 2> /dev/null | sed -ne 's#^Revision: ##p' )
} }
# this functions returns absolute location of .hg directory if one exists # this functions returns absolute location of .hg directory if one exists

View File

@@ -327,25 +327,25 @@ function prompt_histdt {
function git_status_dirty { function git_status_dirty {
dirty=$(git status -s 2> /dev/null | tail -n 1) dirty=$(command git status -s 2> /dev/null | tail -n 1)
[[ -n $dirty ]] && echo " ●" [[ -n $dirty ]] && echo " ●"
} }
function git_stash_dirty { function git_stash_dirty {
stash=$(git stash list 2> /dev/null | tail -n 1) stash=$(command git stash list 2> /dev/null | tail -n 1)
[[ -n $stash ]] && echo " ⚑" [[ -n $stash ]] && echo " ⚑"
} }
# Git: branch/detached head, dirty status # Git: branch/detached head, dirty status
function prompt_git { function prompt_git {
local ref dirty local ref dirty
if git rev-parse --is-inside-work-tree &>/dev/null; then if command git rev-parse --is-inside-work-tree &>/dev/null; then
ZSH_THEME_GIT_PROMPT_DIRTY='±' ZSH_THEME_GIT_PROMPT_DIRTY='±'
dirty=$(git_status_dirty) dirty=$(command git_status_dirty)
stash=$(git_stash_dirty) stash=$(command git_stash_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref=$(command git symbolic-ref HEAD 2> /dev/null) ||
ref="$(git describe --exact-match --tags HEAD 2> /dev/null)" || ref="$(command git describe --exact-match --tags HEAD 2> /dev/null)" ||
ref="$(git show-ref --head -s --abbrev | head -n1 2> /dev/null)" ref="$(command git show-ref --head -s --abbrev | head -n1 2> /dev/null)"
if [[ -n $dirty ]]; then if [[ -n $dirty ]]; then
prompt_segment yellow black prompt_segment yellow black
else else

View File

@@ -14,7 +14,7 @@ GIT_SHA_PREFIX="${_omb_prompt_navy}"
GIT_SHA_SUFFIX="${_omb_prompt_reset_color}" GIT_SHA_SUFFIX="${_omb_prompt_reset_color}"
function git_short_sha() { function git_short_sha() {
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX" SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX"
} }
function _omb_theme_PROMPT_COMMAND() { function _omb_theme_PROMPT_COMMAND() {

View File

@@ -63,7 +63,7 @@ function winname {
# Displays the current prompt # Displays the current prompt
function _omb_theme_PROMPT_COMMAND() { function _omb_theme_PROMPT_COMMAND() {
PS1="\n${icon_start}$(_omb_prompt_print_python_venv)${icon_user}${_omb_prompt_bold_brown}\u${_omb_prompt_normal}${icon_host}${_omb_prompt_bold_teal}\h${_omb_prompt_normal}${icon_directory}${_omb_prompt_bold_purple}\W${_omb_prompt_normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${_omb_prompt_white}$(scm_prompt_info)${_omb_prompt_normal}\n${icon_end}" PS1="\n${icon_start}$(_omb_prompt_print_python_venv)${icon_user}${_omb_prompt_bold_brown}\u${_omb_prompt_normal}${icon_host}${_omb_prompt_bold_teal}\h${_omb_prompt_normal}${icon_directory}${_omb_prompt_bold_purple}\W${_omb_prompt_normal}\$([[ -n \$(command git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${_omb_prompt_white}$(scm_prompt_info)${_omb_prompt_normal}\n${icon_end}"
PS2="${icon_end}" PS2="${icon_end}"
} }

View File

@@ -33,7 +33,7 @@ function doubletime_scm_prompt {
if [ $CHAR = $SCM_NONE_CHAR ]; then if [ $CHAR = $SCM_NONE_CHAR ]; then
return return
elif [ $CHAR = $SCM_GIT_CHAR ]; then elif [ $CHAR = $SCM_GIT_CHAR ]; then
echo "$(git_prompt_status)" echo "$(command git_prompt_status)"
else else
echo "[$(scm_prompt_info)]" echo "[$(scm_prompt_info)]"
fi fi
@@ -55,7 +55,7 @@ _omb_util_add_prompt_command _omb_theme_PROMPT_COMMAND
function git_prompt_status { function git_prompt_status {
local git_status_output local git_status_output
git_status_output=$(git status 2> /dev/null ) git_status_output=$(command git status 2> /dev/null )
if [ -n "$(echo $git_status_output | grep 'Changes not staged')" ]; then if [ -n "$(echo $git_status_output | grep 'Changes not staged')" ]; then
git_status="${_omb_prompt_bold_brown}$(scm_prompt_info)" git_status="${_omb_prompt_bold_brown}$(scm_prompt_info)"
elif [ -n "$(echo $git_status_output | grep 'Changes to be committed')" ]; then elif [ -n "$(echo $git_status_output | grep 'Changes to be committed')" ]; then

View File

@@ -118,15 +118,15 @@ function virtual_prompt_info() {
# Parse git info # Parse git info
function git_prompt_info() { function git_prompt_info() {
if [[ -n $(git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then if [[ -n $(command git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then
local state=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} local state=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else else
local state=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} local state=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi fi
local prefix=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} local prefix=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
local suffix=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} local suffix=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
local ref=$(git symbolic-ref HEAD 2> /dev/null) || return local ref=$(command git symbolic-ref HEAD 2> /dev/null) || return
local commit_id=$(git rev-parse HEAD 2>/dev/null) || return local commit_id=$(command git rev-parse HEAD 2>/dev/null) || return
echo -e "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${commit_id:0:$MAX_GIT_HEX_LENGTH}$state$suffix" echo -e "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${commit_id:0:$MAX_GIT_HEX_LENGTH}$state$suffix"
} }
@@ -148,17 +148,17 @@ function hg_prompt_info() {
# Parse svn info # Parse svn info
function svn_prompt_info() { function svn_prompt_info() {
if [[ -n $(svn status --ignore-externals -q 2> /dev/null) ]]; then if [[ -n $(command svn status --ignore-externals -q 2> /dev/null) ]]; then
local state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} local state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else else
local state=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} local state=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi fi
local prefix=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} local prefix=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
local suffix=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} local suffix=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
local ref=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return local ref=$(command svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return
[[ -z $ref ]] && return [[ -z $ref ]] && return
local revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) local revision=$(command svn info 2> /dev/null | sed -ne 's#^Revision: ##p' )
echo -e "$prefix${REF_COLOR}$ref${DEFAULT_COLOR}:$revision$state$suffix" echo -e "$prefix${REF_COLOR}$ref${DEFAULT_COLOR}:$revision$state$suffix"
} }

View File

@@ -14,7 +14,7 @@ GIT_SHA_PREFIX=" ${_omb_prompt_olive}"
GIT_SHA_SUFFIX="${_omb_prompt_reset_color}" GIT_SHA_SUFFIX="${_omb_prompt_reset_color}"
function git_short_sha() { function git_short_sha() {
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX" SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX"
} }
function _omb_theme_PROMPT_COMMAND() { function _omb_theme_PROMPT_COMMAND() {

View File

@@ -116,31 +116,31 @@ function prompt_git {
local branchName='' local branchName=''
# Check if the current directory is in a Git repository. # Check if the current directory is in a Git repository.
if git rev-parse --is-inside-work-tree &>/dev/null; then if command git rev-parse --is-inside-work-tree &>/dev/null; then
# check if the current directory is in .git before running git checks # 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 if [[ $(command git rev-parse --is-inside-git-dir 2> /dev/null) == false ]]; then
# Ensure the index is up to date. # Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null command git update-index --really-refresh -q &>/dev/null
# Check for uncommitted changes in the index. # Check for uncommitted changes in the index.
if ! git diff --quiet --ignore-submodules --cached; then if ! command git diff --quiet --ignore-submodules --cached; then
s+='+' s+='+'
fi fi
# Check for unstaged changes. # Check for unstaged changes.
if ! git diff-files --quiet --ignore-submodules --; then if ! command git diff-files --quiet --ignore-submodules --; then
s+='!' s+='!'
fi fi
# Check for untracked files. # Check for untracked files.
if [[ $(git ls-files --others --exclude-standard) ]]; then if [[ $(command git ls-files --others --exclude-standard) ]]; then
s+='?' s+='?'
fi fi
# Check for stashed files. # Check for stashed files.
if git rev-parse --verify refs/stash &>/dev/null; then if command git rev-parse --verify refs/stash &>/dev/null; then
s+='$' s+='$'
fi fi
@@ -150,8 +150,8 @@ function prompt_git {
# If HEAD isnt a symbolic ref, get the short SHA for the latest commit # If HEAD isnt a symbolic ref, get the short SHA for the latest commit
# Otherwise, just give up. # Otherwise, just give up.
branchName=$( branchName=$(
git symbolic-ref --quiet --short HEAD 2> /dev/null || command git symbolic-ref --quiet --short HEAD 2> /dev/null ||
git rev-parse --short HEAD 2> /dev/null || command git rev-parse --short HEAD 2> /dev/null ||
echo '(unknown)') echo '(unknown)')
[[ $s ]] && s=" [$s]" [[ $s ]] && s=" [$s]"

View File

@@ -27,16 +27,16 @@ OMB_PROMPT_CONDAENV_USE_BASENAME=true
OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:=false} OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:=false}
function parse_git_dirty { function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]] && echo "*" [[ $(command git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]] && echo "*"
} }
function parse_git_branch { function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" command git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
} }
function _omb_theme_PROMPT_COMMAND() { function _omb_theme_PROMPT_COMMAND() {
local python_venv local python_venv
_omb_prompt_get_python_venv _omb_prompt_get_python_venv
PS1="$python_venv${MAGENTA}\u ${WHITE}at ${ORANGE}\h ${WHITE}in ${GREEN}\w${WHITE}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")${PURPLE}\$(parse_git_branch)${WHITE}\n\$ ${RESET}" PS1="$python_venv${MAGENTA}\u ${WHITE}at ${ORANGE}\h ${WHITE}in ${GREEN}\w${WHITE}\$([[ -n \$(command git branch 2> /dev/null) ]] && echo \" on \")${PURPLE}\$(parse_git_branch)${WHITE}\n\$ ${RESET}"
} }
_omb_util_add_prompt_command _omb_theme_PROMPT_COMMAND _omb_util_add_prompt_command _omb_theme_PROMPT_COMMAND