mirror of
https://github.com/tiktok/sparo.git
synced 2024-11-27 09:36:04 -05:00
feat: zsh plugin
This commit is contained in:
parent
2c8c5e9a0c
commit
693b51b2b0
3 changed files with 128 additions and 0 deletions
51
zsh-plugin/sparo/README.md
Normal file
51
zsh-plugin/sparo/README.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
# 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:
|
||||
|
||||
```shell
|
||||
plugins=(... sparo)
|
||||
```
|
||||
|
||||
Or, manually load it by appending the following code to your zshrc file:
|
||||
|
||||
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. |
|
33
zsh-plugin/sparo/install.sh
Normal file
33
zsh-plugin/sparo/install.sh
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
BRANCH=${1:-main}
|
||||
|
||||
# check existence of $ZSH/custom
|
||||
if [ ! -d "$ZSH/custom/" ]; then
|
||||
echo "$ZSH/custom/ does not exist."
|
||||
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
|
44
zsh-plugin/sparo/sparo.plugin.zsh
Normal file
44
zsh-plugin/sparo/sparo.plugin.zsh
Normal file
|
@ -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'
|
Loading…
Reference in a new issue