mirror of
https://github.com/dcarrillo/prezto.git
synced 2025-06-14 20:41:44 +00:00
Moved hub into the git plugin.
This commit is contained in:
@ -1,13 +1,20 @@
|
||||
# Get the latest Git completion.
|
||||
completion_file="${0:h}/_git"
|
||||
completion_file="${0:h}/completions/_git"
|
||||
completion_file_url='http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=blob_plain;f=Completion/Unix/Command/_git;hb=HEAD'
|
||||
if [[ ! -e "$completion_file" ]] && (( $+commands[git] )); then
|
||||
if (( $+commands[curl] )); then
|
||||
curl -L "$completion_file_url" -o "$completion_file" &> /dev/null &!
|
||||
# Remove empty completions directory.
|
||||
if [[ -d "${completion_file:h}"(/^F) ]]; then
|
||||
rmdir "${completion_file:h}" 2> /dev/null
|
||||
fi
|
||||
|
||||
if (( $+commmands[wget] )); then
|
||||
wget -C "$completion_file_url" -O "$completion_file" &> /dev/null &!
|
||||
if mkdir -p "${completion_file:h}" > /dev/null; then
|
||||
if (( $+commands[curl] )); then
|
||||
curl -L "$completion_file_url" -o "$completion_file" &> /dev/null &!
|
||||
fi
|
||||
|
||||
if (( $+commmands[wget] )); then
|
||||
wget -C "$completion_file_url" -O "$completion_file" &> /dev/null &!
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
unset completion_file
|
||||
|
9
plugins/git/functions/git-branch
Normal file
9
plugins/git/functions/git-branch
Normal file
@ -0,0 +1,9 @@
|
||||
# Gets the current branch.
|
||||
local ref="$(git symbolic-ref HEAD 2> /dev/null)"
|
||||
if [[ -n "$ref" ]]; then
|
||||
print "${ref#refs/heads/}"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
22
plugins/git/functions/git-hub
Normal file
22
plugins/git/functions/git-hub
Normal file
@ -0,0 +1,22 @@
|
||||
# Open the GitHub repository in the browser.
|
||||
local url=$(
|
||||
git config -l \
|
||||
| grep "remote.origin.url" \
|
||||
| sed -En "s/remote.origin.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
|
||||
)
|
||||
|
||||
if [[ -n "$url" ]]; then
|
||||
url="${url}/tree/${$(git-branch):-master}"
|
||||
|
||||
if (( $+commands[$BROWSER] )); then
|
||||
"$BROWSER" "$url"
|
||||
return 0
|
||||
else
|
||||
print "fatal: Browser not set or set to a non-existent browser." >&2
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print "fatal: Not a Git repository or origin remote not set." >&2
|
||||
return 1
|
||||
fi
|
||||
|
@ -1,22 +1,3 @@
|
||||
# The default styles.
|
||||
zstyle ':git-info:' action 'action:%s' # %s - Special action name (am, merge, rebase).
|
||||
zstyle ':git-info:' added 'added:%a' # %a - Indicator to notify of added files.
|
||||
zstyle ':git-info:' ahead 'ahead:%A' # %A - Indicator to notify of ahead branch.
|
||||
zstyle ':git-info:' behind 'behind:%B' # %B - Indicator to notify of behind branch.
|
||||
zstyle ':git-info:' branch '%b' # %b - Branch name.
|
||||
zstyle ':git-info:' clean 'clean' # %C - Indicator to notify of clean branch.
|
||||
zstyle ':git-info:' commit 'commit:%c' # %c - SHA-1 hash.
|
||||
zstyle ':git-info:' deleted 'deleted:%d' # %d - Indicator to notify of deleted files.
|
||||
zstyle ':git-info:' dirty 'dirty' # %D - Indicator to notify of dirty branch.
|
||||
zstyle ':git-info:' modified 'modified:%m' # %m - Indicator to notify of modified files.
|
||||
zstyle ':git-info:' remote '%R' # %R - Remote name.
|
||||
zstyle ':git-info:' renamed 'renamed:%r' # %r - Indicator to notify of renamed files.
|
||||
zstyle ':git-info:' stashed 'stashed:%S' # %S - Indicator to notify of stashed files.
|
||||
zstyle ':git-info:' unmerged 'unmerged:%U' # %U - Indicator to notify of unmerged files.
|
||||
zstyle ':git-info:' untracked 'untracked:%u' # %u - Indicator to notify of untracked files.
|
||||
zstyle ':git-info:' prompt ' git:(%b %D%C)' # Left prompt.
|
||||
zstyle ':git-info:' rprompt '' # Right prompt.
|
||||
|
||||
# Gets the Git special action (am, merge, rebase, etc.).
|
||||
# Borrowed from vcs_info and edited.
|
||||
function _git-action() {
|
||||
@ -36,7 +17,7 @@ function _git-action() {
|
||||
else
|
||||
action='am/rebase'
|
||||
fi
|
||||
echo "$action"
|
||||
print "$action"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
@ -45,7 +26,7 @@ function _git-action() {
|
||||
"${git_dir}/rebase-merge/interactive" \
|
||||
"${git_dir}/.dotest-merge/interactive"; do
|
||||
if [[ -f "$action_dir" ]]; then
|
||||
echo 'rebase-i'
|
||||
print 'rebase-i'
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
@ -54,23 +35,23 @@ function _git-action() {
|
||||
"${git_dir}/rebase-merge" \
|
||||
"${git_dir}/.dotest-merge"; do
|
||||
if [[ -d "$action_dir" ]]; then
|
||||
echo 'rebase-m'
|
||||
print 'rebase-m'
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -f "${git_dir}/MERGE_HEAD" ]]; then
|
||||
echo 'merge'
|
||||
print 'merge'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then
|
||||
echo 'cherry-pick'
|
||||
print 'cherry-pick'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "${git_dir}/BISECT_LOG" ]]; then
|
||||
echo 'bisect'
|
||||
print 'bisect'
|
||||
return 0
|
||||
fi
|
||||
|
||||
@ -175,7 +156,7 @@ function git-info() {
|
||||
elif [[ "$1" == [Oo][Ff][Ff] ]]; then
|
||||
git config --bool prompt.showinfo false
|
||||
else
|
||||
echo "Usage: $0 [ on | off ]"
|
||||
print "Usage: $0 [ on | off ]"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
@ -355,3 +336,5 @@ function git-info() {
|
||||
return 0
|
||||
}
|
||||
|
||||
git-info "$@"
|
||||
|
9
plugins/git/functions/git-root
Normal file
9
plugins/git/functions/git-root
Normal file
@ -0,0 +1,9 @@
|
||||
# Gets the repository root.
|
||||
local root="$(git rev-parse --show-toplevel 2> /dev/null)"
|
||||
if [[ -n "$root" ]]; then
|
||||
print "$root"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
8
plugins/git/hub.zsh
Normal file
8
plugins/git/hub.zsh
Normal file
@ -0,0 +1,8 @@
|
||||
# Hub by defunkt
|
||||
# https://github.com/defunkt/hub
|
||||
if (( $+commands[hub] )); then
|
||||
function git() {
|
||||
hub "$@"
|
||||
}
|
||||
fi
|
||||
|
@ -6,8 +6,8 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Source plugin files.
|
||||
source "${0:h}/utility.zsh"
|
||||
source "${0:h}/alias.zsh"
|
||||
source "${0:h}/info.zsh"
|
||||
source "${0:h}/hub.zsh"
|
||||
source "${0:h}/style.zsh"
|
||||
source "${0:h}/completion.zsh"
|
||||
|
||||
|
18
plugins/git/style.zsh
Normal file
18
plugins/git/style.zsh
Normal file
@ -0,0 +1,18 @@
|
||||
# The default styles.
|
||||
zstyle ':git-info:' action 'action:%s' # %s - Special action name (am, merge, rebase).
|
||||
zstyle ':git-info:' added 'added:%a' # %a - Indicator to notify of added files.
|
||||
zstyle ':git-info:' ahead 'ahead:%A' # %A - Indicator to notify of ahead branch.
|
||||
zstyle ':git-info:' behind 'behind:%B' # %B - Indicator to notify of behind branch.
|
||||
zstyle ':git-info:' branch '%b' # %b - Branch name.
|
||||
zstyle ':git-info:' clean 'clean' # %C - Indicator to notify of clean branch.
|
||||
zstyle ':git-info:' commit 'commit:%c' # %c - SHA-1 hash.
|
||||
zstyle ':git-info:' deleted 'deleted:%d' # %d - Indicator to notify of deleted files.
|
||||
zstyle ':git-info:' dirty 'dirty' # %D - Indicator to notify of dirty branch.
|
||||
zstyle ':git-info:' modified 'modified:%m' # %m - Indicator to notify of modified files.
|
||||
zstyle ':git-info:' remote '%R' # %R - Remote name.
|
||||
zstyle ':git-info:' renamed 'renamed:%r' # %r - Indicator to notify of renamed files.
|
||||
zstyle ':git-info:' stashed 'stashed:%S' # %S - Indicator to notify of stashed files.
|
||||
zstyle ':git-info:' unmerged 'unmerged:%U' # %U - Indicator to notify of unmerged files.
|
||||
zstyle ':git-info:' untracked 'untracked:%u' # %u - Indicator to notify of untracked files.
|
||||
zstyle ':git-info:' prompt ' git:(%b %D%C)' # Left prompt.
|
||||
zstyle ':git-info:' rprompt '' # Right prompt.
|
@ -1,46 +0,0 @@
|
||||
# Gets the current branch.
|
||||
function git-branch() {
|
||||
local ref="$(git symbolic-ref HEAD 2> /dev/null)"
|
||||
if [[ -n "$ref" ]]; then
|
||||
echo "${ref#refs/heads/}"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Gets the repository root.
|
||||
function git-root() {
|
||||
local root="$(git rev-parse --show-toplevel 2> /dev/null)"
|
||||
if [[ -n "$root" ]]; then
|
||||
echo "$root"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Open the GitHub repository in the browser.
|
||||
function git-hub() {
|
||||
local url=$(
|
||||
git config -l \
|
||||
| grep "remote.origin.url" \
|
||||
| sed -En "s/remote.origin.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
|
||||
)
|
||||
|
||||
if [[ -n "$url" ]]; then
|
||||
url="${url}/tree/${$(git-branch):-master}"
|
||||
|
||||
if (( $+commands[$BROWSER] )); then
|
||||
"$BROWSER" "$url"
|
||||
return 0
|
||||
else
|
||||
echo "fatal: Browser not set or set to a non-existent browser." >&2
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "fatal: Not a Git repository or origin remote not set." >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
Reference in New Issue
Block a user