@@ -143,6 +143,9 @@ async def execute(
143143 ignore_dirs = "|" .join ([f"^{ d } $" for d in self .ignored_dirs ])
144144 ignore_pattern = f" | grep -v -E '{ ignore_dirs } '"
145145
146+ # Escape the target directory for use in regex patterns
147+ escaped_target_dir = target_dir .replace ("." , r"\." )
148+
146149 # Build the appropriate find command based on recursion setting and git availability
147150 if git_available :
148151 # Use git commands when git is available to respect .gitignore
@@ -163,11 +166,11 @@ async def execute(
163166 # Use grep to filter out target directory, then check each remaining directory
164167 if list_files_args .recursive :
165168 # Filter out the target directory upfront, then check git ignore status
166- dirs_command = f"find { target_dir } -xdev -type d | grep -v '^{ target_dir } $' | while read -r dir; do git check-ignore \" $dir/\" >/dev/null || echo \" $dir\" ; done | sort"
169+ dirs_command = f"find { target_dir } -xdev -type d | grep -v '^{ escaped_target_dir } $' | while read -r dir; do git check-ignore \" $dir/\" >/dev/null || echo \" $dir\" ; done | sort"
167170 if ignore_pattern :
168171 dirs_command += ignore_pattern
169172 else :
170- dirs_command = f"find { target_dir } -xdev -maxdepth 1 -type d | grep -v '^{ target_dir } $' | while read -r dir; do git check-ignore \" $dir/\" >/dev/null || echo \" $dir\" ; done | sort"
173+ dirs_command = f"find { target_dir } -xdev -maxdepth 1 -type d | grep -v '^{ escaped_target_dir } $' | while read -r dir; do git check-ignore \" $dir/\" >/dev/null || echo \" $dir\" ; done | sort"
171174 if ignore_pattern :
172175 dirs_command += ignore_pattern
173176 else :
@@ -182,7 +185,7 @@ async def execute(
182185 else :
183186 # List only immediate files and directories using find with maxdepth
184187 # -xdev: don't cross filesystem boundaries
185- dirs_command = f"find { target_dir } -xdev -maxdepth 1 -type d | grep -v '^{ target_dir } $' | sort"
188+ dirs_command = f"find { target_dir } -xdev -maxdepth 1 -type d | grep -v '^{ escaped_target_dir } $' | sort"
186189 if ignore_pattern :
187190 dirs_command += ignore_pattern
188191 files_command = f"find { target_dir } -xdev -maxdepth 1 -type f | sort"
0 commit comments