threads / patch / 51215

patch, 2 partsdocument alias accepting non-command first word

Subject: [PATCH 0/2] document alias accepting non-command first word

## tl;dr

8 messages between May 31, 2019 and Jun 6, 2019. Diffs are folded; open one to read it.

replies: 7people: 2as markdown or json

Denton Liu· May 31, 2019, 20:23 UTC · lore

When I first saw Johannes' email here[1], I was surprised that an alias where the first-word is a command-line option to be passed into `git` was permitted. I was only used to aliases where the first word is a command.

Document this behaviour so that users will be able to discover that this is a feature.

[1]: https://public-inbox.org/git/nycvar.QRO.7.76.6.1905281235280.44@tvgsbejvaqbjf.bet/
Denton Liu (2):
  config/alias.txt: change " and ' to `
  config/alias.txt: document alias accepting non-command first word
 Documentation/config/alias.txt | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
-- 
2.22.0.rc1.169.g49223abbf8
Denton Liu· May 31, 2019, 20:23 UTC · re: Denton Liu · lore

[PATCH 1/2] config/alias.txt: change " and ' to `

Before, the documentation would mix " and ' for code and config snippets. Change these instances to ` so that they are marked up in monospace.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 Documentation/config/alias.txt | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Show changes to Documentation/config/alias.txt +6 −6
diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt
index 0b14178314..5425449a50 100644
--- a/Documentation/config/alias.txt
+++ b/Documentation/config/alias.txt
@@ -1,7 +1,7 @@
 alias.*::
 	Command aliases for the linkgit:git[1] command wrapper - e.g.
-	after defining "alias.last = cat-file commit HEAD", the invocation
-	"git last" is equivalent to "git cat-file commit HEAD". To avoid
+	after defining `alias.last = cat-file commit HEAD`, the invocation
+	`git last` is equivalent to `git cat-file commit HEAD`. To avoid
 	confusion and troubles with script usage, aliases that
 	hide existing Git commands are ignored. Arguments are split by
 	spaces, the usual shell quoting and escaping is supported.
@@ -9,10 +9,10 @@ alias.*::
 +
 If the alias expansion is prefixed with an exclamation point,
 it will be treated as a shell command.  For example, defining
-"alias.new = !gitk --all --not ORIG_HEAD", the invocation
-"git new" is equivalent to running the shell command
-"gitk --all --not ORIG_HEAD".  Note that shell commands will be
+`alias.new = !gitk --all --not ORIG_HEAD`, the invocation
+`git new` is equivalent to running the shell command
+`gitk --all --not ORIG_HEAD`.  Note that shell commands will be
 executed from the top-level directory of a repository, which may
 not necessarily be the current directory.
-`GIT_PREFIX` is set as returned by running 'git rev-parse --show-prefix'
+`GIT_PREFIX` is set as returned by running `git rev-parse --show-prefix`
 from the original current directory. See linkgit:git-rev-parse[1].
-- 
2.22.0.rc1.169.g49223abbf8
Denton Liu· May 31, 2019, 20:23 UTC · re: Denton Liu · lore

[PATCH 2/2] config/alias.txt: document alias accepting non-command first word

One can see that an alias that begins with a non-command first word, such as `loud-rebase = -c commit.verbose=true rebase`, is permitted. However, this isn't immediately obvious to users as alias instances typically begin with a command.

Document the fact that an alias can begin with a non-command first word so that users will be able to discover that this is a feature.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 Documentation/config/alias.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Show changes to Documentation/config/alias.txt +8 −0
diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt
index 5425449a50..f241f03ebe 100644
--- a/Documentation/config/alias.txt
+++ b/Documentation/config/alias.txt
@@ -7,6 +7,14 @@ alias.*::
 	spaces, the usual shell quoting and escaping is supported.
 	A quote pair or a backslash can be used to quote them.
 +
+Note that the first word of an alias does not necessarily have to be a
+command. It can be a command-line option that will be passed into the
+invocation of `git`. In particular, this is useful when used with `-c`
+to pass in one-time configurations. For example,
+`loud-rebase = -c commit.verbose=true rebase` can be defined such that
+running `git loud-merge` would be equivalent to
+`git -c commit.verbose=true rebase`.
++
 If the alias expansion is prefixed with an exclamation point,
 it will be treated as a shell command.  For example, defining
 `alias.new = !gitk --all --not ORIG_HEAD`, the invocation
