diff --git a/README.md b/README.md index 446ddac..0e0986a 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ For linux users `FORGIT_COPY_CMD` should be set to make copy work. Example: `FOR #### aliases +##### shell + You can change the default aliases by defining these variables below. (To disable all aliases, Set the `FORGIT_NO_ALIASES` flag.) @@ -142,6 +144,37 @@ forgit_rebase=grb forgit_fixup=gfu ``` +#### git + +You can use git aliases by making `git-forgit` available in `$PATH`: + +```sh +# after `forgit` was loaded +export PATH="$PATH:$FORGIT_INSTALL_DIR/bin" +``` + +*Some plugin managers can help do this.* + +Then any forgit command will be a subcommand of git: + +``` +$ git forgit log +$ git forgit add +$ git forgit diff +``` + +Optionally you can add [aliases in git](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases): + +```sh +git config --global alias.cf 'forgit checkout_file' +``` + +And use the alias in git: + +```sh +git cf +``` + #### pagers Forgit will use the default configured pager from git (`core.pager`, diff --git a/bin/git-forgit b/bin/git-forgit new file mode 100755 index 0000000..3297b86 --- /dev/null +++ b/bin/git-forgit @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# This file is a bridge between forgit and git itself. This makes forgit a +# subcommand of git, and forwards all arguments on to forgit. So, all of these +# commands will work as expected: +# +# `git forgit log` +# `git forgit checkout_file` +# `git forgit checkout_file README.md` +# +# This gives users the choice to set aliases inside of their git config instead +# of their shell config if they prefer. + +set -e + +source "$FORGIT_INSTALL_DIR/forgit.plugin.zsh" + +cmd="$1" +shift +forgit::${cmd/_/::} "$@" diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 1129619..4b27317 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -12,6 +12,8 @@ function forgit::inside_work_tree git rev-parse --is-inside-work-tree >/dev/null; end +set -x FORGIT_INSTALL_DIR (cd (dirname (dirname (status -f))); and pwd) + set -g forgit_pager "$FORGIT_PAGER" set -g forgit_show_pager "$FORGIT_SHOW_PAGER" set -g forgit_diff_pager "$FORGIT_DIFF_PAGER" diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 2dce324..5ea2e22 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -341,3 +341,15 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then alias "${forgit_rebase:-grb}"='forgit::rebase' alias "${forgit_fixup:-gfu}"='forgit::fixup' fi + +# set installation path (for use by `bin/git-forgit`) +if [[ -n "$ZSH_VERSION" ]]; then + FORGIT_INSTALL_DIR="$( dirname -- "$0")" +elif [[ -n "$BASH_VERSION" ]]; then + FORGIT_INSTALL_DIR="$(dirname -- "${BASH_SOURCE[0]}")" +else + forgit::warn "Only zsh and bash are fully supported" +fi +if [[ -n "$FORGIT_INSTALL_DIR" ]]; then + export FORGIT_INSTALL_DIR +fi