Skip to content

Comments

Add toggle features (Ctrl+G/T), fix bugs, add BATS tests#24

Open
jellydn wants to merge 24 commits intomieubrisse:mainfrom
jellydn:main
Open

Add toggle features (Ctrl+G/T), fix bugs, add BATS tests#24
jellydn wants to merge 24 commits intomieubrisse:mainfrom
jellydn:main

Conversation

@jellydn
Copy link
Contributor

@jellydn jellydn commented Aug 25, 2025

Add Toggle Features, Bug Fixes, Hardening & Tests

Toggle Features

  • Ctrl+T: Toggle visibility of gitignored files (.env, etc.)
  • Ctrl+G: Toggle between all files and git-changed files only
  • Independent state management with graceful fallback outside git repos

Bug Fixes

  • cmdk-core.sh: Exit code captured cleanup status instead of fzf; return used in non-sourced script; no cleanup on Ctrl-C/errors
  • list-files.sh: Home directory excludes computed but never applied to fd; shebang sh but uses bash arrays/pipefail
  • preview.sh: Shebang sh but uses pipefail; no fallbacks for missing tools
  • reload-files.sh: A && B || C is not if-then-else — C could run when A is true
  • cmdk.fish: Fixed bash process substitution incompatibility

Hardening

  • Flag validation in cmdk-core.sh — only -o, -s, -e accepted; unknown flags rejected
  • Dependency checks for fzf, fd, file at startup with actionable error messages
  • Tool fallbacks in preview.sh (batcat, macOS ls -G, missing tiv/pdftotext/unzip)
  • All scripts pass ShellCheck cleanly

Tests

Added 21 BATS tests across 4 files:

  • test/list-files.bats — depth limiting, recursion, spaces/special chars, exclude dirs
  • test/git-files.bats — non-git exit, modified/staged/untracked, dedup
  • test/toggle-state.bats — init, toggle, get, cleanup, invalid command
  • test/preview.bats — text files, directories, HOME keyword

jellydn and others added 5 commits August 25, 2025 16:11
Replace process substitution < <(...) with temporary file approach
to resolve "bad substitution: no closing ')'" error when running
cmdk in fish shell. The process substitution syntax is bash-specific
and causes parsing errors in fish.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Restored -s flag for recursive directory listing from PR mieubrisse#17
- Combined upstream changes with fish shell compatibility fix
- Maintained temporary file approach to avoid bash substitution issues
- Preserved proper argument passing for multiple flags

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Temporarily disable 'set -u' around $* expansion to prevent
"unbound variable" error when cmdk is called without arguments.
Re-enable immediately after the command construction.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Fix all unbound variable errors with array access

- Guard array access in cmdk-core.sh to check array length before
iteration
- Fix argument processing in list-files.sh to handle zero arguments
- Make shell scripts executable
- Prevents "unbound variable" errors when arrays are empty or no args
passed

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Added dedicated "Editor Configuration" section with examples
- Included setup instructions for Neovim, Cursor, VS Code
- Added shell-specific configuration examples for Fish/Bash/Zsh
- Removed completed TODO item about customizing file opening

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add -e flag to show gitignored files including .env
- Add Ctrl+T hotkey to toggle visibility during selection
- Create toggle-state.sh and reload-with-toggle.sh for state management
- Update README with usage documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jellydn jellydn changed the title Fix bash substitution error in fish shell Add gitignored file toggle and fix fish shell compatibility Aug 26, 2025
jellydn and others added 3 commits August 26, 2025 18:14
- Change shebang from sh to bash for toggle scripts
- Fix exit code checking in cmdk-core.sh
- Add shellcheck disable comment for intentional word splitting
- Use bash instead of sh for consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
jellydn and others added 3 commits August 26, 2025 18:26
- Add missing shebang line
- Add error handling for cd command
- Disable shellcheck warnings for intentional zsh-specific syntax

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- HOME and .. are no longer shown in subdirectories mode (-s)
- Users get cleaner output focused only on current directory tree
- System mode unchanged, still shows HOME and .. for navigation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Both -o and -s modes now exclude HOME (not relevant for local navigation)
- Both modes keep .. for easy parent directory navigation
- System mode unchanged with both HOME and .. available

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jellydn jellydn marked this pull request as ready for review August 26, 2025 12:45
@jellydn
Copy link
Contributor Author

