cmd - Why does filtering output of git diff with findstr using a regular expression to get just lines ending with .js not work? -
i'm working on first javascript project. advised me use eslint git pre-hook check code. i'm writing own pre-hook pass eslint (only changed files checked). i'm trying find every file .js extension. tried following solutions none working:
git diff --cached --name-only --diff-filter=acm | findstr /r ".js$" => returns nothing git diff --cached --name-only --diff-filter=acm | findstr /r ".js" => returns .js , .json git diff --cached --name-only --diff-filter=acm | findstr /r ".js^$" => returns nothing
could me regular expression find every file .js extension?
open command prompt window , run findstr /?
output of standard windows console application.
there perhaps no need regular expression find @ all. simple case-insensitive (/i
) interpreted literal (/l
) search string additional option match lines ending (/e
) string enough.
git diff --cached --name-only --diff-filter=acm | findstr /e /i /l .js
another solution using /c:
results in interpreting search string default literal string (in cases) except option /r
used forcing regular expression interpretation.
git diff --cached --name-only --diff-filter=acm | findstr /e /i /c:.js
but in case of lines output git
have trailing spaces or horizontal tabs necessary use case-insensitive regular expression find.
git diff --cached --name-only --diff-filter=acm | findstr /i /r /c:"\.js[ ]*$"
.
must escaped backslash in search expression interpreted literal character instead of regular expression meaning of character.
please note 1 character in square bracket space character , other 1 horizontal tab character. tab character displayed above , below according html standard sequence of 1 or more spaces.
in case better use batch file difficult "type" tab character in command prompt window.
git.exe diff --cached --name-only --diff-filter=acm | %systemroot%\system32\findstr.exe /i /r /c:"\.js[ ]*$"
it advisable in batch file specify files/scripts execute file extension , if possible full path make batch file independent on current values of environment variables path
, pathext
as possible.
Comments
Post a Comment