MCPcopy Create free account
hub / github.com/Snapchat/Valdi / checkShellAutoComplete

Method checkShellAutoComplete

npm_modules/cli/src/commands/doctor.ts:930–1010  ·  view source on GitHub ↗

* Validates shell autocomplete configuration. * * Checks if shell autocomplete (compinit/bashcompinit) is configured. * dev_setup adds these to shell RC files for better CLI experience. * * @private

()

Source from the content-addressed store, hash-verified

928
929 // Determine shell and required configuration
930 if (shell.endsWith('/zsh')) {
931 rcFile = path.join(homeDir, '.zshrc');
932 requiredLines = ['autoload -U compinit && compinit', 'autoload -U bashcompinit && bashcompinit'];
933 } else if (shell.endsWith('/bash')) {
934 rcFile = path.join(homeDir, '.bashrc');
935 // Bash typically auto-loads completion, so we're more lenient
936 requiredLines = [];
937 } else {
938 // Unknown shell, skip check
939 return;
940 }
941
942 if (!rcFile || !fs.existsSync(rcFile)) {
943 this.addResult({
944 name: 'Shell autocomplete',
945 status: 'warn',
946 message: `Shell configuration file not found (${rcFile || 'unknown'})`,
947 details: 'Shell autocomplete improves CLI experience',
948 category: 'Development tools',
949 });
950 return;
951 }
952
953 // For bash, we just report success since it typically handles completion automatically
954 if (requiredLines.length === 0) {
955 this.addResult({
956 name: 'Shell autocomplete',
957 status: 'pass',
958 message: 'Shell autocomplete configured (bash)',
959 category: 'Development tools',
960 });
961 return;
962 }
963
964 // Read RC file and check for required lines
965 try {
966 const rcContent = fs.readFileSync(rcFile, 'utf8');
967 const rcLines = rcContent.split('\n');
968
969 const missingLines: string[] = [];
970 for (const required of requiredLines) {
971 if (!rcLines.includes(required)) {
972 missingLines.push(required);
973 }
974 }
975
976 if (missingLines.length === 0) {
977 this.addResult({
978 name: 'Shell autocomplete',
979 status: 'pass',
980 message: 'Shell autocomplete configured',
981 category: 'Development tools',
982 });
983 } else {
984 this.addResult({
985 name: 'Shell autocomplete',
986 status: 'warn',
987 message: 'Shell autocomplete not fully configured',

Callers 1

runDiagnosticsMethod · 0.95

Calls 5

addResultMethod · 0.95
readFileSyncMethod · 0.80
splitMethod · 0.80
joinMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected