mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-15 22:21:20 +00:00
* fix(shell-completion): resolve ENOTDIR error when parent path is a file
Fixes issue where `--shell-completion` fails with ENOTDIR error when
a file exists where a directory should be created (e.g., ~/.zsh exists
as a file instead of a directory).
Changes:
- Added ensureDirectory() helper that safely creates directories
- Validates parent paths are directories, not files
- Provides clear error message when file conflicts occur
- Applied to all shell installers (bash, zsh, fish, powershell)
- Maintains idempotent behavior (safe to call multiple times)
Before: mkdir with recursive:true fails silently with ENOTDIR
After: Clear error message guides user to resolve file conflict
* chore: bump version to 4.1.4
* feat(completion): improve UI/UX with descriptions and grouping
Improves shell completion UI/UX across all shells (bash, zsh, fish,
PowerShell) with better organization and clearer descriptions.
Changes:
- Zsh: Added descriptions for all profiles and grouped by category
- Commands: "auth", "doctor" with descriptions
- Model profiles: glm, glmt, kimi, etc. with descriptions
- Account profiles: Dynamic with "Account-based profile" label
- Used _alternative for visual grouping
- Fish: Added explicit completions with descriptions for known profiles
- Replaced generic profile listing with specific entries
- Each profile now shows clear description (e.g., "GLM-4.6 (cost-optimized)")
- Bash: Added --shell-completion flag and subflags completion
- PowerShell: Added --shell-completion flag and subflags completion
- All shells: Added completion for --shell-completion subflags
Before (zsh):
ccs
auth -- Manage multiple Claude accounts
doctor -- Run health check and diagnostics
default glm glmt kimi max
After (zsh):
commands
auth -- Manage multiple Claude accounts
doctor -- Run health check and diagnostics
model profiles
default -- Default Claude Sonnet 4.5
glm -- GLM-4.6 (cost-optimized)
glmt -- GLM-4.6 with thinking mode
kimi -- Kimi for Coding (long-context)
max -- Claude Opus (maximum capability)
account profiles
work -- Account-based profile
personal -- Account-based profile
Consistent, organized, and informative completion across all shells.
* fix(completion): handle custom profiles and fix zsh syntax errors
Fixes two issues:
1. Zsh syntax errors with _describe -t flag in _alternative
2. Adds general handling for custom settings profiles (e.g., m2)
Changes:
- Zsh: Fixed _alternative syntax (removed -t tag from _describe calls)
- Error was: "_describe:21: bad option: -M"
- Cause: Tag is auto-derived in _alternative, don't specify with -t
- Fish: Added __fish_ccs_get_custom_settings_profiles function
- Dynamically loads non-hardcoded profiles from config.json
- Shows "Settings-based profile" description for custom profiles
- Removed 'max' from hardcoded known profiles
- 'max' is user's account-based profile, not a default setting
Now supports any custom settings profile (e.g., m2.settings.json for
Minimax M2) without hardcoding. Custom profiles show with generic
"Settings-based profile" description.
Installation properly overwrites:
- fs.copyFileSync overwrites completion files by default
- RC files only modified if marker not already present
* fix(zsh): simplify completion to avoid _alternative syntax issues
Replaced _alternative with multiple _describe calls to fix persistent
zsh completion errors.
The _alternative approach was causing:
- '_describe:21: bad option: -M'
- '(eval):1: bad substitution'
- Unwanted variable expansion in completion menu
New approach uses sequential _describe calls which zsh handles correctly.
Simpler, more reliable, and still shows grouped completion with
descriptions.
Before: _alternative with complex nested _describe calls (broken)
After: Three simple _describe calls (works correctly)
* feat(zsh): add colors and improved formatting to completion
Enhances zsh completion UI/UX with colors and better spacing:
Colors:
- Blue: commands (auth, doctor)
- Green: model profiles (default, glm, glmt, kimi, custom)
- Yellow: account profiles
- Gray: descriptions
Formatting:
- Wider separator ( -- ) for better readability
- Group headers in bold cyan
- Menu selection enabled for navigation
- list-rows-first for better column layout
Before:
auth -- Manage multiple Claude accounts
default -- Default Claude Sonnet 4.5
doctor -- Run health check and diagnostics
glm -- GLM-4.6 (cost-optimized)
After:
commands (cyan header)
auth -- Manage multiple Claude accounts (blue)
doctor -- Run health check and diagnostics (blue)
model profiles (cyan header)
default -- Default Claude Sonnet 4.5 (green)
glm -- GLM-4.6 (cost-optimized) (green)
glmt -- GLM-4.6 with thinking mode (green)
kimi -- Kimi for Coding (long-context) (green)
account profiles (cyan header)
max -- Account-based profile (yellow)
Table-like appearance with colors matching --help output style.
* feat(fish): add colors to completion descriptions
Adds color-coded descriptions to Fish completion matching zsh style:
Colors:
- Blue: commands (auth, doctor)
- Green: model profiles (default, glm, glmt, kimi, custom)
- Yellow: account profiles
Fish has excellent native color support via set_color, making this
straightforward to implement.
Before:
auth Manage multiple Claude accounts
default Default Claude Sonnet 4.5
glm GLM-4.6 (cost-optimized)
max Account profile
After:
auth Manage multiple Claude accounts (blue)
default Default Claude Sonnet 4.5 (green)
glm GLM-4.6 (cost-optimized) (green)
max Account profile (yellow)
Consistent color scheme across zsh and fish shells.
* fix(zsh): correct color application for commands vs descriptions
Fixed color codes being applied backwards - commands were gray while
descriptions were colorful.
Issue:
- Used '1;34' format which zsh misinterpreted
- Commands appeared gray (unreadable)
- Descriptions appeared in color
Fix:
- Simplified color codes from '1;34' to '34' (just the color, no style prefix)
- Pattern now: =(#b)(command)(-- description)=34=90
- First group (command): color 34 (blue/green/yellow)
- Second group (description): color 90 (gray)
Before:
auth -- Manage multiple Claude accounts (gray) (blue)
After:
auth -- Manage multiple Claude accounts (blue) (gray)
Commands now properly colored, descriptions muted.
* feat(zsh): improve section header visibility with separators
Makes section headers more distinct and recognizable as dividers:
Before:
commands
auth -- ...
After:
── commands ──
auth -- ...
Changes:
- Added blank line before headers ($'\n')
- Bold yellow with decorative separators (── text ──)
- Clearly distinguishes section headers from actual commands
Now it's obvious that 'commands', 'model profiles', and 'account
profiles' are just section labels, not completable items.
* fix(zsh): use full ANSI color codes to fix reversed colors
The issue was using shorthand color codes (34, 90) instead of full
ANSI format (0;34, 2;37). Zsh was misinterpreting the shorthand,
causing colors to be applied to wrong groups.
Fixed:
- Commands: 0;34 (normal blue) - was appearing gray
- Model profiles: 0;32 (normal green) - was appearing gray
- Account profiles: 0;33 (normal yellow) - was appearing gray
- Descriptions: 2;37 (dim white) - was appearing colorful
Color codes must be escaped as 0\;34 in zsh strings.
Before fix:
auth (gray) -- description (blue)
After fix:
auth (blue) -- description (dim gray)
* fix(zsh): swap color order for completion groups
Zsh may apply colors in reverse order to capture groups on some systems.
Swapped color order: group 2 first, then group 1.
Pattern: (command)(separator + description)
Was: =blue=dim_white (applied as: blue to cmd, dim to desc)
Now: =dim_white=blue (applied as: dim to desc, blue to cmd)
Testing if this resolves the reversed color issue.
* fix(zsh): add empty leading color to fix reversed coloring
ROOT CAUSE: Zsh list-colors apply first color to WHOLE match, then
override with subsequent colors for each group. Without an empty
leading color, the whole match color leaks to groups without overrides.
Pattern behavior:
=(#b)(cmd)(desc)=BLUE=DIM
→ Whole: BLUE, Group1: DIM (override), Group2: BLUE (no override)
→ Result: cmd=dim, desc=BLUE (REVERSED!)
=(#b)(cmd)(desc)==BLUE=DIM
→ Whole: none, Group1: BLUE, Group2: DIM
→ Result: cmd=BLUE, desc=dim (CORRECT!)
The '==' at start means 'no whole-match color', preventing color bleed.
Now commands will be colorful (blue/green/yellow) and descriptions dim.
* refactor(help): remove specific account examples and generalize description
Removed deterministic account examples (work, personal, team) to make
the help text more generic and less prescriptive.
Changes:
- Removed 'ccs work' and 'ccs personal' example lines
- Removed 'Multi-account workflow' examples section
- Updated description from 'multiple Claude accounts (work, personal, team)'
to 'multiple Claude accounts and alternative models'
- Changed to 'Run different Claude CLI sessions concurrently'
- Applied consistently across Node.js (bin/ccs.js), bash (lib/ccs),
and PowerShell (lib/ccs.ps1)
This makes the help text more flexible and doesn't imply specific
use cases or account naming conventions.
* refactor(help): clarify delegation section and remove non-existent command
Updated delegation section in help text across all implementations:
Changes:
- Renamed section from 'Delegation (Token Optimization)' to
'Delegation (inside Claude Code CLI)' to clarify context
- Removed non-existent '/ccs:create m2' command
- Simplified description to focus on cost savings
- Updated command descriptions:
- '/ccs:glm' now 'for simple tasks' (clearer use case)
- '/ccs:kimi' unchanged (already clear)
- Added delegation section to PowerShell help (was missing)
- Consistent messaging across Node.js, bash, and PowerShell
The new section makes it immediately clear that delegation commands
are used within Claude Code CLI sessions, not as standalone commands.
---------
257 lines
6.8 KiB
JavaScript
257 lines
6.8 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const { execSync } = require('child_process');
|
|
|
|
/**
|
|
* Shell Completion Installer
|
|
* Auto-configures shell completion for bash, zsh, fish, PowerShell
|
|
*/
|
|
|
|
class ShellCompletionInstaller {
|
|
constructor() {
|
|
this.homeDir = os.homedir();
|
|
this.ccsDir = path.join(this.homeDir, '.ccs');
|
|
this.completionDir = path.join(this.ccsDir, 'completions');
|
|
this.scriptsDir = path.join(__dirname, '../../scripts/completion');
|
|
}
|
|
|
|
/**
|
|
* Detect current shell
|
|
*/
|
|
detectShell() {
|
|
const shell = process.env.SHELL || '';
|
|
|
|
if (shell.includes('bash')) return 'bash';
|
|
if (shell.includes('zsh')) return 'zsh';
|
|
if (shell.includes('fish')) return 'fish';
|
|
if (process.platform === 'win32') return 'powershell';
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Ensure completion files are in ~/.ccs/completions/
|
|
*/
|
|
ensureCompletionFiles() {
|
|
if (!fs.existsSync(this.completionDir)) {
|
|
fs.mkdirSync(this.completionDir, { recursive: true });
|
|
}
|
|
|
|
// Copy completion scripts
|
|
const files = ['ccs.bash', 'ccs.zsh', 'ccs.fish', 'ccs.ps1'];
|
|
files.forEach(file => {
|
|
const src = path.join(this.scriptsDir, file);
|
|
const dest = path.join(this.completionDir, file);
|
|
|
|
if (fs.existsSync(src)) {
|
|
fs.copyFileSync(src, dest);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Safely create directory, checking for file conflicts
|
|
* @param {string} dirPath - Path to create
|
|
* @throws {Error} If path exists but is a file
|
|
*/
|
|
ensureDirectory(dirPath) {
|
|
if (fs.existsSync(dirPath)) {
|
|
const stat = fs.statSync(dirPath);
|
|
if (!stat.isDirectory()) {
|
|
throw new Error(
|
|
`Cannot create directory: ${dirPath} exists but is a file.\n` +
|
|
`Please remove or rename this file and try again.`
|
|
);
|
|
}
|
|
// Directory exists, nothing to do
|
|
return;
|
|
}
|
|
|
|
// Check parent directories recursively
|
|
const parentDir = path.dirname(dirPath);
|
|
if (parentDir !== dirPath) {
|
|
this.ensureDirectory(parentDir);
|
|
}
|
|
|
|
// Create the directory
|
|
fs.mkdirSync(dirPath);
|
|
}
|
|
|
|
/**
|
|
* Install bash completion
|
|
*/
|
|
installBash() {
|
|
const rcFile = path.join(this.homeDir, '.bashrc');
|
|
const completionPath = path.join(this.completionDir, 'ccs.bash');
|
|
|
|
if (!fs.existsSync(completionPath)) {
|
|
throw new Error('Completion file not found. Please reinstall CCS.');
|
|
}
|
|
|
|
const marker = '# CCS shell completion';
|
|
const sourceCmd = `source "${completionPath}"`;
|
|
const block = `\n${marker}\n${sourceCmd}\n`;
|
|
|
|
// Check if already installed
|
|
if (fs.existsSync(rcFile)) {
|
|
const content = fs.readFileSync(rcFile, 'utf8');
|
|
if (content.includes(marker)) {
|
|
return { success: true, alreadyInstalled: true };
|
|
}
|
|
}
|
|
|
|
// Append to .bashrc
|
|
fs.appendFileSync(rcFile, block);
|
|
|
|
return {
|
|
success: true,
|
|
message: `Added to ${rcFile}`,
|
|
reload: 'source ~/.bashrc'
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Install zsh completion
|
|
*/
|
|
installZsh() {
|
|
const rcFile = path.join(this.homeDir, '.zshrc');
|
|
const completionPath = path.join(this.completionDir, 'ccs.zsh');
|
|
const zshCompDir = path.join(this.homeDir, '.zsh', 'completion');
|
|
|
|
if (!fs.existsSync(completionPath)) {
|
|
throw new Error('Completion file not found. Please reinstall CCS.');
|
|
}
|
|
|
|
// Create zsh completion directory (with file conflict checking)
|
|
this.ensureDirectory(zshCompDir);
|
|
|
|
// Copy to zsh completion directory
|
|
const destFile = path.join(zshCompDir, '_ccs');
|
|
fs.copyFileSync(completionPath, destFile);
|
|
|
|
const marker = '# CCS shell completion';
|
|
const setupCmds = [
|
|
'fpath=(~/.zsh/completion $fpath)',
|
|
'autoload -Uz compinit && compinit'
|
|
];
|
|
const block = `\n${marker}\n${setupCmds.join('\n')}\n`;
|
|
|
|
// Check if already installed
|
|
if (fs.existsSync(rcFile)) {
|
|
const content = fs.readFileSync(rcFile, 'utf8');
|
|
if (content.includes(marker)) {
|
|
return { success: true, alreadyInstalled: true };
|
|
}
|
|
}
|
|
|
|
// Append to .zshrc
|
|
fs.appendFileSync(rcFile, block);
|
|
|
|
return {
|
|
success: true,
|
|
message: `Added to ${rcFile}`,
|
|
reload: 'source ~/.zshrc'
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Install fish completion
|
|
*/
|
|
installFish() {
|
|
const completionPath = path.join(this.completionDir, 'ccs.fish');
|
|
const fishCompDir = path.join(this.homeDir, '.config', 'fish', 'completions');
|
|
|
|
if (!fs.existsSync(completionPath)) {
|
|
throw new Error('Completion file not found. Please reinstall CCS.');
|
|
}
|
|
|
|
// Create fish completion directory (with file conflict checking)
|
|
this.ensureDirectory(fishCompDir);
|
|
|
|
// Copy to fish completion directory (fish auto-loads from here)
|
|
const destFile = path.join(fishCompDir, 'ccs.fish');
|
|
fs.copyFileSync(completionPath, destFile);
|
|
|
|
return {
|
|
success: true,
|
|
message: `Installed to ${destFile}`,
|
|
reload: 'Fish auto-loads completions (no reload needed)'
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Install PowerShell completion
|
|
*/
|
|
installPowerShell() {
|
|
const profilePath = process.env.PROFILE || path.join(
|
|
this.homeDir,
|
|
'Documents',
|
|
'PowerShell',
|
|
'Microsoft.PowerShell_profile.ps1'
|
|
);
|
|
const completionPath = path.join(this.completionDir, 'ccs.ps1');
|
|
|
|
if (!fs.existsSync(completionPath)) {
|
|
throw new Error('Completion file not found. Please reinstall CCS.');
|
|
}
|
|
|
|
const marker = '# CCS shell completion';
|
|
const sourceCmd = `. "${completionPath.replace(/\\/g, '\\\\')}"`;
|
|
const block = `\n${marker}\n${sourceCmd}\n`;
|
|
|
|
// Create profile directory if needed (with file conflict checking)
|
|
const profileDir = path.dirname(profilePath);
|
|
this.ensureDirectory(profileDir);
|
|
|
|
// Check if already installed
|
|
if (fs.existsSync(profilePath)) {
|
|
const content = fs.readFileSync(profilePath, 'utf8');
|
|
if (content.includes(marker)) {
|
|
return { success: true, alreadyInstalled: true };
|
|
}
|
|
}
|
|
|
|
// Append to PowerShell profile
|
|
fs.appendFileSync(profilePath, block);
|
|
|
|
return {
|
|
success: true,
|
|
message: `Added to ${profilePath}`,
|
|
reload: '. $PROFILE'
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Install for detected or specified shell
|
|
*/
|
|
install(shell = null) {
|
|
const targetShell = shell || this.detectShell();
|
|
|
|
if (!targetShell) {
|
|
throw new Error('Could not detect shell. Please specify: --bash, --zsh, --fish, or --powershell');
|
|
}
|
|
|
|
// Ensure completion files exist
|
|
this.ensureCompletionFiles();
|
|
|
|
// Install for target shell
|
|
switch (targetShell) {
|
|
case 'bash':
|
|
return this.installBash();
|
|
case 'zsh':
|
|
return this.installZsh();
|
|
case 'fish':
|
|
return this.installFish();
|
|
case 'powershell':
|
|
return this.installPowerShell();
|
|
default:
|
|
throw new Error(`Unsupported shell: ${targetShell}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = { ShellCompletionInstaller };
|