From d136ac02627bd73d019e4b2f9e0ce971730a3f55 Mon Sep 17 00:00:00 2001 From: Hamidreza Date: Fri, 11 Apr 2025 10:13:53 +0330 Subject: [PATCH] autoComplete improved for better time folder filtering and fields improved for better field filtering --- cmake/autoComplete | 107 +++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 33 deletions(-) diff --git a/cmake/autoComplete b/cmake/autoComplete index 6c289ce5..babf3843 100644 --- a/cmake/autoComplete +++ b/cmake/autoComplete @@ -1,48 +1,89 @@ PF_cFlags="--description --help --version" AllTimeFolders= __getAllTime(){ - files=( $(ls) ) - deleteFiles=(settings caseSetup cleanThisCase VTK runThisCase stl postprocess postProcess) - declare -A delk - for del in "${deleteFiles[@]}" ; do delk[$del]=1 ; done - # Tag items to remove, based on - for k in "${!files[@]}" ; do - [ "${delk[${files[$k]}]-}" ] && unset 'files[k]' - done - # Compaction - COMPREPLY=("${files[@]}") - AllTimeFolders="${files[@]}" + # Initialize empty array for time folders + local time_folders=() + + # Loop through all directories in current folder + for dir in */; do + # Remove trailing slash + dir=${dir%/} + + # Check if directory name is a valid floating point number + # This pattern matches integers and floating point numbers + if [[ $dir =~ ^[0-9]+(\.[0-9]+)?$ ]]; then + time_folders+=("$dir") + fi + done + + # Set completion reply to the time folders + COMPREPLY=("${time_folders[@]}") + AllTimeFolders="${time_folders[@]}" } __getFields(){ - __getAllTime - local -A unique_files=() + __getAllTime + local -A unique_files=() + # Files to exclude from suggestions + local exclude_files=("shapeHash" "pStructure" "particleInsertion" "p" "alpha" "U" "Sp" "Su" "phi") + declare -A exclude_dict + + # Build exclude dictionary for faster lookups + for file in "${exclude_files[@]}"; do + exclude_dict["$file"]=1 + done - for dir in $AllTimeFolders; do - # Check if the directory exists - if [ ! -d "$dir" ]; then - continue # Skip to the next directory - fi - - files_in_dir=$(find "$dir" -maxdepth 1 -type f -printf '%f\n' | sort -u) - - # Add filenames to the associative array (duplicates will be overwritten) - while IFS= read -r filename; do - unique_files["$filename"]=1 # Just the key is important, value can be anything - done <<< "$files_in_dir" - - done - COMPREPLY=("${!unique_files[@]}") - AllTimeFolders= + for dir in $AllTimeFolders; do + # Skip if not a directory + [ ! -d "$dir" ] && continue + + # Find all files in this time directory + while IFS= read -r filename; do + # Skip empty lines and excluded files + [ -z "$filename" ] || [ "${exclude_dict[$filename]+exists}" ] && continue + + # Add to unique files + unique_files["$filename"]=1 + done < <(find "$dir" -maxdepth 1 -type f -printf '%f\n') + done + + # Set completion reply to the unique filenames + COMPREPLY=(${!unique_files[@]}) + + # Clear global variable + AllTimeFolders= } _pFlowToVTK(){ - if [ "$3" == "--time" ] ; then + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" + + # Check if we're completing a field + local is_field=0 + for ((i=1; i