Skip to content

Conversation

seefood
Copy link
Contributor

@seefood seefood commented Oct 7, 2025

Summary

Implements tab completion for Laravel's artisan command-line tool, addressing issue #2248.

Features

  • Dynamic Command Completion: Automatically retrieves available commands from php artisan list
  • Alias Support: Works with both artisan and the common art alias
  • Smart Activation: Only activates when an artisan file exists in the current directory
  • Robust Implementation: Uses command prefix to bypass user aliases, ensuring reliability
  • Clean Code: Passes all shellcheck and shfmt linting requirements

Implementation Details

The completion function:

  1. Checks for the presence of an artisan file in the current directory
  2. Dynamically fetches available commands using php artisan --raw --no-ansi list
  3. Provides completions via bash's compgen builtin
  4. Gracefully handles missing artisan file or PHP errors

Usage

After enabling the completion:

bash-it enable completion artisan

Users can tab-complete artisan commands:

php artisan make:<TAB>
# Shows: make:cast make:channel make:command make:controller ...

php artisan migr<TAB>
# Completes to: php artisan migrate

Testing

  • ✅ Sourced successfully in bash-it environment
  • ✅ Function properly defined with expected behavior
  • ✅ Passes shellcheck with no warnings
  • ✅ Passes shfmt formatting checks
  • ✅ Passes all pre-commit hooks

Related

Closes #2248

Test Plan

To test this completion:

  1. Navigate to a Laravel project directory
  2. Enable the completion: bash-it enable completion artisan
  3. Reload your shell or source bash-it
  4. Try tab completion: php artisan make:<TAB> or artisan migr<TAB>
  5. Verify completions appear for valid artisan commands

🤖 Generated with Claude Code

Implements tab completion for Laravel's artisan command-line tool.

**Features:**
- Dynamic command completion from `php artisan list`
- Works with both `artisan` and `art` aliases
- Only activates when artisan file exists in current directory
- Uses `command` prefix to bypass user aliases for robustness
- Follows bash-it completion conventions

**Implementation:**
- Parses `php artisan --raw --no-ansi list` output
- Provides completions via bash's `compgen` builtin
- Gracefully handles missing artisan file or PHP errors
- Passes shellcheck and shfmt linting

**Use Case:**
Developers working with Laravel projects can now tab-complete artisan
commands like `make:controller`, `migrate`, `tinker`, etc., improving
productivity and reducing typos.

Closes Bash-it#2248

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

Co-Authored-By: Claude <[email protected]>
seefood added a commit that referenced this pull request Oct 7, 2025
Updated all three planning documents to reflect the completed work:

**Issues Fixed (6 total)**:
- #2317: Auto-detect git remote (PR #2345)
- #2248: Laravel artisan completion (PR #2349)
- #2296: down4me URL malformation (PR #2350)
- #2260: SSH completion @ sign (PR #2351)
- #2238: Uninstall script backup (PR #2352)
- #2216: Node version conditional display (PR #2353)

**Changes to docs/plans/**:
1. bash-it-issues-comprehensive-analysis.md
   - Marked 5 quick wins as FIXED with PR numbers
   - Updated executive summary: 32 → 27 open issues
   - Updated work plan to show Phase 1 completed
   - Updated issue reference appendix

2. bash-it-quick-reference.md
   - Moved completed issues to "Fixed" section
   - Updated TL;DR metrics
   - Removed completed items from decision list
   - Updated metrics table with current progress

3. bash-it-roadmap-2025.md
   - Updated health metrics (32 → 27 issues)
   - Marked Phase 1 as COMPLETED
   - Listed all 6 PRs with dates
   - Updated success criteria checkmarks

**Remaining Work**:
- 1 quick fix (#2314 - todo alias rename)
- 18 stale issues to close
- 4 strategic decisions needed

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

Co-Authored-By: Claude <[email protected]>
seefood and others added 2 commits October 7, 2025 16:05
Applied 3 of 4 review suggestions from @akinomyoga:

1. Fixed comment - only checks current directory, not parent directories
2. Removed unnecessary /g flag from sed substitution
3. Combined two complete commands into one line

Note on compgen -W quoting: Kept double quotes as single quotes would
prevent variable expansion. The SC2034 warning is a false positive since
commands is used in compgen. Artisan commands are safe (no special chars).

Co-Authored-By: akinomyoga <[email protected]>

# Get list of available artisan commands
# Use command prefix to bypass user aliases
commands=$(command php artisan --raw --no-ansi list 2> /dev/null | command sed "s/[[:space:]].*//")

Check warning

Code scanning / shellcheck

SC2034 Warning

commands appears unused. Verify use (or export if used externally).
commands=$(command php artisan --raw --no-ansi list 2> /dev/null | command sed "s/[[:space:]].*//")

# shellcheck disable=SC2034,SC2207
COMPREPLY=($(compgen -W '${commands}' -- "${cur}"))

Check warning

Code scanning / shellcheck

SC2016 Warning

Expressions don't expand in single quotes, use double quotes for that.
# Use command prefix to bypass user aliases
commands=$(command php artisan --raw --no-ansi list 2> /dev/null | command sed "s/[[:space:]].*//")

# shellcheck disable=SC2034,SC2207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# shellcheck disable=SC2034,SC2207
# shellcheck disable=SC2016,SC2207

fi

# Get list of available artisan commands
# Use command prefix to bypass user aliases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Use command prefix to bypass user aliases
# Use command prefix to bypass user aliases
# shellcheck disable=SC2034

@seefood seefood merged commit 2d56bfe into Bash-it:master Oct 8, 2025
4 of 6 checks passed
@seefood seefood deleted the feature/artisan-completion branch October 12, 2025 12:43
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.

[Feature]: Artisan (Laravel) completion

2 participants