From 5c8ac9e4a65434f11004d430fcc694001dbb7d8c Mon Sep 17 00:00:00 2001 From: verse91 Date: Sun, 19 Apr 2026 12:45:20 +0700 Subject: [PATCH] feat: run with terminal --- root/init.go | 41 +++++++++++++++++++++++++++++++++++++++++ root/root.go | 9 +++++++++ 2 files changed, 50 insertions(+) create mode 100644 root/init.go diff --git a/root/init.go b/root/init.go new file mode 100644 index 0000000..6421dbf --- /dev/null +++ b/root/init.go @@ -0,0 +1,41 @@ +package root + +import ( + "fmt" + "github.com/spf13/cobra" +) + +var initCmd = &cobra.Command{ + Use: "init [bash|zsh|fish]", + Short: "Generate the autostart script for your shell", + Long: `Add the output of this command to your shell's configuration file to start Iris automatically. +For example, add this to your ~/.zshrc: + eval "$(iris init zsh)"`, + ValidArgs: []string{"bash", "zsh", "fish"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), + Run: func(cmd *cobra.Command, args []string) { + shell := args[0] + switch shell { + case "bash", "zsh": + fmt.Printf(` +# Iris Autostart Hook +if [ -z "$IRIS_PID" ]; then + export IRIS_ACTIVE_SHELL="%s" + exec iris +fi +`, shell) + case "fish": + fmt.Printf(` +# Iris Autostart Hook +if not set -q IRIS_PID + set -gx IRIS_ACTIVE_SHELL "fish" + exec iris +end +`) + } + }, +} + +func init() { + rootCmd.AddCommand(initCmd) +} diff --git a/root/root.go b/root/root.go index 21acb6d..e7e9908 100644 --- a/root/root.go +++ b/root/root.go @@ -3,6 +3,8 @@ package root import ( "fmt" "os" + "strconv" + "syscall" "github.com/spf13/cobra" "github.com/versenilvis/iris/commands/core" @@ -21,6 +23,13 @@ var ( Long: `IRIS (a.k.a Intelligent Real-time Input Suggestion) is a shell auto-autocompletion tool. It works exactly like coding editor suggestion menu drop down.`, Run: func(cmd *cobra.Command, args []string) { + if pidStr := os.Getenv("IRIS_PID"); pidStr != "" { + if pid, err := strconv.Atoi(pidStr); err == nil && pid > 0 { + _ = syscall.Kill(pid, syscall.SIGUSR1) + fmt.Println("\r\033[K\033[36m[IRIS] Sent reload signal to parent session.\033[0m") + return + } + } if debugMode { f, _ := os.OpenFile("iris.log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) debugLogger = f