From 6e7f688453544a1105c868534526bf542bd73dfb Mon Sep 17 00:00:00 2001 From: AleixMT Date: Sat, 27 Apr 2024 02:31:53 +0200 Subject: [PATCH] UPDATED: remowrk f function --- data/features/FFunction/F.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/data/features/FFunction/F.sh b/data/features/FFunction/F.sh index f15044bf..8f3b5aaa 100755 --- a/data/features/FFunction/F.sh +++ b/data/features/FFunction/F.sh @@ -3,6 +3,8 @@ F() { previous_lines=5 following_lines=5 + grep_query_string="" + read_from_stdin="" # Process arguments while [ -n "$1" ]; do @@ -23,17 +25,29 @@ F() { shift following_lines=$1 ;; + "-") + read_from_stdin="true" + ;; *) # Error - echo "ERROR: \"$1\" not recognized argument. Aborting..." - exit 1 + if [ $# -eq 1 ]; then # If only one argument this is the last argument and means that is the search dir + grep_query_string="$1" + else + echo "ERROR: \"$1\" not recognized argument. Aborting..." + exit 1 + fi ;; 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 + if [ "${read_from_stdin}" = "true" ]; then + # Process stdin + while IFS= read -r line; do + grep -hnI -B ${following_lines} -A ${previous_lines} --color='auto' "${grep_query_string}" < "${line}" 2>/dev/null + done + else + while IFS= read -r line; do + grep -hnI -B ${following_lines} -A ${previous_lines} --color='auto' "${grep_query_string}" < "${line}" 2>/dev/null + done + fi }