-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
F() { | ||
if [ $# -eq 0 ]; then # No arguments given | ||
find / 2>/dev/null | ||
else | ||
if [[ "$1" =~ -i=.+ ]]; then | ||
echo "$1olssssssssssssssssssssssssssssssssss" | ||
ignored_paths="$(echo "${1}" | cut -d "=" -f2 | tr ',' ' ')" | ||
find_args_ignored_paths="" | ||
IFS=' ' | ||
for path in ${ignored_paths}; do | ||
echo "$path entra en el for" | ||
find_args_ignored_paths+=" -not -path '${path}' " | ||
done | ||
shift | ||
fi | ||
if [ -d "$1" ]; then | ||
first_argument="$1" | ||
shift | ||
else | ||
first_argument="." | ||
fi | ||
IFS=$'\n' | ||
while [ -n "$1" ]; do | ||
echo "FIND IGNORED PATHS: ${find_args_ignored_paths}FidnBBBBBBBBBBBBBBBBBBBBBBB" | ||
for filename in $(find "${first_argument}" -type f -not -path '*/\.git/*' ${find_args_ignored_paths} 2>/dev/null); do | ||
local result="$(grep "$1" < "${filename}" 2>/dev/null)" | ||
if [ -n "$(echo "${result}")" ]; then | ||
echo | ||
echo -e "\e[0;33m${filename}\e[0m" | ||
grep -hnI -B 5 -A 5 --color='auto' "$1" < "${filename}" 2>/dev/null | ||
fi | ||
done | ||
shift | ||
done | ||
fi | ||
previous_lines=5 | ||
following_lines=5 | ||
|
||
# Process arguments | ||
while [ -n "$1" ]; do | ||
case "$1" in | ||
"-A") | ||
if [ $# -eq 1 ]; then | ||
echo "ERROR: the \"$1\" option needs to be followed by another argument" | ||
exit 3 | ||
fi | ||
shift | ||
previous_lines=$1 | ||
;; | ||
"-B") | ||
if [ $# -eq 1 ]; then | ||
echo "ERROR: the \"$1\" option needs to be followed by another argument" | ||
exit 3 | ||
fi | ||
shift | ||
following_lines=$1 | ||
;; | ||
*) # Error | ||
echo "ERROR: \"$1\" not recognized argument. Aborting..." | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
# Process stdin | ||
while IFS= read -r line; do | ||
echo -e "\e[0;33m${line}\e[0m" | ||
grep -hnI -B ${following_lines} -A ${previous_lines} --color='auto' "$1" < "${line}" 2>/dev/null | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters