Use grep instead of awk to choose files to format.
dblume

dblume commited on 2024-12-22 14:47:05
Showing 1 changed files, with 2 additions and 2 deletions.


Grep with -P and '\K' is shorter. And the awk previously published did not
support filenames with consecutive spaces. The correct awk would've used
FPAT to allow double-quote escaping delimiters and would've been longer:

    awk '/^[MTARC].+\.([hc](pp)?)"?$/ {print $2}' FPAT='[^ ]*|"[^"]+"'
... ...
@@ -90,10 +90,10 @@ into the unstaged area. Use it like this:
90 90
 
91 91
 ### Option 2: Manually clang-format the staged files
92 92
 
93
-The following formats the staged files, not only your staged changes:
93
+The following formats the staged *files*, not only your staged *changes*:
94 94
 
95 95
     git status --porcelain | \
96
-    awk '/^[MTARC].+\.([hc](pp)?)"?$/ {$1=""; $0=$0; $1=$1; print}' | \
96
+    grep -Po '^[MTARC]..\K.+\.[ch](pp)?"?$' | \
97 97
     xargs clang-format -i
98 98
 
99 99
 Or a similar approach but it'll also overwrite your unstaged changes too:
100 100