generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61c4b00
commit 2c26c41
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as path from 'path'; | ||
import { writeFile } from 'fs/promises'; | ||
import { exec } from 'shelljs'; | ||
import { AsyncCreatable } from '@salesforce/kit'; | ||
import { ConfigFile } from './configFile'; | ||
|
||
const AUTO_COMPLETE_TEMPLATE = ` | ||
#/usr/bin/env bash | ||
_repo_completions() | ||
{ | ||
local cur | ||
COMPREPLY=() | ||
cur=\${COMP_WORDS[COMP_CWORD]} | ||
code_dir=@CODE_DIRECTORY@ | ||
COMPREPLY=($( compgen -W "$(ls -d $code_dir/*/ | cut -d "/" -f 5)" -- $cur ) ) | ||
} | ||
complete -F _repo_completions mpm view | ||
complete -F _repo_completions mpm open | ||
`; | ||
|
||
export class AutoComplete extends AsyncCreatable<string> { | ||
public static LOCATION = path.join(ConfigFile.MPM_DIR, 'autocomplete.bash'); | ||
public constructor(private directory: string) { | ||
super(directory); | ||
} | ||
|
||
protected async init(): Promise<void> { | ||
if (process.platform === 'win32') return; | ||
|
||
const contents = AUTO_COMPLETE_TEMPLATE.replace('@CODE_DIRECTORY@', this.directory); | ||
await writeFile(AutoComplete.LOCATION, contents); | ||
exec(`source ${AutoComplete.LOCATION}`, { silent: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters