git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] contrib/git-jump/git-jump: support alias expansion

From
Taylor Blau <me@ttaylorr.com>
Date
Sep 4, 2019, 17:55 UTC
Message-ID
<473a7c7b241ad2d449d3bcb6daeb77a179c7e45f.1567619579.git.me@ttaylorr.com>
In-Reply-To
<cover.1567619579.git.me@ttaylorr.com>

When a caller of 'git-jump' has, say, the alias 'di' assigned to 'diff', it can be cumbersome to remember to type 'git jump diff' instead of the shorthand '... di' that they are used to.

Let's teach 'git-jump' to expand these aliases before calling the mode-specific subroutine. Do so by fetching the configuration value of 'alias.$1', defaulting to "$1" in the case that no alias is set.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 contrib/git-jump/README   | 4 ++++
 contrib/git-jump/git-jump | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/contrib/git-jump/README b/contrib/git-jump/README
index 2f618a7f97..9e59990ba0 100644
--- a/contrib/git-jump/README
+++ b/contrib/git-jump/README
@@ -74,6 +74,10 @@ git jump grep -i foo_bar
 
 # use the silver searcher for git jump grep
 git config jump.grepCmd "ag --column"
+
+# jump to changes via an alias of 'git diff', assuming you have set
+# `git config alias.diff di`
+git jump di
 --------------------------------------------------
 
 
diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index 931b0fe3a9..15e129b350 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -15,6 +15,8 @@ grep: elements are grep hits. Arguments are given to git grep or, if
       configured, to the command in `jump.grepCmd`.
 
 ws: elements are whitespace errors. Arguments are given to diff --check.
+
+Aliases of any of the above are expanded automatically.
 EOF
 }
 
@@ -68,7 +70,7 @@ if test $# -lt 1; then
 	usage >&2
 	exit 1
 fi
-mode=$1; shift
+mode="$(git config --default "$1" --get -- "alias.$1")"; shift
 
 trap 'rm -f "$tmp"' 0 1 2 3 15
 tmp=`mktemp -t git-jump.XXXXXX` || exit 1
-- 
2.22.0
Previous: Taylor BlauNext: Taylor Blau
Message 2 of 4 in “contrib/git-jump: support alias expansion”
  1. 0/1 contrib/git-jump: support alias expansionTaylor Blau, Sep 4, 2019
  2. 1/1 contrib/git-jump/git-jump: support alias expansionTaylor Blau, Sep 4, 2019
  3. Taylor BlauSep 4, 2019
  4. Jeff KingSep 5, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.