-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from tiktok/feat-sparo-zsh-plugin
sparo zsh plugin
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# sparo zsh plugin | ||
|
||
This "sparo" zsh plugin provides many aliases just like [git zsh plugin](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/README.md) does. | ||
|
||
## Install & Update | ||
|
||
```shell | ||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/tiktok/sparo/main/zsh-plugin/sparo/install.sh)" "" main | ||
``` | ||
|
||
To use it, add `sparo` to the plugins array in your zshrc file: | ||
|
||
**~/.zshrc** | ||
|
||
```shell | ||
plugins=(... sparo) | ||
``` | ||
|
||
Or, manually load it by appending the following code to your zshrc file: | ||
|
||
**~/.zshrc** | ||
|
||
```shell | ||
source $ZSH/custom/plugins/sparo/sparo.plugin.zsh | ||
``` | ||
|
||
## Aliases | ||
|
||
| Alias | Command | ||
| :--------------------- | :-------------------------------------------------- | | ||
| `sa` | `sparo add` | | ||
| `sb` | `sparo branch` | | ||
| `sco` | `sparo checkout` | | ||
| `scm` | `sparo checkout $(git_main_branch)` | | ||
| `scl` | `sparo clone` | | ||
| `sc` | `sparo commit` | | ||
| `scmsg` | `sparo commit --message` | | ||
| `sc!` | `sparo commit --amend` | | ||
| `sd` | `sparo diff` | | ||
| `sf` | `sparo fetch` | | ||
| `sfo` | `sparo fetch origin` | | ||
| `sl` | `sparo pull` | | ||
| `sp` | `sparo push` | | ||
| `spf!` | `sparo push --force` | | ||
| `spf` | `sparo push --force-with-lease --force-if-includes` | | ||
| `srb` | `sparo rebase` | | ||
| `srba` | `sparo rebase --abort` | | ||
| `srbc` | `sparo rebase --continue` | | ||
| `srbi` | `sparo rebase --interactive` | | ||
| `sst` | `sparo status` | | ||
|
||
|
||
## Functions | ||
|
||
| Command | Description | | ||
| :--------------------- | :----------------------------------------------------------------------------- | | ||
| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
BRANCH=${1:-main} | ||
|
||
# check ZSH environment | ||
if [ -z "$ZSH" ]; then | ||
echo "ZSH environment variable does not defined." | ||
exit 1 | ||
fi | ||
|
||
# target folder | ||
plugin_dir="$ZSH/custom/plugins/sparo" | ||
|
||
mkdir -p "$plugin_dir" | ||
|
||
# download sparo.plugin.zsh to plugin dir | ||
echo "Downloading sparo.plugin.zsh to $plugin_dir from $BRANCH branch..." | ||
curl -L "https://raw.githubusercontent.com/tiktok/sparo/$BRANCH/zsh-plugin/sparo/sparo.plugin.zsh" -o "$plugin_dir/sparo.plugin.zsh" | ||
|
||
cat <<EOF | ||
Sparo plugin installed! | ||
It's necessary to do the following changes in your .zshrc file: | ||
1. Add "sparo" in the plugins list if you are using Oh-My-Zsh | ||
plugins=(... sparo) | ||
OR, 2. Manually load this file by appending the following code to your .zshrc file. | ||
source $ZSH/custom/plugins/sparo/sparo.plugin.zsh | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
if typeset -f git_main_branch > /dev/null; then | ||
# Reuse git_main_branch if it's defined in git plugin | ||
else | ||
# https://github.com/ohmyzsh/ohmyzsh/blob/1d09c6bb0a950756a65b02457842933e3aa493eb/plugins/git/git.plugin.zsh#L34 | ||
# Check if main exists and use instead of master | ||
function git_main_branch() { | ||
command git rev-parse --git-dir &>/dev/null || return | ||
local ref | ||
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}; do | ||
if command git show-ref -q --verify $ref; then | ||
echo ${ref:t} | ||
return 0 | ||
fi | ||
done | ||
|
||
# If no main branch was found, fall back to master but return error | ||
echo master | ||
return 1 | ||
} | ||
fi | ||
|
||
# Aliases | ||
# (order should follow README) | ||
|
||
alias sa='sparo add' | ||
alias sb='sparo branch' | ||
alias sco='sparo checkout' | ||
alias scm='sparo checkout $(git_main_branch)' | ||
alias scl='sparo clone' | ||
alias sc='sparo commit' | ||
alias scmsg='sparo commit --message' | ||
alias sc!='sparo commit --amend' | ||
alias sd='sparo diff' | ||
alias sf='sparo fetch' | ||
alias sfo='sparo fetch origin' | ||
alias sl='sparo pull' | ||
alias sp='sparo push' | ||
alias spf!='sparo push --force' | ||
alias spf='sparo push --force-with-lease --force-if-includes' | ||
alias srb='sparo rebase' | ||
alias srba='sparo rebase --abort' | ||
alias srbc='sparo rebase --continue' | ||
alias srbi='sparo rebase --interactive' | ||
alias sst='sparo status' |