mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 08:19:59 +00:00
fix: avoid relative completion backend execution
This commit is contained in:
committed by
Tam Nhu Tran
parent
62a4d44b58
commit
4f2dd70b8c
@@ -22,18 +22,6 @@ __ccs_completion_run() {
|
|||||||
local current="$1"
|
local current="$1"
|
||||||
shift || true
|
shift || true
|
||||||
|
|
||||||
local script_dir repo_root repo_cli
|
|
||||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
repo_root="$(cd "${script_dir}/../.." && pwd)"
|
|
||||||
repo_cli="${repo_root}/dist/ccs.js"
|
|
||||||
if [[ ! -f "${repo_cli}" ]]; then
|
|
||||||
repo_cli="${repo_root}/bin/ccs.js"
|
|
||||||
fi
|
|
||||||
if [[ -f "${repo_cli}" ]]; then
|
|
||||||
node "${repo_cli}" __complete --shell bash --current "${current}" -- "$@" 2>/dev/null
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if command -v ccs >/dev/null 2>&1; then
|
if command -v ccs >/dev/null 2>&1; then
|
||||||
ccs __complete --shell bash --current "${current}" -- "$@" 2>/dev/null
|
ccs __complete --shell bash --current "${current}" -- "$@" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -11,17 +11,6 @@ function __fish_ccs_complete
|
|||||||
set -e tokens_before_current[-1]
|
set -e tokens_before_current[-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
set -l script_file (status filename)
|
|
||||||
set -l repo_root (realpath (dirname $script_file)/../.. 2>/dev/null)
|
|
||||||
set -l repo_cli "$repo_root/dist/ccs.js"
|
|
||||||
if not test -f "$repo_cli"
|
|
||||||
set repo_cli "$repo_root/bin/ccs.js"
|
|
||||||
end
|
|
||||||
if test -f "$repo_cli"
|
|
||||||
node "$repo_cli" __complete --shell fish --current "$current" -- $tokens_before_current 2>/dev/null
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if command -sq ccs
|
if command -sq ccs
|
||||||
ccs __complete --shell fish --current "$current" -- $tokens_before_current 2>/dev/null
|
ccs __complete --shell fish --current "$current" -- $tokens_before_current 2>/dev/null
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,16 +6,6 @@ function Invoke-CcsCompletionBackend {
|
|||||||
[string[]]$TokensBeforeCurrent
|
[string[]]$TokensBeforeCurrent
|
||||||
)
|
)
|
||||||
|
|
||||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
|
|
||||||
$repoCli = Join-Path $repoRoot 'dist\ccs.js'
|
|
||||||
if (-not (Test-Path $repoCli)) {
|
|
||||||
$repoCli = Join-Path $repoRoot 'bin\ccs.js'
|
|
||||||
}
|
|
||||||
if (Test-Path $repoCli) {
|
|
||||||
& node $repoCli __complete --shell powershell --current $CurrentWord -- @TokensBeforeCurrent 2>$null
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Get-Command ccs -ErrorAction SilentlyContinue) {
|
if (Get-Command ccs -ErrorAction SilentlyContinue) {
|
||||||
& ccs __complete --shell powershell --current $CurrentWord -- @TokensBeforeCurrent 2>$null
|
& ccs __complete --shell powershell --current $CurrentWord -- @TokensBeforeCurrent 2>$null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,19 +22,6 @@ __ccs_completion_run() {
|
|||||||
local current="$1"
|
local current="$1"
|
||||||
shift || true
|
shift || true
|
||||||
|
|
||||||
local script_path script_dir repo_root repo_cli
|
|
||||||
script_path="${(%):-%N}"
|
|
||||||
script_dir="${script_path:A:h}"
|
|
||||||
repo_root="${script_dir:h:h}"
|
|
||||||
repo_cli="${repo_root}/dist/ccs.js"
|
|
||||||
if [[ ! -f "${repo_cli}" ]]; then
|
|
||||||
repo_cli="${repo_root}/bin/ccs.js"
|
|
||||||
fi
|
|
||||||
if [[ -f "${repo_cli}" ]]; then
|
|
||||||
node "${repo_cli}" __complete --shell zsh --current "${current}" -- "$@" 2>/dev/null
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( $+commands[ccs] )); then
|
if (( $+commands[ccs] )); then
|
||||||
ccs __complete --shell zsh --current "${current}" -- "$@" 2>/dev/null
|
ccs __complete --shell zsh --current "${current}" -- "$@" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -143,6 +143,27 @@ describe('shell-completion command', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('completion adapters only delegate to the ccs command on PATH', () => {
|
||||||
|
const completionScripts = [
|
||||||
|
'../../../scripts/completion/ccs.bash',
|
||||||
|
'../../../scripts/completion/ccs.zsh',
|
||||||
|
'../../../scripts/completion/ccs.fish',
|
||||||
|
'../../../scripts/completion/ccs.ps1',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const scriptPath of completionScripts) {
|
||||||
|
const script = readFileSync(join(import.meta.dir, scriptPath), 'utf8');
|
||||||
|
|
||||||
|
expect(script).not.toContain('../..');
|
||||||
|
expect(script).not.toContain('repo_root');
|
||||||
|
expect(script).not.toContain('repoRoot');
|
||||||
|
expect(script).not.toContain('repo_cli');
|
||||||
|
expect(script).not.toContain('repoCli');
|
||||||
|
expect(script).not.toContain('node ');
|
||||||
|
expect(script).not.toContain('& node');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('fish completion strips a duplicated partial token before delegating to __complete', () => {
|
it('fish completion strips a duplicated partial token before delegating to __complete', () => {
|
||||||
const fishScript = readFileSync(
|
const fishScript = readFileSync(
|
||||||
join(import.meta.dir, '../../../scripts/completion/ccs.fish'),
|
join(import.meta.dir, '../../../scripts/completion/ccs.fish'),
|
||||||
|
|||||||
Reference in New Issue
Block a user