Skip to content

Commit 7d3c710

Browse files
committed
Fix -C suggestion.
1 parent 29cd56d commit 7d3c710

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

crates/rb-cli/src/commands/shell_integration.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ _rb_completion() {{
6868
# Call rb to get context-aware completions
6969
local completions
7070
completions=$(rb __bash_complete "${{COMP_LINE}}" "${{COMP_POINT}}" 2>/dev/null)
71-
71+
7272
if [ -n "$completions" ]; then
73+
# Only use nospace when actively navigating through a directory path
74+
# (i.e., when current word ends with /)
75+
if [[ "$cur" =~ /$ ]]; then
76+
compopt -o nospace
77+
fi
78+
7379
COMPREPLY=($(compgen -W "$completions" -- "$cur"))
74-
# Bash will automatically add space for single completion
7580
else
7681
# No rb completions, fall back to default bash completion (files/dirs)
7782
compopt -o default
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# ShellSpec tests for directory completion nospace behavior
3+
# Tests that bash completion for directories behaves correctly with trailing slashes
4+
5+
Describe "Ruby Butler Directory Completion Nospace"
6+
Include spec/support/helpers.sh
7+
8+
Describe "bash completion script behavior"
9+
It "should add space after completing a partial directory name (allows next argument)"
10+
# When completing "rb -C sp<TAB>" -> "rb -C spec/ "
11+
# Bash SHOULD add a space because user might want to continue with next arg
12+
# The completion function detects $cur doesn't end with / yet
13+
14+
Skip "Manual test: source completion, type 'rb -C sp' then TAB"
15+
16+
# Expected: "rb -C spec/ " (with space)
17+
# This allows: "rb -C spec/ run" or other commands
18+
End
19+
20+
It "should NOT add space when navigating within directory path (allows subdirectory completion)"
21+
# When completing "rb -C spec/<TAB>" -> suggests subdirs
22+
# Bash should NOT add space because $cur ends with /
23+
# This allows continued navigation: "rb -C spec/commands/<TAB>"
24+
25+
Skip "Manual test: source completion, type 'rb -C spec/' then TAB"
26+
27+
# Expected: suggests "spec/behaviour/", "spec/commands/", "spec/support/"
28+
# Then "rb -C spec/commands/" (no space) allows further TAB completion
29+
End
30+
End
31+
32+
Describe "completion output correctness"
33+
It "outputs directory names with trailing slash"
34+
When run rb __bash_complete "rb -C sp" 9
35+
The output should include "spec/"
36+
End
37+
38+
It "outputs subdirectories with full path and trailing slash"
39+
When run rb __bash_complete "rb -C spec/" 13
40+
The output should include "spec/behaviour/"
41+
The output should include "spec/commands/"
42+
The output should include "spec/support/"
43+
End
44+
End
45+
End

spec/commands/completion/path_completion_spec.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
# ShellSpec tests for path-based completion
33
# Tests directory and file completion for path-based flags
4+
#
5+
# Note: These tests verify the completion OUTPUT (what rb __bash_complete returns).
6+
# The bash completion function behavior (adding/not adding space) is controlled by
7+
# the generated bash script which uses compopt -o nospace when $cur ends with /
48

59
Describe "Ruby Butler Path Completion"
610
Include spec/support/helpers.sh
@@ -29,6 +33,20 @@ Describe "Ruby Butler Path Completion"
2933
The status should equal 0
3034
The first line of output should not equal "runtime"
3135
End
36+
37+
It "completes partial directory path and suggests subdirectories"
38+
When run rb __bash_complete "rb -C sp" 9
39+
The status should equal 0
40+
The output should include "spec/"
41+
End
42+
43+
It "suggests subdirectories after completing a directory"
44+
When run rb __bash_complete "rb -C spec/" 13
45+
The status should equal 0
46+
The output should include "spec/behaviour/"
47+
The output should include "spec/commands/"
48+
The output should include "spec/support/"
49+
End
3250
End
3351

3452
Context "-G flag (gem-home) completion"

0 commit comments

Comments
 (0)