-- 
2.22.0.rc1.169.g49223abbf8
Johannes Schindelin· Jun 5, 2019, 12:37 UTC · re: Denton Liu · lore

Re: [PATCH 2/2] config/alias.txt: document alias accepting non-command first word

Hi Denton,
On Fri, 31 May 2019, Denton Liu wrote:
Show 7 quoted lines
> One can see that an alias that begins with a non-command first word,
> such as `loud-rebase = -c commit.verbose=true rebase`, is permitted.
> However, this isn't immediately obvious to users as alias instances
> typically begin with a command.
>
> Document the fact that an alias can begin with a non-command first word
> so that users will be able to discover that this is a feature.
You caught me.

Granted, back in 2006, when I introduced that feature, we were not *quite* as diligent about documenting new features as we are today (see 4ab243a944a6 (Allow an alias to start with "-p", 2006-07-24)).

I like your patch! Maybe you would like to mention `-p`, too, as a possible use case, as that was the original reason I introduced the feature? (To this day, the first thing I do on a new machine *right* after installing Git is to call `git config --global alias.ps '-p status'`)

I'd be fine with these two patches as-are, of course.

Thank you! Dscho

Show 29 quoted lines
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  Documentation/config/alias.txt | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt
> index 5425449a50..f241f03ebe 100644
> --- a/Documentation/config/alias.txt
> +++ b/Documentation/config/alias.txt
> @@ -7,6 +7,14 @@ alias.*::
>  	spaces, the usual shell quoting and escaping is supported.
>  	A quote pair or a backslash can be used to quote them.
>  +
> +Note that the first word of an alias does not necessarily have to be a
> +command. It can be a command-line option that will be passed into the
> +invocation of `git`. In particular, this is useful when used with `-c`
> +to pass in one-time configurations. For example,
> +`loud-rebase = -c commit.verbose=true rebase` can be defined such that
> +running `git loud-merge` would be equivalent to
> +`git -c commit.verbose=true rebase`.
> ++
>  If the alias expansion is prefixed with an exclamation point,
>  it will be treated as a shell command.  For example, defining
>  `alias.new = !gitk --all --not ORIG_HEAD`, the invocation
> --
> 2.22.0.rc1.169.g49223abbf8
>
>
Denton Liu· Jun 5, 2019, 20:10 UTC · re: Denton Liu · lore

[PATCH v2 0/2] Doc: document alias accepting non-command first word

Thanks for the review, Johannes. I think it's a good idea to add another alias for `-p` so included that suggestion. Also, while I was at it, I found a typo so I fixed that too.

Changes since v1:
* s/loud-merge/loud-rebase/
* Add `-p` as another example since that was Dscho's original use-case
Denton Liu (2):
  config/alias.txt: change " and ' to `
  config/alias.txt: document alias accepting non-command first word
 Documentation/config/alias.txt | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
Interdiff against v1:
Show changes to Documentation/config/alias.txt +5 −3
diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt
index f241f03ebe..f1ca739d57 100644
--- a/Documentation/config/alias.txt
+++ b/Documentation/config/alias.txt
@@ -10,10 +10,12 @@ alias.*::
 Note that the first word of an alias does not necessarily have to be a
 command. It can be a command-line option that will be passed into the
 invocation of `git`. In particular, this is useful when used with `-c`
-to pass in one-time configurations. For example,
+to pass in one-time configurations or `-p` to force pagination. For example,
 `loud-rebase = -c commit.verbose=true rebase` can be defined such that
-running `git loud-merge` would be equivalent to
-`git -c commit.verbose=true rebase`.
+running `git loud-rebase` would be equivalent to
+`git -c commit.verbose=true rebase`. Also, `ps = -p status` would be a
+helpful alias since `git ps` would paginate the output of `git status`
+where the original command does not.
 +
 If the alias expansion is prefixed with an exclamation point,
 it will be treated as a shell command.  For example, defining
-- 
2.22.0.rc1.169.g49223abbf8
Denton Liu· Jun 5, 2019, 20:10 UTC · re: Denton Liu · lore

