Skip to content

Commit

Permalink
UPDATED: F fucntion rework
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Apr 26, 2024
1 parent ace78fa commit 85e833e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
69 changes: 35 additions & 34 deletions data/features/FFunction/F.sh
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
}
2 changes: 0 additions & 2 deletions data/features/f/f.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ f()
shift
custom_command="$1"
;;

*) # Error
echo num: $#
if [ $# -eq 1 ]; then # If only one argument this is the last argument and means that is the search dir
find_dir="$1"
else
Expand Down

0 comments on commit 85e833e

Please sign in to comment.