From 85e833edceaed8e584c849e17ed2e3da41c7eadb Mon Sep 17 00:00:00 2001 From: AleixMT Date: Sat, 27 Apr 2024 01:02:37 +0200 Subject: [PATCH] UPDATED: F fucntion rework --- data/features/FFunction/F.sh | 69 ++++++++++++++++++------------------ data/features/f/f.sh | 2 -- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/data/features/FFunction/F.sh b/data/features/FFunction/F.sh index 218ee41c..f15044bf 100755 --- a/data/features/FFunction/F.sh +++ b/data/features/FFunction/F.sh @@ -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 } diff --git a/data/features/f/f.sh b/data/features/f/f.sh index dd39cef4..99661961 100755 --- a/data/features/f/f.sh +++ b/data/features/f/f.sh @@ -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