Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ more control over exactly where this configuration lives, you can manually set i
shell run at startup:

```bash
source <(ng completion script)
if [[ $- == *i* ]]; then
source <(ng completion script)
fi
Comment thread
clydin marked this conversation as resolved.
```

This is equivalent to what `ng completion` will automatically set up, and gives power users more
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/utilities/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export async function initializeAutocomplete(): Promise<string> {
try {
await fs.appendFile(
rcFile,
'\n\n# Load Angular CLI autocompletion.\nsource <(ng completion script)\n',
'\n\n# Load Angular CLI autocompletion for interactive shells.\nif [[ $- == *i* ]]; then\n source <(ng completion script)\nfi\n',
);
} catch (err) {
assertIsError(err);
Expand Down
67 changes: 17 additions & 50 deletions tests/e2e/tests/commands/completion/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import {

const testRegistry = getGlobalVariable('package-registry');

const AUTOCOMPLETION_SNIPPET = `
# Load Angular CLI autocompletion for interactive shells.
if [[ $- == *i* ]]; then
source <(ng completion script)
fi
`.trim();
Comment thread
clydin marked this conversation as resolved.

export default async function () {
// Windows Cmd and Powershell do not support autocompletion. Run a different set of tests to
// confirm autocompletion fails gracefully.
Expand All @@ -33,11 +40,7 @@ export default async function () {
);

const rcContents = await fs.readFile(path.join(home, '.bashrc'), 'utf-8');
const expected = `
# Load Angular CLI autocompletion.
source <(ng completion script)
`.trim();
if (!rcContents.includes(expected)) {
if (!rcContents.includes(AUTOCOMPLETION_SNIPPET)) {
throw new Error(`~/.bashrc does not contain autocompletion script. Contents:\n${rcContents}`);
}
});
Expand All @@ -55,11 +58,7 @@ source <(ng completion script)
);

const rcContents = await fs.readFile(path.join(home, '.zshrc'), 'utf-8');
const expected = `
# Load Angular CLI autocompletion.
source <(ng completion script)
`.trim();
if (!rcContents.includes(expected)) {
if (!rcContents.includes(AUTOCOMPLETION_SNIPPET)) {
throw new Error(`~/.zshrc does not contain autocompletion script. Contents:\n${rcContents}`);
}
});
Expand All @@ -79,11 +78,7 @@ source <(ng completion script)
);

const rcContents = await fs.readFile(bashrc, 'utf-8');
const expected = `# Other commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const expected = `# Other commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (rcContents !== expected) {
throw new Error(`~/.bashrc does not match expectation. Contents:\n${rcContents}`);
}
Expand All @@ -104,11 +99,7 @@ source <(ng completion script)
);

const rcContents = await fs.readFile(bashProfile, 'utf-8');
const expected = `# Other commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const expected = `# Other commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (rcContents !== expected) {
throw new Error(`~/.bash_profile does not match expectation. Contents:\n${rcContents}`);
}
Expand All @@ -129,11 +120,7 @@ source <(ng completion script)
);

const rcContents = await fs.readFile(profile, 'utf-8');
const expected = `# Other commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const expected = `# Other commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (rcContents !== expected) {
throw new Error(`~/.profile does not match expectation. Contents:\n${rcContents}`);
}
Expand All @@ -159,11 +146,7 @@ source <(ng completion script)
);

const bashrcContents = await fs.readFile(bashrc, 'utf-8');
const bashrcExpected = `# \`.bashrc\` commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const bashrcExpected = `# \`.bashrc\` commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (bashrcContents !== bashrcExpected) {
throw new Error(`~/.bashrc does not match expectation. Contents:\n${bashrcContents}`);
}
Expand Down Expand Up @@ -194,11 +177,7 @@ source <(ng completion script)
);

const rcContents = await fs.readFile(zshrc, 'utf-8');
const expected = `# Other commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const expected = `# Other commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (rcContents !== expected) {
throw new Error(`~/.zshrc does not match expectation. Contents:\n${rcContents}`);
}
Expand All @@ -219,11 +198,7 @@ source <(ng completion script)
);

const rcContents = await fs.readFile(zshProfile, 'utf-8');
const expected = `# Other commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const expected = `# Other commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (rcContents !== expected) {
throw new Error(`~/.zsh_profile does not match expectation. Contents:\n${rcContents}`);
}
Expand All @@ -244,11 +219,7 @@ source <(ng completion script)
);

const rcContents = await fs.readFile(profile, 'utf-8');
const expected = `# Other commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const expected = `# Other commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (rcContents !== expected) {
throw new Error(`~/.profile does not match expectation. Contents:\n${rcContents}`);
}
Expand All @@ -274,11 +245,7 @@ source <(ng completion script)
);

const zshrcContents = await fs.readFile(zshrc, 'utf-8');
const zshrcExpected = `# \`.zshrc\` commands...

# Load Angular CLI autocompletion.
source <(ng completion script)
`;
const zshrcExpected = `# \`.zshrc\` commands...\n\n${AUTOCOMPLETION_SNIPPET}\n`;
if (zshrcContents !== zshrcExpected) {
throw new Error(`~/.zshrc does not match expectation. Contents:\n${zshrcContents}`);
}
Expand Down
Loading