Skip to contentSkip to conversation

scripts/bash_aliases: man_gitstaged(): Script around a porcelain git command

PATCH Superseded Alejandro Colomar 1 participant 2 messages Feb 22, 2021 – Feb 23, 2021 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/bash_aliases: man_gitstaged(): Script around a porcelain git command

The output of 'git status' is not stable.

The more stable 'git status --porcelain' is more complex, and scripting around it would be more complex.

However, 'git diff --staged --name-only' produces almost exactly the output that we were lookiong for.

---
 scripts/bash_aliases | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/bash_aliases +3 -5
index 127ed5d08..dcc0eb28b 100644
@@ -153,13 +153,11 @@ function pdfman()
 
 function man_gitstaged()
 {
-	git status							\
-	|sed "/Changes not staged for commit:/q"			\
-	|grep -E "^\s*(modified|deleted|new file):"			\
-	|sed "s/^.*:\s*/, /"						\
+	git diff --staged --name-only					\
+	|sed "s/$/, /"							\
 	|sed "s%man[1-9]/%%"						\
 	|tr -d '\n'							\
-	|sed "s/^, //"
+	|sed "s/, $//"
 }
 
 ########################################################################
Signature · 1 line
2.30.1.721.g45526154a5
#1 lore raw

PATCH v2 1/1 scripts/bash_aliases: man_gitstaged(): Script around a more stable git command

The output of 'git status' is not intended to be stable.

The more stable 'git status --porcelain' is more complex, and scripting around it would be more complex.

However, 'git diff --staged --name-only' produces almost exactly the output that we were lookiong for. This simplifies the script, and makes it more stable and robust.

---

v2: Fix commit message

---
 scripts/bash_aliases | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/bash_aliases +3 -5
index 127ed5d08..dcc0eb28b 100644
@@ -153,13 +153,11 @@ function pdfman()
 
 function man_gitstaged()
 {
-	git status							\
-	|sed "/Changes not staged for commit:/q"			\
-	|grep -E "^\s*(modified|deleted|new file):"			\
-	|sed "s/^.*:\s*/, /"						\
+	git diff --staged --name-only					\
+	|sed "s/$/, /"							\
 	|sed "s%man[1-9]/%%"						\
 	|tr -d '\n'							\
-	|sed "s/^, //"
+	|sed "s/, $//"
 }
 
 ########################################################################
Signature · 1 line
2.30.1.721.g45526154a5