Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expand shell plugins to all shells except cmd #230

Merged
merged 1 commit into from
Apr 12, 2024
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ If you'd like to automatically start inshellisense when you open your shell, run
```shell
# bash
is init bash >> ~/.bashrc

# zsh
is init zsh >> ~/.zshrc

# fish
is init fish >> ~/.config/fish/config.fish

# pwsh
is init pwsh >> $profile

# powershell
is init powershell >> $profile

# xonsh
is init xonsh >> ~/.xonshrc

# nushell
is init nu >> $nu.env-path
```

### Usage
Expand Down
25 changes: 23 additions & 2 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const supportedShells = [
Shell.Nushell,
].filter((shell) => shell != null) as Shell[];

export const initSupportedShells = [Shell.Bash];
export const initSupportedShells = supportedShells.filter((shell) => shell != Shell.Cmd);

export const userZdotdir = process.env?.ZDOTDIR ?? os.homedir() ?? `~`;
export const zdotdir = path.join(os.tmpdir(), `is-zsh`);
Expand Down Expand Up @@ -124,10 +124,31 @@ export const getShellPromptRewrites = (shell: Shell) => shell == Shell.Nushell;

export const getShellConfig = (shell: Shell): string => {
switch (shell) {
case Shell.Zsh:
case Shell.Bash:
return `if [[ -z "\${ISTERM}" && $- = *i* && $- != *c* ]]; then
is -s bash ; exit
is -s ${shell} ; exit
fi`;
case Shell.Powershell:
case Shell.Pwsh:
return `$__IsCommandFlag = ([Environment]::GetCommandLineArgs() | ForEach-Object { $_.contains("-Command") }) -contains $true
$__IsNoExitFlag = ([Environment]::GetCommandLineArgs() | ForEach-Object { $_.contains("-NoExit") }) -contains $true
$__IsInteractive = -not $__IsCommandFlag -or ($__IsCommandFlag -and $__IsNoExitFlag)
if ([string]::IsNullOrEmpty($env:ISTERM) -and [Environment]::UserInteractive -and $__IsInteractive) {
is -s ${shell}
Stop-Process -Id $pid
}`;
case Shell.Fish:
return `if test -z "$ISTERM" && status --is-interactive
is -s fish ; kill %self
end`;
case Shell.Xonsh:
return `if 'ISTERM' not in \${...} and $XONSH_INTERACTIVE:
is -s xonsh ; exit`;
case Shell.Nushell:
return `if "ISTERM" not-in $env and $nu.is-interactive {
is -s nu ; exit
}`;
}
return "";
};
Loading