Skip to content

Commit d8f22c0

Browse files
committed
sort uninstall commands, deepest dir first
1 parent f69734d commit d8f22c0

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/redfetch/meta.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,16 @@ def should_print_path(path):
507507

508508
def generate_removal_commands(paths):
509509
"""Generate OS-specific commands to remove the given directories."""
510+
def deepest_first(path: str) -> tuple[int, str]:
511+
depth = path.replace("\\", "/").rstrip("/").count("/")
512+
return (-depth, path.casefold())
513+
510514
system = platform.system()
511515
if system == 'Windows':
512516
# Generate PowerShell commands
513517
console.print("[bold]These directories may be removed manually after you make sure there's nothing you need from them, you can do so by running the following PowerShell commands:[/bold]\n")
514518
commands = []
515-
for path in sorted(paths):
516-
# Escape quotes and handle special characters
519+
for path in sorted(paths, key=deepest_first):
517520
escaped_path = path.replace("'", "''")
518521
command = f"Remove-Item -LiteralPath '{escaped_path}' -Recurse -Force"
519522
commands.append(command)
@@ -522,8 +525,7 @@ def generate_removal_commands(paths):
522525
# Assuming Unix-like system
523526
console.print("[bold]You can remove these directories by running the following commands in your terminal:[/bold]\n")
524527
commands = []
525-
for path in sorted(paths):
526-
# Escape single quotes
528+
for path in sorted(paths, key=deepest_first):
527529
escaped_path = path.replace("'", "'\\''")
528530
command = f"rm -rf '{escaped_path}'"
529531
commands.append(command)

0 commit comments

Comments
 (0)