summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-03-07 06:31:23 +0800
committerGitHub <noreply@github.com>2024-03-07 06:31:23 +0800
commitf82f577b6dd65c973d96faa2df7682538b517119 (patch)
tree5f0a39a8c9a811e67b790a943ca9f178daf8a17e
parentd6e12b1f56c7b3437f28e8bce5d1f2b999970f4c (diff)
downloadaichat-f82f577b6dd65c973d96faa2df7682538b517119.tar.gz
feat: add nushell integration (#344)
-rw-r--r--scripts/shell-integration/integration.nu21
-rw-r--r--src/config/role.rs17
2 files changed, 33 insertions, 5 deletions
diff --git a/scripts/shell-integration/integration.nu b/scripts/shell-integration/integration.nu
new file mode 100644
index 0000000..291f287
--- /dev/null
+++ b/scripts/shell-integration/integration.nu
@@ -0,0 +1,21 @@
+def _aichat_nushell [] {
+ let _prev = (commandline)
+ if ($_prev != "") {
+ print '⌛'
+ commandline edit -r (aichat -e $_prev)
+ }
+}
+
+$env.config.keybindings = ($env.config.keybindings | append {
+ name: aichat_integration
+ modifier: alt
+ keycode: char_e
+ mode: [emacs, vi_insert]
+ event:[
+ {
+ send: executehostcommand,
+ cmd: "_aichat_nushell"
+ }
+ ]
+ }
+) \ No newline at end of file
diff --git a/src/config/role.rs b/src/config/role.rs
index 2bff545..7b4a117 100644
--- a/src/config/role.rs
+++ b/src/config/role.rs
@@ -28,17 +28,24 @@ impl Role {
pub fn for_execute() -> Self {
let os = detect_os();
let (shell, _, _) = detect_shell();
- let combine = match shell.as_str() {
- "nushell" | "powershell" => ";",
- _ => "&&",
+ let (shell, use_semicolon) = match (shell.as_str(), os.as_str()) {
+ ("nushell", "windows") => ("cmd", true),
+ ("nushell", _) => ("bash", true),
+ ("powershell", _) => ("powershell", true),
+ ("pwsh", _) => ("powershell", false),
+ _ => (shell.as_str(), false),
+ };
+ let combine = if use_semicolon {
+ "\nIf multiple steps required try to combine them together using ';'.\nIf it already combined with '&&' try to replace it with ';'.".to_string()
+ } else {
+ "\nIf multiple steps required try to combine them together using &&.".to_string()
};
Self {
name: Self::EXECUTE.into(),
prompt: format!(
r#"Provide only {shell} commands for {os} without any description.
+Ensure the output is a valid {shell} command. {combine}
If there is a lack of details, provide most logical solution.
-Ensure the output is a valid {shell} command.
-If multiple steps required try to combine them together using {combine}.
Provide only plain text without Markdown formatting.
Do not provide markdown formatting such as ```"#
),