-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathfind_interview_prep.sh
executable file
·90 lines (75 loc) · 2.76 KB
/
find_interview_prep.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# This file is part of eRCaGuy_hello_world: https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world
# Find all files which contain the words "interview prep" (case *in*sensitive) in this repo.
#
# Dependencies:
# 1. Install ripgrep (rg) first.
# See here: https://github.com/BurntSushi/ripgrep#installation
# In the cmds below, update the version number to the latest release found here:
# https://github.com/BurntSushi/ripgrep/releases
#
# rg --version # check your version beforehand, if upgrading
# mkdir -p ~/Downloads/Install_Files/ripgrep
# cd ~/Downloads/Install_Files/ripgrep
# curl -LO https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep_13.0.0_amd64.deb
# sudo dpkg -i ripgrep_13.0.0_amd64.deb
# rg --version # check your version to ensure it was installed or upgraded
# Status: done and works!
# Check this script with:
#
## shellcheck find_interview_prep.sh
#
# Run command:
#
# ./find_interview_prep.sh
#
# Source (import) command to get access to any functions herein:
# [my answer] https://stackoverflow.com/a/62626515/4561887):
#
# . find_interview_prep.sh
# References:
# 1.
# RETURN_CODE_SUCCESS=0
RETURN_CODE_ERROR=1
# See my answer here: https://stackoverflow.com/a/60157372/4561887
FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[-1]}")"
SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")"
# SCRIPT_FILENAME="$(basename "$FULL_PATH_TO_SCRIPT")"
main() {
echo "Finding all \"interview prep\" files in directory"\
"\"$SCRIPT_DIRECTORY\" and lower."
cd "$SCRIPT_DIRECTORY" || exit "$RETURN_CODE_ERROR"
files="$(rg -i --no-ignore --no-hidden -l --color always 'interview prep')"
files_count="$(echo "$files" | wc -l)"
echo "$files"
echo "Done. $files_count file(s) found."
}
# Determine if the script is being sourced or executed (run).
# See:
# 1. "eRCaGuy_hello_world/bash/if__name__==__main___check_if_sourced_or_executed_best.sh"
# 1. My answer: https://stackoverflow.com/a/70662116/4561887
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
# This script is being run.
__name__="__main__"
else
# This script is being sourced.
__name__="__source__"
fi
# Only run `main` if this script is being **run**, NOT sourced (imported).
# - See my answer: https://stackoverflow.com/a/70662116/4561887
if [ "$__name__" = "__main__" ]; then
main "$@"
fi
# SAMPLE OUTPUT:
#
# 1) WHEN RUN (it prints "Running main.")
#
# eRCaGuy_hello_world/bash$ ../find_interview_prep.sh
# Finding all "interview prep" files in directory "/home/gabriel/GS/dev/eRCaGuy_hello_world" and lower.
# find_interview_prep.sh
# Done. 1 file(s) found.
#
#
# 2) WHEN SOURCED (no output)
#
# eRCaGuy_hello_world$ . find_interview_prep.sh