diff --git a/scripts/completion/README.md b/scripts/completion/README.md index 037ebe83..4eb306d2 100644 --- a/scripts/completion/README.md +++ b/scripts/completion/README.md @@ -137,7 +137,7 @@ $ ccs auth show work personal team --json $ ccs api -create discover copy export import remove +create list discover copy export import remove ``` ### Backend Contract diff --git a/scripts/completion/ccs.fish b/scripts/completion/ccs.fish index e033b08a..96d801bf 100644 --- a/scripts/completion/ccs.fish +++ b/scripts/completion/ccs.fish @@ -7,6 +7,9 @@ function __fish_ccs_complete end set -l current (commandline -ct) + if test -n "$current"; and test (count $tokens_before_current) -gt 0; and test "$tokens_before_current[-1]" = "$current" + set -e tokens_before_current[-1] + end set -l script_file (status filename) set -l repo_root (realpath (dirname $script_file)/../.. 2>/dev/null) diff --git a/tests/unit/commands/shell-completion-command.test.ts b/tests/unit/commands/shell-completion-command.test.ts index 4c2d71ab..c8a285d9 100644 --- a/tests/unit/commands/shell-completion-command.test.ts +++ b/tests/unit/commands/shell-completion-command.test.ts @@ -1,3 +1,6 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + import { describe, it, expect, beforeAll, beforeEach, afterEach, mock } from 'bun:test'; type ShellTarget = 'bash' | 'zsh' | 'fish' | 'powershell' | null; @@ -139,4 +142,15 @@ describe('shell-completion command', () => { true ); }); + + it('fish completion strips a duplicated partial token before delegating to __complete', () => { + const fishScript = readFileSync( + join(import.meta.dir, '../../../scripts/completion/ccs.fish'), + 'utf8' + ); + + expect(fishScript).toContain('set -l current (commandline -ct)'); + expect(fishScript).toContain('test "$tokens_before_current[-1]" = "$current"'); + expect(fishScript).toContain('set -e tokens_before_current[-1]'); + }); });