Skip to content

Commit

Permalink
FINISHED: f rework, -l was not implemented but other arguments were
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Apr 26, 2024
1 parent 03449ff commit ace78fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ whoami

Linux-Auto-Customizer
test
src/AleixMT/
17 changes: 8 additions & 9 deletions data/features/f/f.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ f()
{
default_ignored_dirs=("node_modules" ".git")
find_ignored_dirs_shell_command=""
# Since we expect f to be called as a binary in the PATH, we can expect the working directory to be the same that
# we are using f against
skip_defaults="false"
ignore_all_levels="true"
find_dir=""
Expand All @@ -20,7 +18,7 @@ f()
"--ignore-all" | "-i")
ignore_all_levels="true"
;;
"--literal" | "-l")
"--literal" | "-l") # TODO: Unluckily, I didn't make it work...
ignore_all_levels="false"
;;
"--dir" | "-d" | "--dir-exclude")
Expand All @@ -30,7 +28,7 @@ f()
fi
shift
if [ "${ignore_all_levels}" = "true" ]; then
find_ignored_dirs_shell_command+=" -o -path ./'*'/$1/'*'"
find_ignored_dirs_shell_command+=" -o -path */$1/*"
else
find_ignored_dirs_shell_command+=" -o -path ./$1/'*'"
fi
Expand All @@ -45,6 +43,7 @@ f()
;;

*) # 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 All @@ -56,21 +55,21 @@ f()
shift
done

# Remove the space and the -o from the beginning of the ignored dirs
find_ignored_dirs_shell_command="${find_ignored_dirs_shell_command:3}"

# Add the default ignored paths depending on the state of the flag
if [ "${skip_defaults}" = "false" ]; then
for dir in "${default_ignored_dirs[@]}"; do
if [ "${ignore_all_levels}" = "true" ]; then
find_ignored_dirs_shell_command+=" -o -path ./'*'/${dir}/'*'"
find_ignored_dirs_shell_command+=" -o -path */${dir}/*"
else
find_ignored_dirs_shell_command+=" -o -path ./${dir}/'*'"
fi
done
fi

# Set current directory if query directory not present
if [ -z "${find_dir}" ]; then
# Since we expect f to be called as a binary in the PATH, we can expect the working directory to be the same that
# we are using f against
find_dir="."
else
if [ ! -d "${find_dir}" ]; then
Expand All @@ -79,5 +78,5 @@ f()
fi
fi

find "${find_dir}" -type f -not \( ${find_ignored_dirs_shell_command} \) 2>/dev/null
find "${find_dir}" -type f -not \( -type d ${find_ignored_dirs_shell_command} \) 2> /dev/null
}

0 comments on commit ace78fa

Please sign in to comment.