[PATCH v2 1/2] config/alias.txt: change " and ' to `

Before, the documentation would mix " and ' for code and config snippets. Change these instances to ` so that they are marked up in monospace.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 Documentation/config/alias.txt | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Show changes to Documentation/config/alias.txt +6 −6
diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt
index 0b14178314..5425449a50 100644
--- a/Documentation/config/alias.txt
+++ b/Documentation/config/alias.txt
@@ -1,7 +1,7 @@
 alias.*::
 	Command aliases for the linkgit:git[1] command wrapper - e.g.
-	after defining "alias.last = cat-file commit HEAD", the invocation
-	"git last" is equivalent to "git cat-file commit HEAD". To avoid
+	after defining `alias.last = cat-file commit HEAD`, the invocation
+	`git last` is equivalent to `git cat-file commit HEAD`. To avoid
 	confusion and troubles with script usage, aliases that
 	hide existing Git commands are ignored. Arguments are split by
 	spaces, the usual shell quoting and escaping is supported.
@@ -9,10 +9,10 @@ alias.*::
 +
 If the alias expansion is prefixed with an exclamation point,
 it will be treated as a shell command.  For example, defining
-"alias.new = !gitk --all --not ORIG_HEAD", the invocation
-"git new" is equivalent to running the shell command
-"gitk --all --not ORIG_HEAD".  Note that shell commands will be
+`alias.new = !gitk --all --not ORIG_HEAD`, the invocation
+`git new` is equivalent to running the shell command
+`gitk --all --not ORIG_HEAD`.  Note that shell commands will be
 executed from the top-level directory of a repository, which may
 not necessarily be the current directory.
-`GIT_PREFIX` is set as returned by running 'git rev-parse --show-prefix'
+`GIT_PREFIX` is set as returned by running `git rev-parse --show-prefix`
 from the original current directory. See linkgit:git-rev-parse[1].
-- 
2.22.0.rc1.169.g49223abbf8
Denton Liu· Jun 5, 2019, 20:10 UTC · re: Denton Liu · lore

[PATCH v2 2/2] config/alias.txt: document alias accepting non-command first word

One can see that an alias that begins with a non-command first word, such as `loud-rebase = -c commit.verbose=true rebase`, is permitted. However, this isn't immediately obvious to users as alias instances typically begin with a command.

Document the fact that an alias can begin with a non-command first word so that users will be able to discover that this is a feature.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 Documentation/config/alias.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)
Show changes to Documentation/config/alias.txt +10 −0
diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt
index 5425449a50..f1ca739d57 100644
--- a/Documentation/config/alias.txt
+++ b/Documentation/config/alias.txt
@@ -7,6 +7,16 @@ alias.*::
 	spaces, the usual shell quoting and escaping is supported.
 	A quote pair or a backslash can be used to quote them.
 +
+Note that the first word of an alias does not necessarily have to be a
+command. It can be a command-line option that will be passed into the
+invocation of `git`. In particular, this is useful when used with `-c`
+to pass in one-time configurations or `-p` to force pagination. For example,
+`loud-rebase = -c commit.verbose=true rebase` can be defined such that
+running `git loud-rebase` would be equivalent to
+`git -c commit.verbose=true rebase`. Also, `ps = -p status` would be a
+helpful alias since `git ps` would paginate the output of `git status`
+where the original command does not.
++
 If the alias expansion is prefixed with an exclamation point,
 it will be treated as a shell command.  For example, defining
 `alias.new = !gitk --all --not ORIG_HEAD`, the invocation
-- 
2.22.0.rc1.169.g49223abbf8
Johannes Schindelin· Jun 6, 2019, 12:48 UTC · re: Denton Liu · lore

Re: [PATCH v2 0/2] Doc: document alias accepting non-command first word

Hi Denton,
On Wed, 5 Jun 2019, Denton Liu wrote:
Show 8 quoted lines
> Thanks for the review, Johannes. I think it's a good idea to add another
> alias for `-p` so included that suggestion. Also, while I was at it, I
> found a typo so I fixed that too.
>
> Changes since v1:
>
> * s/loud-merge/loud-rebase/
> * Add `-p` as another example since that was Dscho's original use-case

Looks good to me! Dscho

← back to recent threads