mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-02 02:19:06 +01:00
Rewrote the Git plugin and Sorin theme.
This commit is contained in:
parent
448cda2a57
commit
225ea89e74
8 changed files with 708 additions and 386 deletions
46
plugins/git/utility.zsh
Normal file
46
plugins/git/utility.zsh
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# 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
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue