-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace
More file actions
executable file
·36 lines (27 loc) · 1.16 KB
/
replace
File metadata and controls
executable file
·36 lines (27 loc) · 1.16 KB
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
#!/usr/bin/env bash
#
# replace - Find and replace text in a git repo fast
#
# USAGE
# replace <TEXT_TO_FIND> <TEXT_TO_REPLACE_WITH>
#
# TODO: Clean up this script
#
set -o nounset # Exit when using an undefined variable. Use ${VAR:-} to use an undefined VAR.
set -o errexit # Exit when a command fails. Append "|| true" if a command to fail.
[[ "${DEBUG:-}" == 'true' ]] && set -o xtrace
# readonly file_spec="${1}"
readonly before="${1}"
readonly after="${2}"
time git grep "${before}" | cut -d ':' -f 1 | parallel --jobs "100%" --progress "gsed -i -e 's/${before}\b/${after}/g' {}"
# time find . -name *.rb -exec gsed -i -e 's/old_service\b/new_service/g' {} \;
# 33.106
# time find . -name *.rb | parallel -j24 --progress "gsed -i -e 's/old_service\b/new_service/g' {}"
# 20.136
# time git grep old_service | cut -d ':' -f 1 | parallel -j24 --progress "gsed -i -e 's/old_service\b/new_service/g' {}"
# 5.893
# time rg old_service | cut -d ':' -f 1 | parallel -j24 --progress "gsed -i -e 's/old_service\b/new_service/g' {}"
# 6.036
# time git grep old_service | cut -d ':' -f 1 | xargs -I "{}" gsed -i -e 's/old_service\b/new_service/g' {}
# no progress indicator
# 6.963