-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.cmd
67 lines (52 loc) · 1.38 KB
/
search.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@echo off
rem =====
rem For more information on ScriptTiger and more ScriptTiger scripts visit the following URL:
rem https://scripttiger.github.io/
rem Or visit the following URL for the latest information on this ScriptTiger script:
rem https://github.com/ScriptTiger/Repo-Search
rem =====
rem =====
rem Remember current directory for file output
rem =====
set DIR=%~dp0
rem =====
rem Change the current directory to the source directory to search
rem =====
if "%~1"=="" (
set /p INPUT=Root directory to search?
) else (
set INPUT=%~1)
cd "%INPUT%"
rem =====
rem File types to search for
rem =====
if "%~2"=="" (
set /p TYPES=Search which source files ^(i.e. "*.txt *.md" to search all txt and md files^)?
) else (
set TYPES=%~2)
rem =====
rem Begin main script
rem =====
:0
rem =====
rem Set options for search and execute
rem =====
choice /m "Use regular expressions?"
if %ERRORLEVEL%==1 (set FIND=findstr /r /s /i ) else (set FIND=findstr /s /i /c:)
set /p INPUT=Search for: || exit /b
set FIND=%FIND%"%INPUT%" %TYPES%^|more
%FIND%
rem =====
rem Give option to output search results to a file in the current directory
rem =====
choice /m "Output results to file?"
if %ERRORLEVEL%==1 (
set /p INPUT=Name of file to export results to? && %FIND%>"%DIR%%INPUT%.txt"
)
rem =====
rem Give option to open any source files of interest
rem =====
:1
set /P INPUT=Open file: || goto 0
write "%INPUT%"
goto 1