Skip to content

Commit

Permalink
fix: xonsh should be expected on path, don't search python modules (#215
Browse files Browse the repository at this point in the history
)

* fix: xonsh should be expected on path, don't search python modules

Signed-off-by: Chapman Pendery <cpendery@vt.edu>

* fix: xonsh prompt when not under test

Signed-off-by: Chapman Pendery <cpendery@vt.edu>

---------

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
  • Loading branch information
cpendery authored Mar 22, 2024
1 parent 710f256 commit 405385c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
python -m pip install 'xonsh[full]'
pipx install 'xonsh[full]'
- run: npm test

Expand Down
32 changes: 10 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shell/shellIntegration.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __is_update_cwd() -> str:
$PROMPT_FIELDS['__is_prompt_start'] = __is_prompt_start
$PROMPT_FIELDS['__is_prompt_end'] = __is_prompt_end
$PROMPT_FIELDS['__is_update_cwd'] = __is_update_cwd
if $ISTERM_TESTING:
if 'ISTERM_TESTING' in ${...}:
$PROMPT = "> "

$PROMPT = "{__is_prompt_start}{__is_update_cwd}" + $PROMPT + "{__is_prompt_end}"
13 changes: 6 additions & 7 deletions src/isterm/pty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import url from "node:url";
import fs from "node:fs";

import pty, { IPty, IEvent } from "@homebridge/node-pty-prebuilt-multiarch";
import { Shell, getPythonPath, userZdotdir, zdotdir } from "../utils/shell.js";
import { Shell, userZdotdir, zdotdir } from "../utils/shell.js";
import { IsTermOscPs, IstermOscPt, IstermPromptStart, IstermPromptEnd } from "../utils/ansi.js";
import xterm from "@xterm/headless";
import { CommandManager, CommandState } from "./commandManager.js";
Expand Down Expand Up @@ -253,7 +253,7 @@ export const spawn = async (options: ISTermOptions): Promise<ISTerm> => {

const convertToPtyTarget = async (shell: Shell) => {
const platform = os.platform();
let shellTarget = shell == Shell.Bash && platform == "win32" ? await gitBashPath() : platform == "win32" ? `${shell}.exe` : shell;
const shellTarget = shell == Shell.Bash && platform == "win32" ? await gitBashPath() : platform == "win32" ? `${shell}.exe` : shell;
const shellFolderPath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "..", "shell");
let shellArgs: string[] = [];

Expand All @@ -276,9 +276,7 @@ const convertToPtyTarget = async (shell: Shell) => {
path.join(os.homedir(), ".config", "xonsh", "rc.d"),
];
const configs = [sharedConfig, ...userConfigs].filter((config) => fs.existsSync(config));

shellArgs = ["-m", "xonsh", "--rc", ...configs, path.join(shellFolderPath, "shellIntegration.xsh")];
shellTarget = await getPythonPath();
shellArgs = ["--rc", ...configs, path.join(shellFolderPath, "shellIntegration.xsh")];
break;
}
}
Expand All @@ -287,11 +285,12 @@ const convertToPtyTarget = async (shell: Shell) => {
};

const convertToPtyEnv = (shell: Shell, underTest: boolean) => {
const env = {
const env: Record<string, string> = {
...process.env,
ISTERM: "1",
ISTERM_TESTING: underTest ? "1" : undefined,
};
if (underTest) env.ISTERM_TESTING = "1";

switch (shell) {
case Shell.Cmd: {
if (underTest) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ui/autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { test, expect, Shell } from "@microsoft/tui-test";
import os from "node:os";

const windowsShells = [Shell.Cmd, Shell.Powershell, Shell.WindowsPowershell, "xonsh"];
const windowsShells = [Shell.Cmd, Shell.Powershell, Shell.WindowsPowershell, Shell.Xonsh];
const unixShells = [Shell.Bash, Shell.Fish, Shell.Zsh];
const shells = os.platform() == "win32" ? windowsShells : unixShells;

Expand Down
4 changes: 0 additions & 4 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ export const gitBashPath = async (): Promise<string> => {
throw new Error("unable to find a git bash executable installed");
};

export const getPythonPath = async (): Promise<string> => {
return await which("python", { nothrow: true });
};

const getGitBashPaths = async (): Promise<string[]> => {
const gitDirs: Set<string> = new Set();

Expand Down

0 comments on commit 405385c

Please sign in to comment.