Skip to content

Commit

Permalink
chore: get setup env var from base class
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 committed Jan 30, 2024
1 parent 89895ff commit 9567ccd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export abstract class AutocompleteBase extends Command {
}
}

public getSetupEnvVar(shell: string): string {
return `${this.cliBinEnvVar}_AC_${shell.toUpperCase()}_SETUP_PATH`
}

writeLogFile(msg: string) {
mkdirSync(this.config.cacheDir, {recursive: true})
const entry = `[${new Date().toISOString()}] ${msg}\n`
Expand Down
2 changes: 1 addition & 1 deletion src/commands/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class Index extends AutocompleteBase {
}

private printShellInstructions(shell: string): void {
const setupEnvVar = `${this.cliBinEnvVar}_AC_${shell.toUpperCase()}_SETUP_PATH`
const setupEnvVar = this.getSetupEnvVar(shell)
const tabStr = shell === 'bash' ? '<TAB><TAB>' : '<TAB>'
const scriptCommand = `${this.config.bin} autocomplete${this.config.topicSeparator}script ${shell}`

Expand Down
8 changes: 2 additions & 6 deletions src/commands/autocomplete/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export default class Script extends AutocompleteBase {
const {args} = await this.parse(Script)
const shell = args.shell ?? this.config.shell

const binUpcase = this.cliBinEnvVar
const shellUpcase = shell.toUpperCase()
if (shell === 'powershell') {
const completionFuncPath = path.join(
this.config.cacheDir,
Expand All @@ -33,12 +31,10 @@ export default class Script extends AutocompleteBase {
this.log(`. ${completionFuncPath}`)
} else {
this.log(
`${this.prefix}${binUpcase}_AC_${shellUpcase}_SETUP_PATH=${path.join(
`${this.prefix}${this.getSetupEnvVar(shell)}=${path.join(
this.autocompleteCacheDir,
`${shell}_setup`,
)} && test -f $${binUpcase}_AC_${shellUpcase}_SETUP_PATH && source $${binUpcase}_AC_${shellUpcase}_SETUP_PATH;${
this.suffix
}`,
)} && test -f $${this.getSetupEnvVar(shell)} && source $${this.getSetupEnvVar(shell)};${this.suffix}`,
)
}
}
Expand Down

0 comments on commit 9567ccd

Please sign in to comment.