mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
fix: add shell integration support without requiring user installation (#101)
* fix: add shell integration support without requiring user installation Signed-off-by: Chapman Pendery <cpendery@vt.edu> * fix: style lints Signed-off-by: Chapman Pendery <cpendery@vt.edu> * fix: failing tests Signed-off-by: Chapman Pendery <cpendery@vt.edu> --------- Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
||||
node_modules/
|
||||
build/
|
||||
build/
|
||||
t*.md
|
||||
Generated
+33
-523
File diff suppressed because it is too large
Load Diff
+1
-2
@@ -35,13 +35,12 @@
|
||||
"dependencies": {
|
||||
"@withfig/autocomplete": "^2.633.0",
|
||||
"ajv": "^8.12.0",
|
||||
"ansi-escapes": "^6.2.0",
|
||||
"ansi-styles": "^6.2.1",
|
||||
"chalk": "^5.3.0",
|
||||
"commander": "^11.0.0",
|
||||
"find-process": "^1.4.7",
|
||||
"ink": "^4.4.1",
|
||||
"node-pty": "^1.0.0",
|
||||
"react": "^18.2.0",
|
||||
"which": "^4.0.0",
|
||||
"wrap-ansi": "^8.1.0",
|
||||
"xterm-headless": "^5.3.0"
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
|
||||
$command = $null
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
|
||||
|
||||
$oldPrompt = $function:prompt
|
||||
function prompt { "`r" }
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
|
||||
$prompt = $oldPrompt
|
||||
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
|
||||
|
||||
$inshellisense = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\inshellisense\build\index.js"
|
||||
if ($command) {
|
||||
Start-Process -NoNewWindow -Wait "node" "$inshellisense -c $command -s powershell"
|
||||
}
|
||||
else {
|
||||
Start-Process -NoNewWindow -Wait "node" "$inshellisense -s powershell"
|
||||
}
|
||||
|
||||
$executedCommand = node $inshellisense --history
|
||||
if ($executedCommand) {
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
|
||||
$command = $null
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
|
||||
|
||||
$oldPrompt = $function:prompt
|
||||
function prompt { "`r" }
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
|
||||
$prompt = $oldPrompt
|
||||
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
|
||||
|
||||
$inshellisense = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\inshellisense\build\index.js"
|
||||
if ($command) {
|
||||
Start-Process -NoNewWindow -Wait "node" "$inshellisense -c $command -s pwsh"
|
||||
}
|
||||
else {
|
||||
Start-Process -NoNewWindow -Wait "node" "$inshellisense -s pwsh"
|
||||
}
|
||||
|
||||
$executedCommand = node $inshellisense --history
|
||||
if ($executedCommand) {
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
|
||||
}
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
__inshellisense__() {
|
||||
inshellisense -c "$READLINE_LINE" -s bash
|
||||
history -s $(inshellisense --history)
|
||||
READLINE_LINE=
|
||||
}
|
||||
|
||||
bind -x '"\C-a": __inshellisense__'
|
||||
@@ -1,8 +0,0 @@
|
||||
function inshellisense-widget -d "Activate autocomplete"
|
||||
inshellisense -c (commandline -b) -s fish
|
||||
commandline -r ''
|
||||
commandline -f repaint
|
||||
# TODO: add support for history insertion
|
||||
end
|
||||
|
||||
bind \ca inshellisense-widget
|
||||
@@ -1,10 +0,0 @@
|
||||
__inshellisense__() {
|
||||
input=$LBUFFER
|
||||
LBUFFER=
|
||||
inshellisense -c "$input" -s zsh < $TTY
|
||||
print -s $(inshellisense --history)
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
zle -N __inshellisense __inshellisense__
|
||||
bindkey '^A' __inshellisense
|
||||
@@ -0,0 +1,9 @@
|
||||
if [[ -f $USER_ZDOTDIR/.zshenv ]]; then
|
||||
ZDOTDIR=$USER_ZDOTDIR
|
||||
|
||||
# prevent recursion
|
||||
if [[ $USER_ZDOTDIR != $ZDOTDIR ]]; then
|
||||
ZDOTDIR=$USER_ZDOTDIR
|
||||
. $USER_ZDOTDIR/.zshenv
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,4 @@
|
||||
if [[ -f $USER_ZDOTDIR/.zlogin ]]; then
|
||||
ZDOTDIR=$USER_ZDOTDIR
|
||||
. $ZDOTDIR/.zlogin
|
||||
fi
|
||||
@@ -0,0 +1,4 @@
|
||||
if [[ -f $USER_ZDOTDIR/.zprofile ]]; then
|
||||
ZDOTDIR=$USER_ZDOTDIR
|
||||
. $USER_ZDOTDIR/.zprofile
|
||||
fi
|
||||
@@ -0,0 +1,19 @@
|
||||
if [[ -f $USER_ZDOTDIR/.zshrc ]]; then
|
||||
ZDOTDIR=$USER_ZDOTDIR
|
||||
. $USER_ZDOTDIR/.zshrc
|
||||
fi
|
||||
|
||||
__is_prompt_start() {
|
||||
builtin printf '\e]6973;PS\a'
|
||||
}
|
||||
|
||||
__is_prompt_end() {
|
||||
builtin printf '\e]6973;PE\a'
|
||||
}
|
||||
|
||||
__is_update_prompt() {
|
||||
__is_prior_prompt="$PS1"
|
||||
PS1="%{$(__is_prompt_start)%}$PS1%{$(__is_prompt_end)%}"
|
||||
}
|
||||
|
||||
__is_update_prompt
|
||||
@@ -0,0 +1,17 @@
|
||||
__is_prompt_start() {
|
||||
builtin printf '\e]6973;PS\a'
|
||||
}
|
||||
|
||||
__is_prompt_end() {
|
||||
builtin printf '\e]6973;PE\a'
|
||||
}
|
||||
|
||||
__is_update_prompt() {
|
||||
if [[ "$__is_custom_PS1" == "" || "$__is_custom_PS1" != "$PS1" ]]; then
|
||||
__is_original_PS1=$PS1
|
||||
__is_custom_PS1="\[$(__is_prompt_start)\]$__is_original_PS1\[$(__is_prompt_end)\]"
|
||||
PS1="$__is_custom_PS1"
|
||||
fi
|
||||
}
|
||||
|
||||
__is_update_prompt
|
||||
@@ -0,0 +1,6 @@
|
||||
function __is_copy_function; functions $argv[1] | sed "s/^function $argv[1]/function $argv[2]/" | source; end
|
||||
function __is_prompt_start; printf '\e]6973;PS\a'; end
|
||||
function __is_prompt_end; printf '\e]6973;PE\a'; end
|
||||
|
||||
__is_copy_function fish_prompt is_user_prompt
|
||||
function fish_prompt; printf (__is_prompt_start); printf (is_user_prompt); printf (__is_prompt_end); end
|
||||
@@ -0,0 +1,8 @@
|
||||
$Global:__IsOriginalPrompt = $function:Prompt
|
||||
|
||||
function Global:Prompt() {
|
||||
$Result = "$([char]0x1b)]6973;PS`a"
|
||||
$Result += $Global:__IsOriginalPrompt.Invoke()
|
||||
$Result += "$([char]0x1b)]6973;PE`a"
|
||||
return $Result
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { Command } from "commander";
|
||||
import { supportedShells } from "../utils/bindings.js";
|
||||
import { render } from "../ui/ui-bind.js";
|
||||
|
||||
const action = async () => {
|
||||
await render();
|
||||
};
|
||||
|
||||
const cmd = new Command("bind");
|
||||
cmd.description(`adds keybindings to the selected shell: ${supportedShells.join(", ")}`);
|
||||
cmd.action(action);
|
||||
|
||||
export default cmd;
|
||||
@@ -2,7 +2,7 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { render } from "../ui/ui-root.js";
|
||||
import { Shell, supportedShells as shells } from "../utils/bindings.js";
|
||||
import { Shell, supportedShells as shells, setupZshDotfiles } from "../utils/shell.js";
|
||||
import { inferShell } from "../utils/shell.js";
|
||||
import { loadConfig } from "../utils/config.js";
|
||||
import { Command } from "commander";
|
||||
@@ -23,5 +23,8 @@ export const action = (program: Command) => async (options: RootCommandOptions)
|
||||
if (!shells.map((s) => s.valueOf()).includes(shell)) {
|
||||
program.error(`Unsupported shell: '${shell}', supported shells: ${supportedShells}`, { exitCode: 1 });
|
||||
}
|
||||
if (shell == Shell.Zsh) {
|
||||
await setupZshDotfiles();
|
||||
}
|
||||
await render(shell);
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ const action = async () => {
|
||||
};
|
||||
|
||||
const cmd = new Command("uninstall");
|
||||
cmd.description(`removes all bindings and configuration for inshellisense`);
|
||||
cmd.description(`removes all configuration for inshellisense`);
|
||||
cmd.action(action);
|
||||
|
||||
export default cmd;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
import { Command } from "commander";
|
||||
|
||||
import bind from "./commands/bind.js";
|
||||
import uninstall from "./commands/uninstall.js";
|
||||
import { action, supportedShells } from "./commands/root.js";
|
||||
import { getVersion } from "./utils/version.js";
|
||||
@@ -22,7 +21,6 @@ program
|
||||
.option("-s, --shell <shell>", `shell to use for command execution, supported shells: ${supportedShells}`)
|
||||
.showHelpAfterError("(add --help for additional information)");
|
||||
|
||||
program.addCommand(bind);
|
||||
program.addCommand(uninstall);
|
||||
|
||||
program.parse();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { IBufferCell, IMarker, Terminal } from "xterm-headless";
|
||||
import os from "node:os";
|
||||
import { Shell } from "../utils/bindings.js";
|
||||
import { Shell } from "../utils/shell.js";
|
||||
import log from "../utils/log.js";
|
||||
import { getConfig } from "../utils/config.js";
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user