From 896aaa44a49e504a91d664019d2a90861e1328f8 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 17 Oct 2021 22:27:51 -0700 Subject: [PATCH 01/10] add handling for standalone version of forgit (for use in git commands) --- bin/git-forgit | 8 ++++++++ forgit.plugin.zsh | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 bin/git-forgit diff --git a/bin/git-forgit b/bin/git-forgit new file mode 100755 index 0000000..7e7a3d3 --- /dev/null +++ b/bin/git-forgit @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +source "$FORGIT_INSTALL_DIR/forgit.plugin.zsh" + +cmd="$1" +shift +forgit::${cmd/-/::} "$@" diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index f63b90d..de55079 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -333,3 +333,18 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then alias "${forgit_rebase:-grb}"='forgit::rebase' alias "${forgit_fixup:-gfu}"='forgit::fixup' fi + +if [[ -n "$FORGIT_STANDALONE" ]]; then + 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 "Shell not supported for FORGIT_STANDLONE (only zsh and bash)" + fi + + if [[ -n "$FORGIT_INSTALL_DIR" ]]; then + export FORGIT_INSTALL_DIR + fi +fi + From 800b35c687e2461f5e42d9ec1d4bf55957b2e820 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 17 Oct 2021 23:16:13 -0700 Subject: [PATCH 02/10] update alias documentation --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 446ddac..437f2e7 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,14 @@ forgit_rebase=grb forgit_fixup=gfu ``` +You can also use git aliases. To do this: +1. Set the `FORGIT_STANDALONE` flag (example: `export FORGIT_STANDALONE=1`) +2. Add the bin directory in `FORGIT_INSTALL_DIR` to your `PATH` (example: +`PATH="$PATH:FORGIT_INSTALL_DIR/bin`) +3. Add (aliases in git)[https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases] (example: +`git config --global alias.cf 'forgit checkout_file'`) +4. Use the alias in git instead of the shell (example: `git cf`) + #### pagers Forgit will use the default configured pager from git (`core.pager`, From d6fa65ec92e24dac94ece63b631ff761794fa5dc Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 17 Oct 2021 23:18:23 -0700 Subject: [PATCH 03/10] clean up documentation format for readme alias section --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 437f2e7..af21f01 100644 --- a/README.md +++ b/README.md @@ -142,13 +142,15 @@ forgit_rebase=grb forgit_fixup=gfu ``` -You can also use git aliases. To do this: -1. Set the `FORGIT_STANDALONE` flag (example: `export FORGIT_STANDALONE=1`) -2. Add the bin directory in `FORGIT_INSTALL_DIR` to your `PATH` (example: -`PATH="$PATH:FORGIT_INSTALL_DIR/bin`) -3. Add (aliases in git)[https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases] (example: -`git config --global alias.cf 'forgit checkout_file'`) -4. Use the alias in git instead of the shell (example: `git cf`) +Or if you prefer, you can also use git aliases (instead of shell aliases). To do this: +1. Set the `FORGIT_STANDALONE` flag + - example: `export FORGIT_STANDALONE=1` +2. Add the bin directory in `FORGIT_INSTALL_DIR` to your `PATH` + - example: `PATH="$PATH:FORGIT_INSTALL_DIR/bin` +3. Add (aliases in git)[https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases] + - example: `git config --global alias.cf 'forgit checkout_file'` +4. Use the alias in git instead of the shell + - example: `git cf` #### pagers From 8bcd87af380842658a138def0c4e1d88875888c6 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 17 Oct 2021 23:33:00 -0700 Subject: [PATCH 04/10] change dash to underscore for bin/git-forgit Using an underscore instead of a dash simplifies the workflow and documentation by making the commands and environment variables that forgit uses the same (i.e. `git forgit checkout_file` is the same command referred to by `forgit_checkout_file`) --- bin/git-forgit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-forgit b/bin/git-forgit index 7e7a3d3..038d0c8 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -5,4 +5,4 @@ source "$FORGIT_INSTALL_DIR/forgit.plugin.zsh" cmd="$1" shift -forgit::${cmd/-/::} "$@" +forgit::${cmd/_/::} "$@" From df36068105b788e8c7375fe4174cb841c92a6185 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 17 Oct 2021 23:36:16 -0700 Subject: [PATCH 05/10] add some comments for clarification --- bin/git-forgit | 11 +++++++++++ forgit.plugin.zsh | 1 + 2 files changed, 12 insertions(+) diff --git a/bin/git-forgit b/bin/git-forgit index 038d0c8..3297b86 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -1,4 +1,15 @@ #!/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" diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index de55079..76f794b 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -334,6 +334,7 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then alias "${forgit_fixup:-gfu}"='forgit::fixup' fi +# set installation path (for use by `bin/git-forgit`) if [[ -n "$FORGIT_STANDALONE" ]]; then if [[ -n "$ZSH_VERSION" ]]; then FORGIT_INSTALL_DIR="$( dirname -- "$0")" From 96d0924aef65363b0374fa8ac99b98490813c7cc Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 17 Oct 2021 23:40:42 -0700 Subject: [PATCH 06/10] fix typos in docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af21f01..d97dd47 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Or if you prefer, you can also use git aliases (instead of shell aliases). To do 1. Set the `FORGIT_STANDALONE` flag - example: `export FORGIT_STANDALONE=1` 2. Add the bin directory in `FORGIT_INSTALL_DIR` to your `PATH` - - example: `PATH="$PATH:FORGIT_INSTALL_DIR/bin` + - example: `PATH="$PATH:FORGIT_INSTALL_DIR/bin"` 3. Add (aliases in git)[https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases] - example: `git config --global alias.cf 'forgit checkout_file'` 4. Use the alias in git instead of the shell From 5403f42acfb6cc71bbf9d36776860f57845fc121 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 17 Oct 2021 23:42:26 -0700 Subject: [PATCH 07/10] add to readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d97dd47..105410e 100644 --- a/README.md +++ b/README.md @@ -146,10 +146,12 @@ Or if you prefer, you can also use git aliases (instead of shell aliases). To do 1. Set the `FORGIT_STANDALONE` flag - example: `export FORGIT_STANDALONE=1` 2. Add the bin directory in `FORGIT_INSTALL_DIR` to your `PATH` - - example: `PATH="$PATH:FORGIT_INSTALL_DIR/bin"` -3. Add (aliases in git)[https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases] + - example: `PATH="$PATH:$FORGIT_INSTALL_DIR/bin"` +3. You can now run any forgit command as a subcommand of git! + - example: `git forgit log` +4. Add (aliases in git)[https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases] - example: `git config --global alias.cf 'forgit checkout_file'` -4. Use the alias in git instead of the shell +5. Use the alias in git instead of the shell - example: `git cf` #### pagers From 950a7352dbf4e5c8041f7c165e32db72456fe3ea Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Wed, 20 Oct 2021 10:17:03 +0800 Subject: [PATCH 08/10] support fish shell --- conf.d/forgit.plugin.fish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index ab29537..0051a56 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" From b86dc4b0c88c9d84f4d61b6912ae15f2a54e3426 Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Fri, 22 Oct 2021 10:38:17 +0800 Subject: [PATCH 09/10] refactor: reduce git alias config steps --- forgit.plugin.zsh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 76f794b..d441fdb 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -335,17 +335,13 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then fi # set installation path (for use by `bin/git-forgit`) -if [[ -n "$FORGIT_STANDALONE" ]]; then - 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 "Shell not supported for FORGIT_STANDLONE (only zsh and bash)" - fi - - if [[ -n "$FORGIT_INSTALL_DIR" ]]; then - export FORGIT_INSTALL_DIR - fi +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 - From cef385bd449cb4506bbf27f481130d7ddd3c8780 Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Fri, 22 Oct 2021 10:39:35 +0800 Subject: [PATCH 10/10] docs: update git aliases description --- README.md | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 105410e..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,17 +144,36 @@ forgit_rebase=grb forgit_fixup=gfu ``` -Or if you prefer, you can also use git aliases (instead of shell aliases). To do this: -1. Set the `FORGIT_STANDALONE` flag - - example: `export FORGIT_STANDALONE=1` -2. Add the bin directory in `FORGIT_INSTALL_DIR` to your `PATH` - - example: `PATH="$PATH:$FORGIT_INSTALL_DIR/bin"` -3. You can now run any forgit command as a subcommand of git! - - example: `git forgit log` -4. Add (aliases in git)[https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases] - - example: `git config --global alias.cf 'forgit checkout_file'` -5. Use the alias in git instead of the shell - - example: `git cf` +#### 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