Skip to content

Small script for searching and replacing keywords across a project

Notifications You must be signed in to change notification settings

racoltdev/projectfind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Intro: projectfind / projectreplace

projectfind searches within and below the current working directory for a keyword or phrase and projectreplace replaces it with some other string. projectreplace uses projectfind and both can be used similarly. The available arguments and usages are the same between the two, but for the sake of clarity this guide is separated into one part for each.

If I'm handed an old python project without a requirements.txt, I might run projectfind import to find all the libraries needed for the project to run. Or if I'm working on an old project with some loose ends, I'll run projectfind todo -i. Similarly, if I want to rename a class, I would run projectreplace className newName.

It works on my debian install. If theres issues with it working on other platforms or shells, I might fix it. Open an issue to get it on my radar.

projectfind

Finds all instances of a keyphrase within a project.

Usage

projectfind [keyphrase] [arguments]
projectfind expects a keyphrase followed by any additional arguments.

Arguments

-h, --help
 Display the help manual.
-d , --depth
 The number of directories deep a search should go. Default is 2.
-e , --exclude
 Any file or directory glob that should be excluded from search.
-i, --ignorecase
 Case agnostic search.
-p, --partial
 Match keyphrase even if it is a part of another word.
-r , --exclusionrules
 Takes a file containing a newline separated list as argument. Any files or directories matched by globs in the list are excluded from the search. Useful if you search a project a lot or have some common system wide paths you exclude often.

Output

Returns a newline seperated list of file, line number, and line contents of each instance of the keyphrase across the project.

Examples

$projectfind import
 Finds all instances of "import" in files up to 2 directories below current working directory.
$projectfind main -d 1
 Finds all instances of "main" only in the current working directory.
$projectfind include -e Doxyfile -e bin/
 Finds all instances of "include" to depth 2, ignoring the bin directory and Doxyfile file.
$projectfind todo -i
 Case agnostic search for "todo".
$projectfind import -p
 Finds instances of "import" as well as other words like "imported".
$projectfind exec -r .gitignore
 Finds instances of "exec" excluding anything listed in .gitignore.
$projectfind "todo\|TODO"
$projectfind "todo|TODO" -E
 Searches for instances of "todo" or "TODO".
$projectfind include \<time.h\>
$projectfind include "<time.h>"
$projectfind "include <time.h>"
 These all find any instance of "include <time.h>" across the project with depth 2.

projectreplace

Replaces all instances of a phrase in a project with some other string.
projectreplace is built off of projectfind. All arguments and examples here are similarly mirrored in projectfind.

Usage

projectreplace [keyphrase] [replace phrase] [arguments]
projectreplace expects a keyphrase and the string to replace it with, followed by any additional arguments.

Arguments

-h, --help
 Display this manual.
-d , --depth
 The number of directories deep a search should go. Default is 2.
-e , --exclude
 Any file or directory glob that should be excluded from search.
-i, --ignorecase
 Case agnostic search.
-p, --partial
 Match and replace keyphrase even if it is a part of another word.
-r , --exclusionrules
 Takes a file containing a newline separated list as argument. Any files or directories matched by globs in the list are excluded from the search. Useful if you search a project a lot or have some common system wide paths you exclude often.

Output

Returns the content of each changed line in the project.

Examples

$projectreplace import include
 Finds all instances of "import" in files up to 2 directories below current working directory and replaces it with "include".
$projectreplace main notMain -d 1
 Finds and replaces all instances of "main" with "notMain" only in the current working directory.
$projectreplace include import -e Doxyfile -e bin/
 Finds and replaces all instances of "include" with replace, except in the bin directory and Doxyfile file.
$projectreplace todo TODO -i
 Case agnostic search for "todo" and replace all with "TODO".
$projectreplace import Import -p
 Finds instances of "import" as well as other words like "imported" and replaces the matching part of the word with "Import".
$projectreplace exec run -r .gitignore
 Replaces instances of "exec" with "run", excluding anything listed in .gitignore.
$projectreplace "todo\|TODO" DONE
$projectreplace "todo|TODO" DONE -E
 Replaces all "todo" and "TODO" with "DONE".
$projectreplace "include <time.h>" "include \"mytime.h\""
 Replace a string with whitespace and special characters.

About

Small script for searching and replacing keywords across a project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages