Skip to content

Commit

Permalink
Merge pull request ohmybash#484 from akinomyoga/prompt-git
Browse files Browse the repository at this point in the history
lib/git: Fix problems caused by uses of Zsh features
  • Loading branch information
akinomyoga authored Oct 14, 2023
2 parents 1e2b292 + 1dfbd39 commit 07d9382
Show file tree
Hide file tree
Showing 18 changed files with 227 additions and 212 deletions.
10 changes: 5 additions & 5 deletions completions/gh.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ EOF
format=${format//\p/\2}
format=${format//\o/\3}
fi
command git config --get-regexp 'remote\.[^.]*\.url' |
_omb_prompt_git config --get-regexp 'remote\.[^.]*\.url' |
grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#'
}
Expand All @@ -332,12 +332,12 @@ EOF
function __hub_heads {
local i remote repo branch dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/heads/"
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read branch; do
echo "${repo}:${branch#${remote}/}"
done
Expand All @@ -351,11 +351,11 @@ EOF
function __hub_revlist {
local i remote=${1:-origin} dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read i; do
echo "${i#${remote}/}"
done
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/tags/"
fi
}
Expand Down
10 changes: 5 additions & 5 deletions completions/git_flow.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ __git_flow_feature ()

__git_flow_list_features ()
{
git flow feature list 2> /dev/null | tr -d ' |*'
_omb_prompt_git flow feature list 2> /dev/null | tr -d ' |*'
}

__git_flow_list_remote_features ()
{
git branch -r 2> /dev/null | grep "origin/$(__git_flow_feature_prefix)" | awk '{ sub(/^origin\/$(__git_flow_feature_prefix)/, "", $1); print }'
_omb_prompt_git branch -r 2> /dev/null | grep "origin/$(__git_flow_feature_prefix)" | awk '{ sub(/^origin\/$(__git_flow_feature_prefix)/, "", $1); print }'
}

__git_flow_feature_prefix ()
{
git config gitflow.prefix.feature 2> /dev/null || echo "feature/"
_omb_prompt_git config gitflow.prefix.feature 2> /dev/null || echo "feature/"
}

__git_flow_release ()
Expand All @@ -143,7 +143,7 @@ __git_flow_release ()

__git_flow_list_releases ()
{
git flow release list 2> /dev/null
_omb_prompt_git flow release list 2> /dev/null
}

__git_flow_hotfix ()
Expand All @@ -168,7 +168,7 @@ __git_flow_hotfix ()

__git_flow_list_hotfixes ()
{
git flow hotfix list 2> /dev/null
_omb_prompt_git flow hotfix list 2> /dev/null
}

# temporarily wrap __git_find_on_cmdline() for backwards compatibility
Expand Down
16 changes: 8 additions & 8 deletions completions/git_flow_avh.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ __git_flow_prefix ()
{
case "$1" in
feature|release|hotfix|support)
git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/"
_omb_prompt_git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/"
return
;;
esac
Expand All @@ -464,23 +464,23 @@ __git_flow_list_local_branches ()
{
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix | \
_omb_prompt_git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref#$prefix}"
echo "$ref"
done | sort
else
git for-each-ref --format="ref=%(refname:short)" refs/heads/ | sort
_omb_prompt_git for-each-ref --format="ref=%(refname:short)" refs/heads/ | sort

fi
}

__git_flow_list_remote_branches ()
{
local prefix="$(__git_flow_prefix $1)"
local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")"
git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix | \
local origin="$(_omb_prompt_git config gitflow.origin 2> /dev/null || echo "origin")"
_omb_prompt_git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
Expand All @@ -490,17 +490,17 @@ __git_flow_list_remote_branches ()

__git_flow_list_branches ()
{
local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")"
local origin="$(_omb_prompt_git config gitflow.origin 2> /dev/null || echo "origin")"
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix | \
_omb_prompt_git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
echo "$ref"
done | sort
else
git for-each-ref --format="%(refname:short)" refs/heads/ refs/remotes/$origin | sort
_omb_prompt_git for-each-ref --format="%(refname:short)" refs/heads/ refs/remotes/$origin | sort
fi
}

Expand Down
10 changes: 5 additions & 5 deletions completions/hub.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ EOF
format=${format//\p/\2}
format=${format//\o/\3}
fi
command git config --get-regexp 'remote\.[^.]*\.url' |
_omb_prompt_git config --get-regexp 'remote\.[^.]*\.url' |
grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#'
}
Expand All @@ -334,12 +334,12 @@ EOF
function __hub_heads {
local i remote repo branch dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/heads/"
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read branch; do
echo "${repo}:${branch#${remote}/}"
done
Expand All @@ -353,11 +353,11 @@ EOF
function __hub_revlist {
local i remote=${1:-origin} dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read i; do
echo "${i#${remote}/}"
done
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
_omb_prompt_git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/tags/"
fi
}
Expand Down
Loading

0 comments on commit 07d9382

Please sign in to comment.