aboutsummaryrefslogtreecommitdiff
path: root/contrib/completion/git-completion.bash
diff options
context:
space:
mode:
authorDavid Mandelberg <david@mandelberg.org>2025-03-23 17:05:46 -0400
committerJunio C Hamano <gitster@pobox.com>2025-03-23 23:03:12 -0700
commit5637bdc352a7763e30290bb37239a61cb9865d1b (patch)
treead3fa9340f66998848f1a6fcf32234f256433c33 /contrib/completion/git-completion.bash
parent6a64ac7b014fa2cfa7a69af3c253bcd53a94b428 (diff)
downloadgit-5637bdc352a7763e30290bb37239a61cb9865d1b.tar.xz
completion: add helper to count path components
A follow-up commit will use this with for-each-ref to strip the right number of path components from refnames. Signed-off-by: David Mandelberg <david@mandelberg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/completion/git-completion.bash')
-rw-r--r--contrib/completion/git-completion.bash11
1 files changed, 11 insertions, 0 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 413911be3b..5fdc71208e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -234,6 +234,17 @@ __git_dequote ()
done
}
+# Prints the number of slash-separated components in a path.
+# 1: Path to count components of.
+__git_count_path_components ()
+{
+ local path="$1"
+ local relative="${path#/}"
+ relative="${relative%/}"
+ local slashes="/${relative//[^\/]}"
+ echo "${#slashes}"
+}
+
# The following function is based on code from:
#
# bash_completion - programmable completion functions for bash 3.2+