mirror of
https://github.com/dcarrillo/prezto.git
synced 2024-12-22 17:28:01 +00:00
git: Optimize scripts for git helper functions
Optimize git internal calls and adjustment git helper functions to use more idiomatic Zsh conventions avoiding external calls.
This commit is contained in:
parent
efebe3efec
commit
a3643f124e
@ -15,7 +15,7 @@ fi
|
|||||||
local remotes remote references reference file url
|
local remotes remote references reference file url
|
||||||
|
|
||||||
remote="${1:-origin}"
|
remote="${1:-origin}"
|
||||||
remotes=($(command git config --get-regexp 'remote.*.url' | cut -d. -f2))
|
remotes=($(command git remote show))
|
||||||
|
|
||||||
if (( $remotes[(i)$remote] == $#remotes + 1 )); then
|
if (( $remotes[(i)$remote] == $#remotes + 1 )); then
|
||||||
print "$0: remote not found: $remote" >&2
|
print "$0: remote not found: $remote" >&2
|
||||||
@ -23,14 +23,14 @@ if (( $remotes[(i)$remote] == $#remotes + 1 )); then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
url=$(
|
url=$(
|
||||||
command git config --get "remote.${remote}.url" \
|
command git remote get-url "$remote" \
|
||||||
| sed -En "s/(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
|
| sed -En "s#(git@|https?://)(github.com)(:|/)(.+)/(.+)\.git#https://\2/\4/\5#p"
|
||||||
)
|
)
|
||||||
|
|
||||||
reference="${${2:-$(git-branch-current)}:-HEAD}"
|
reference="${${2:-$(git-branch-current)}:-HEAD}"
|
||||||
references=(
|
references=(
|
||||||
HEAD
|
HEAD
|
||||||
${$(command git ls-remote --heads --tags "$remote" | awk '{print $2}')##refs/(heads|tags)/}
|
${${(f)"$(command git ls-remote --heads --tags "$remote")"}##*refs/(heads|tags)/}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (( $references[(i)$reference] == $#references + 1 )); then
|
if (( $references[(i)$reference] == $#references + 1 )); then
|
||||||
@ -45,9 +45,9 @@ fi
|
|||||||
file="$3"
|
file="$3"
|
||||||
|
|
||||||
if [[ -n "$url" ]]; then
|
if [[ -n "$url" ]]; then
|
||||||
url="${url}/tree/${reference}/${file}"
|
url="$url/tree/$reference/$file"
|
||||||
|
|
||||||
if (( $+commands[$BROWSER] )); then
|
if [[ -z "$BROWSER" ]]; then
|
||||||
"$BROWSER" "$url"
|
"$BROWSER" "$url"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
@ -19,7 +19,7 @@ if [[ -z "$url" || ! "$url" =~ ^https?:\/\/.*github.com\/ ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if (( $+commands[curl] )); then
|
if (( $+commands[curl] )); then
|
||||||
curl -s -i 'https://git.io' -F "url=$url" ${(s: :)code:+ -F "code=$code"} | sed -n 's/^Location: //p'
|
print "${${(@M)${(f)"$(curl -s -i 'https://git.io' -F "url=$url" ${(z)code:+ -F "code=$code"})"}:#Location: *}#Location: }"
|
||||||
else
|
else
|
||||||
print "$0: command not found: curl" >&2
|
print "$0: command not found: curl" >&2
|
||||||
return 1
|
return 1
|
||||||
|
@ -229,8 +229,8 @@ function git-info {
|
|||||||
[[ "$commondir" =~ ^/ ]] || commondir="$(git-dir)/$commondir"
|
[[ "$commondir" =~ ^/ ]] || commondir="$(git-dir)/$commondir"
|
||||||
fi
|
fi
|
||||||
if [[ -f "$(git-dir)/refs/stash" || ( -n "$commondir" && -f "$commondir/refs/stash" ) ]]; then
|
if [[ -f "$(git-dir)/refs/stash" || ( -n "$commondir" && -f "$commondir/refs/stash" ) ]]; then
|
||||||
stashed="$(command git stash list 2> /dev/null | wc -l | awk '{print $1}')"
|
stashed=${#${(f)"$(command git stash list 2> /dev/null)"}}
|
||||||
if [[ -n "$stashed" ]]; then
|
if (( $stashed > 0 )); then
|
||||||
zformat -f stashed_formatted "$stashed_format" "S:$stashed"
|
zformat -f stashed_formatted "$stashed_format" "S:$stashed"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -15,7 +15,7 @@ fi
|
|||||||
local stashed
|
local stashed
|
||||||
|
|
||||||
if [[ -f "$(git-dir)/refs/stash" ]]; then
|
if [[ -f "$(git-dir)/refs/stash" ]]; then
|
||||||
stashed="$(command git stash list 2> /dev/null | wc -l | awk '{print $1}')"
|
stashed=${#${(f)"$(command git stash list 2> /dev/null)"}}
|
||||||
if (( $stashed > 0 )); then
|
if (( $stashed > 0 )); then
|
||||||
if read -q "?Clear $stashed stashed state(s) [y/N]? "; then
|
if read -q "?Clear $stashed stashed state(s) [y/N]? "; then
|
||||||
command git stash clear
|
command git stash clear
|
||||||
|
@ -26,7 +26,7 @@ if [[ -z "$url" ]]; then
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "${dst:h}"
|
mkdir -p "$dst:h"
|
||||||
|
|
||||||
git-submodule-remove "$src"
|
git-submodule-remove "$src"
|
||||||
command git submodule add "$url" "$dst"
|
command git submodule add "$url" "$dst"
|
||||||
|
@ -22,9 +22,9 @@ command git config --file "$(git-dir)/config" --remove-section "submodule.${1}"
|
|||||||
command git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &> /dev/null
|
command git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &> /dev/null
|
||||||
command git add .gitmodules
|
command git add .gitmodules
|
||||||
|
|
||||||
command git rm --cached -rf "${1}"
|
command git rm --cached -rf "$1"
|
||||||
rm -rf "${1}"
|
rm -rf "$1"
|
||||||
rm -rf "$(git-dir)/modules/${1}"
|
rm -rf "$(git-dir)/modules/$1"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user