diff --git a/zsh-plugin/sparo/README.md b/zsh-plugin/sparo/README.md new file mode 100644 index 0000000..4cf38c8 --- /dev/null +++ b/zsh-plugin/sparo/README.md @@ -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. | \ No newline at end of file diff --git a/zsh-plugin/sparo/install.sh b/zsh-plugin/sparo/install.sh new file mode 100644 index 0000000..cae3daa --- /dev/null +++ b/zsh-plugin/sparo/install.sh @@ -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 < /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' \ No newline at end of file