jellydn commented Aug 26, 2025

Hi @mieubrisse, it's ready for your review. Could you please take a look? Thanks!

@mieubrisse
Copy link
Owner

Hey @jellydn thanks for submitting this! Apologies for the delay (life's been pretty crazy recently); I should be able to get this reviewed tomorrow. Thanks for the patience!

@jellydn
Copy link
Contributor Author

jellydn commented Feb 2, 2026

Hi @mieubrisse Do you have the time to review my PR? I'm thinking to send a new one for select file from git. For example, I want to run git status then pipe to cmdk. Thanks.

@mieubrisse
Copy link
Owner

oops sorry @jellydn for losing this! things got a little crazy here and I dropped the ball here 🤦‍♂️ Want to ping me on Discord so we can iterate quickly on this? I want to understand a little more the intent behind some of these. My username is mieubrisse.!

@jellydn jellydn changed the title Add gitignored file toggle and fix fish shell compatibility Add Git Filter Toggle (Ctrl+G) and Environment File Visibility (Ctrl+T) Feb 5, 2026
jellydn and others added 7 commits February 6, 2026 07:47
- Capture fzf exit code immediately instead of after cleanup
- Replace invalid 'return' with 'exit 1' (script is not sourced)
- Add EXIT trap for guaranteed temp file and toggle state cleanup
- Validate flags (-o/-s/-e only), reject unknown flags
- Check for required tools (fzf, fd, file) at startup

Amp-Thread-ID: https://ampcode.com/threads/T-019c3036-2a8f-75cc-849e-4e12ffd77ea6
Co-authored-by: Amp <amp@ampcode.com>
- Fix shebang to bash (script uses arrays and pipefail)
- Actually pass home_exclude_args to fd when PWD==HOME
- Remove unused script_dirpath and add_back_home_excludes variables

Amp-Thread-ID: https://ampcode.com/threads/T-019c3036-2a8f-75cc-849e-4e12ffd77ea6
Co-authored-by: Amp <amp@ampcode.com>
- Fix shebang to bash (script uses pipefail)
- Fallback bat→cat, ls --color→ls -G on macOS
- Graceful messages for missing tiv/pdftotext/unzip

Amp-Thread-ID: https://ampcode.com/threads/T-019c3036-2a8f-75cc-849e-4e12ffd77ea6
Co-authored-by: Amp <amp@ampcode.com>
- list-files: depth, recursion, spaces, special chars, exclude dirs
- git-files: non-git exit, modified/staged/untracked, dedup
- toggle-state: init, toggle, get, cleanup, invalid command
- preview: text files, directories, HOME keyword

Amp-Thread-ID: https://ampcode.com/threads/T-019c3036-2a8f-75cc-849e-4e12ffd77ea6
Co-authored-by: Amp <amp@ampcode.com>
@jellydn
Copy link
Contributor Author

jellydn commented Feb 6, 2026

Addressed several codebase concerns from the audit:

Bug fixes:

  • cmdk-core.sh: Fixed exit code capturing cleanup status instead of fzf's; replaced invalid return with exit; added trap for guaranteed cleanup
  • list-files.sh: Home directory excludes were computed but never applied to fd; fixed shebang shbash
  • preview.sh: Fixed shebang; added fallbacks for optional tools (batcat, macOS ls, missing tiv/pdftotext/unzip)
  • reload-files.sh: Replaced A && B || C with proper if/then/else

Hardening:

  • Flag validation (-o/-s/-e only) and dependency checks (fzf/fd/file) in cmdk-core.sh
  • All scripts pass ShellCheck cleanly

Testing:

  • Added 21 BATS tests across 4 files (list-files, git-files, toggle-state, preview)

@jellydn jellydn changed the title Add Git Filter Toggle (Ctrl+G) and Environment File Visibility (Ctrl+T) Add toggle features (Ctrl+G/T), fix bugs, add BATS tests Feb 6, 2026
@jellydn
Copy link
Contributor Author

jellydn commented Feb 6, 2026

@mieubrisse I know it's getting bigger on this PR. Let me know your thoughts. Thanks.

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.

2 participants