Skip to content

Commit

Permalink
feat: support fish on windows (#247)
Browse files Browse the repository at this point in the history
* feat: support fish on windows

Signed-off-by: Chapman Pendery <[email protected]>

* fix: clear detection for windows fish

Signed-off-by: Chapman Pendery <[email protected]>

* ci: remove macos chmods

Signed-off-by: Chapman Pendery <[email protected]>

---------

Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery committed Apr 25, 2024
1 parent a7219b1 commit 25ce5ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ jobs:
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
echo "source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh" > ~/.zshrc
sudo chmod g-w /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/share/zsh
- name: setup linux shells
if: matrix.os == 'ubuntu-latest'
shell: bash
Expand Down
21 changes: 20 additions & 1 deletion src/isterm/commandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class CommandManager {
#activeCommand: TerminalCommand;
#terminal: Terminal;
#previousCommandLines: Set<number>;
#maxCursorY: number;
#shell: Shell;
#promptRewrites: boolean;
readonly #supportsProperOscPlacements = os.platform() !== "win32";
Expand All @@ -37,6 +38,7 @@ export class CommandManager {
this.#terminal = terminal;
this.#shell = shell;
this.#activeCommand = {};
this.#maxCursorY = 0;
this.#previousCommandLines = new Set();
this.#promptRewrites = getShellPromptRewrites(shell);

Expand Down Expand Up @@ -68,6 +70,7 @@ export class CommandManager {

handleClear() {
this.handlePromptStart();
this.#maxCursorY = 0;
this.#previousCommandLines = new Set();
}

Expand Down Expand Up @@ -108,6 +111,21 @@ export class CommandManager {
}
}

if (this.#shell == Shell.Fish) {
if (inshellisenseConfig?.prompt?.fish != null) {
const extractedPrompt = this._extractPrompt(lineText, inshellisenseConfig.prompt.fish);
if (extractedPrompt) return extractedPrompt;
}

const fishPrompt = lineText.match(/(?<prompt>.*>\s?)/)?.groups?.prompt;
if (fishPrompt) {
const adjustedPrompt = this._adjustPrompt(fishPrompt, lineText, ">");
if (adjustedPrompt) {
return adjustedPrompt;
}
}
}

if (this.#shell == Shell.Nushell) {
if (inshellisenseConfig?.prompt?.nu != null) {
const extractedPrompt = this._extractPrompt(lineText, inshellisenseConfig.prompt.nu);
Expand Down Expand Up @@ -232,8 +250,9 @@ export class CommandManager {

const globalCursorPosition = this.#terminal.buffer.active.baseY + this.#terminal.buffer.active.cursorY;
const withinPollDistance = globalCursorPosition < this.#activeCommand.promptEndMarker.line + 5;
this.#maxCursorY = Math.max(this.#maxCursorY, globalCursorPosition);

if (globalCursorPosition < this.#activeCommand.promptStartMarker.line) {
if (globalCursorPosition < this.#activeCommand.promptStartMarker.line || globalCursorPosition < this.#maxCursorY) {
this.handleClear();
this.#activeCommand.promptEndMarker = this.#terminal.registerMarker(0);
return;
Expand Down
5 changes: 4 additions & 1 deletion src/isterm/pty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ const convertToPtyTarget = async (shell: Shell, underTest: boolean, login: boole
shellArgs = ["-noexit", "-command", `try { . "${path.join(shellFolderPath, "shellIntegration.ps1")}" } catch {}`];
break;
case Shell.Fish:
shellArgs = ["--init-command", `. ${path.join(shellFolderPath, "shellIntegration.fish").replace(/(\s+)/g, "\\$1")}`];
shellArgs =
platform == "win32"
? ["--init-command", `. "$(cygpath -u '${path.join(shellFolderPath, "shellIntegration.fish")}')"`]
: ["--init-command", `. ${path.join(shellFolderPath, "shellIntegration.fish").replace(/(\s+)/g, "\\$1")}`];
break;
case Shell.Xonsh: {
const sharedConfig = os.platform() == "win32" ? path.join("C:\\ProgramData", "xonsh", "xonshrc") : path.join("etc", "xonsh", "xonshrc");
Expand Down
3 changes: 3 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Config = {
xonsh?: PromptPattern[];
nu?: PromptPattern[];
powershell?: PromptPattern[];
fish?: PromptPattern[];
};
specs?: {
path?: string[];
Expand Down Expand Up @@ -95,6 +96,7 @@ const configSchema = {
powershell: promptPatternsSchema,
xonsh: promptPatternsSchema,
nu: promptPatternsSchema,
fish: promptPatternsSchema,
},
},
specs: {
Expand Down Expand Up @@ -153,6 +155,7 @@ export const loadConfig = async (program: Command) => {
xonsh: config.prompt?.xonsh ?? globalConfig?.prompt?.xonsh,
pwsh: config.prompt?.pwsh ?? globalConfig?.prompt?.pwsh,
nu: config.prompt?.nu ?? globalConfig?.prompt?.nu,
fish: config.prompt?.fish ?? globalConfig?.prompt?.fish,
},
specs: {
path: [...(config?.specs?.path ?? []), ...(config?.specs?.path ?? [])],
Expand Down

0 comments on commit 25ce5ca

Please sign in to comment.