Skip to content

Conversation

@ShivamB25
Copy link
Contributor

@ShivamB25 ShivamB25 commented Sep 15, 2025

Summary

This PR implements a --reverse-sort command-line flag that reverses the default sorting order in non-interactive mode, displaying files from smallest to largest instead of largest to smallest.

Fixes #435

Problem

In non-interactive mode, gdu sorts entries from largest to smallest by default. When analyzing directories with many files, users must scroll through large files to view smaller ones, creating a poor user experience especially in terminal environments with limited screen space.

Solution

Added --reverse-sort flag that:

  • Works exclusively in non-interactive mode
  • Reverses sort order to show smallest files first
  • Maintains all existing functionality and performance
  • Integrates with existing flags (--summarize, --top, etc.)
  • Supports YAML configuration files

Changes Made

  1. CLI Interface: Added --reverse-sort flag with help text
  2. App Configuration: Added ReverseSort field to Flags struct
  3. Non-Interactive Logic: Modified sorting in stdout/stdout.go
  4. Documentation: Updated README.md and configuration.md
  5. Testing: Added 6 comprehensive test functions

Usage Examples

# Default behavior (largest to smallest)
gdu --non-interactive /path/to/directory

# New reverse sort (smallest to largest)  
gdu --non-interactive --reverse-sort /path/to/directory

# Works with other flags
gdu --reverse-sort --no-color --non-interactive /path

Testing

  • All existing tests pass
  • Added comprehensive tests for new functionality
  • Tested edge cases: empty directories, config files, flag combinations
  • Verified backward compatibility

Performance

Zero performance impact - uses same sorting algorithms with conditional reverse application.

- Add --reverse-sort boolean flag to command line interface
- Enables reversing sort order from largest-to-smallest to smallest-to-largest
- Only applies to non-interactive mode to address scrolling usability issues
- Follows existing CLI argument patterns and conventions
- Add ReverseSort bool field to Flags struct for YAML config support
- Pass ReverseSort parameter to CreateStdoutUI for non-interactive mode
- Maintains backward compatibility with existing configuration options
- Enables --reverse-sort flag to be stored in config files
- Update CreateStdoutUI function signature to accept reverseSort parameter
- Add reverseSort field to UI struct for state tracking
- Modify showDir function to conditionally apply reverse sorting:
  * Default: sort.Reverse() for largest-to-smallest (existing behavior)
  * With --reverse-sort: standard sort() for smallest-to-largest (new behavior)
- Maintains performance with no additional overhead
- Add 6 new test functions to validate reverse sort behavior
- Test reverse sort with various flag combinations (colors, summarize, top)
- Test reverse sort with analysis files and different UI modes
- Add strings import for test utilities
- Ensure backward compatibility with existing test patterns
- All new tests pass alongside existing 300+ test suite
- Add --reverse-sort flag to CLI help documentation in README.md
- Add usage example showing reverse sort in non-interactive mode
- Document reverse-sort configuration option in configuration.md
- Maintain consistent documentation formatting and style
- Provide clear explanation of feature purpose and usage
- Ignore compiled gdu binary from version control
- Prevents accidental commit of build artifacts
- Maintains clean repository structure
@ShivamB25
Copy link
Contributor Author

@dundee enjoy another PR (last one was empty folder press enter , error if u remember)

- Add missing reverseSort parameter to CreateStdoutUI function call
- Fixes compilation error in stdout_linux_test.go
- Maintains consistency with updated function signature
@ShivamB25
Copy link
Contributor Author

forgot about that one yikes

@codecov
Copy link

codecov bot commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.50%. Comparing base (e96890c) to head (a056b30).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
cmd/gdu/main.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
- Coverage   83.50%   83.50%   -0.01%     
==========================================
  Files          46       46              
  Lines        4408     4414       +6     
==========================================
+ Hits         3681     3686       +5     
- Misses        655      656       +1     
  Partials       72       72              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dundee dundee merged commit df73872 into dundee:master Sep 18, 2025
10 checks passed
@dundee
Copy link
Owner

dundee commented Sep 18, 2025

Very nice contribution! Thank you.

@ShivamB25
Copy link
Contributor Author

@dundee no problem. i use the tool daily so thought it would be nice to add

@dundee dundee added this to the 5.32 milestone Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for reverse sort order in --non-interactive

2 participants