diff --git a/completions/_git-elegant b/completions/_git-elegant new file mode 100755 index 0000000..de87321 --- /dev/null +++ b/completions/_git-elegant @@ -0,0 +1,95 @@ +#compdef git-elegant git +#description enables Elegant Git completion +# +# It's recommended to use this completion with the following Git completion file: +# https://raw.githubusercontent.com/zsh-users/zsh/master/Completion/Unix/Command/_git + +_git-elegant (){ + # update this function if either new commands or options are added + local curcontext='$curcontext' state line + typeset -A opt_args + _arguments -C ':command:->command' '*::option:->option' + local all_commands=( + 'accept-work:applies a branch on top of \`master\` branch' + 'acquire-git:configures a Git installation' + 'acquire-repository:configures current repository' + 'amend-work:amends some changes to the most recent commit' + 'clone-repository:clones a repository and configures it' + 'deliver-work:publishes current branch to a remote repository' + 'init-repository:initializes a new repository and configures it' + 'obtain-work:checkouts a remote branch matching by a name' + 'polish-work:reapplies branch commits interactively' + 'prune-repository:removes useless local branches' + 'release-work:releases available work as a new annotated tag' + 'save-work:commits current modifications' + 'show-commands:prints available Elegant Git commands' + 'show-release-notes:prints a release log between two references' + 'show-work:shows a state of current work in progress' + 'start-work:creates a new branch' + ) + + case ${state} in + command) + local options=( + '--help:displays help' + '--version:displays program version' + '--no-workflows:disables available workflows' + ) + _describe 'first' all_commands -- options + ;; + option) + if [[ ${line[1]} == --no-workflows ]]; then + __ge_complete_commands_workflow + else + __ge_complete_commands + fi + ;; + esac +} + +__ge_complete_commands_workflow() { + _arguments ':command:->command' '*::options:->options' + case ${state} in + command) _describe 'only commands' all_commands ;; + options) __ge_complete_commands ;; + esac +} + +__ge_complete_commands () { + # update this function if a new command requires a competion + # default completion is empty + case ${line[1]} in + accept-work|obtain-work) __ge_remotes ;; + show-release-notes) __ge_show_release_notes ;; + *) _arguments '--help' '--no-workflows' ;; + esac +} + +__ge_remotes() { + # completes first position with remote branches + local remotes=( + $(git for-each-ref --format='%(refname:strip=2)' refs/remotes 2>/dev/null || echo ) + ) + _arguments '--help' \ + '--no-workflows' \ + '1:branch:(${remotes[@]})' +} + +__ge_show_release_notes_modes(){ + local modes=( + 'simple:prints the messages as a plain text (default one)' + 'smart:prints the messages in a form of adopted for a git hosting' + ) + _describe 'modes' modes +} + +__ge_show_release_notes() { + local all=( + $(git for-each-ref --format '%(refname:short)' refs 2>/dev/null || echo ) + ) + _arguments '--help' \ + '--no-workflows' \ + '1:mode:__ge_show_release_notes_modes' \ + '2:from:(${all[@]})' \ + '3:to:(${all[@]})' +} diff --git a/docs/getting-started.md b/docs/getting-started.md index afc6021..ddcdf58 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1,8 +1,31 @@ -# Several important words -You can install Elegant Git by either executing `bash` script or using `homebrew`. After the -installation, please configure your environment by running -[`git elegant acquire-git`](commands.md#acquire-git) and follow the instructions. To find out more, -please read [the configuration approach](configuration.md). +# Installation via Bash script +Run the follwing command and follow the instructions +```bash +curl https://raw.githubusercontent.com/bees-hive/elegant-git/master/install.bash | $(which bash) +``` + +Elegant Git will be installed in `~/.elegant-git` directory. That's why if you want to remove +the installation, just remove the directory. + +# Installation via Homebrew +On macOS, you can install [Homebrew](https://brew.sh/) if you haven't already, then run +``` +brew install git bees-hive/hive/elegant-git +``` +The command will + +- install Git as it has to be installed with Homebrew for enabling Bash/Zsh completion +- install Elegant Git +- configure Bash completion for both Git and Elegant Git + +P.S. If you need Zsh completion for all Git commands, consider using + +(see for the details). + +# Post-installation actions +Configure your environment by running [`git elegant acquire-git`](commands.md#acquire-git) +and follow the instructions. To find out more, please read +[the configuration approach](configuration.md). You can access Elegant Git in CLI using any of ```bash @@ -10,25 +33,9 @@ git git elegant git-elegant ``` -where `` is one of the available commands which are described on [commands](commands.md) -page or are printed in a terminal by running `git elegant`. +where `` is one of the commands described on the [commands](commands.md) page or +printed in a terminal after running `git elegant`. Also, please use [`git elegant clone-repository`](commands.md#clone-repository) or [`git elegant init-repository`](commands.md#init-repository) instead of regular `clone` or `init` Git's commands in order to get Elegant Git working by default. - -# `bash` installation -Run `curl https://raw.githubusercontent.com/bees-hive/elegant-git/master/install.bash | $(which bash)` -and follow the provided instructions to install the tool. `${HOME}/.elegant-git` directory will host -all required files. That's why if you want to remove installation, you need to remove this directory -only (`rm -r ${HOME}/.elegant-git`). - -Elegant Git's BASH completion does not work without regular Git BASH completion. If you don't have -it, please follow -in addition to Elegant Git's configuration. - -# Homebrew installation -On macOS, you can install [Homebrew](https://brew.sh/) if you haven't already, then run -`brew install git` (we must install Git with Homebrew in order to have a working BASH completion) -and `brew install bees-hive/hive/elegant-git` (please visit - if you need details). diff --git a/install.bash b/install.bash index 92fa29c..9b7bdb5 100755 --- a/install.bash +++ b/install.bash @@ -24,8 +24,9 @@ copy(){ update-path() { local INSTALL_PATH=${1} cat < ~/.zsh/completion/_git + + +P.S. +---- +Please restart terminal session in order to activate completion. TEXT } @@ -78,9 +119,7 @@ main() { else update-path ${INSTALL_PATH} fi - if ! complete -p git-elegant 1>/dev/null 2>&1; then - update-completion ${INSTALL_PATH} - fi + update-completion ${INSTALL_PATH} } main $@