diff --git a/commands/core/spec.go b/commands/core/spec.go index 998bc59..6191540 100644 --- a/commands/core/spec.go +++ b/commands/core/spec.go @@ -280,6 +280,7 @@ func topLevelSuggestions(query string) []Suggestion { if !seen[name] && (query == "" || hasPrefix(name, query)) { results = append(results, Suggestion{ Cmd: target, Desc: "alias: " + name, Icon: "root", + // Cmd: target, Desc: "alias: " + name, Icon: "DEBUG", //--> this is just for debug on reloading, dont mind it }) seen[name] = true } diff --git a/justfile b/justfile index fe1d40e..86edbe1 100644 --- a/justfile +++ b/justfile @@ -10,10 +10,12 @@ optimized-build: run: @./iris -# re-build and run +# re-build and reload iris [group('dev')] -update: - @go build -o iris main.go && ./iris +[linux, macos] +reload: + @go build -o iris main.go + @if [ -z "${IRIS_FD:-}" ]; then ./iris; fi # update pkg [group('dev')] diff --git a/root/root.go b/root/root.go index 083d92c..585406f 100644 --- a/root/root.go +++ b/root/root.go @@ -36,12 +36,44 @@ It works exactly like coding editor suggestion menu drop down.`, } func Execute() { + go watchSelf() if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } +func watchSelf() { + exe, err := os.Executable() + if err != nil { + return + } + + startTime := time.Now() + + for { + time.Sleep(500 * time.Millisecond) + info, err := os.Stat(exe) + if err != nil { + continue + } + + if info.ModTime().After(startTime) { + // clean up terminal before exec + fmt.Printf("\r\n\033[35m[IRIS] binary updated, reloading...\033[0m\r\n") + // we need to be careful about raw mode but syscall.Exec will replace the process + // which is fine as the new iris will setup its own raw mode + // however, to be safe for the terminal state, we'd ideally restore then exec + // but since we're inside a PTY wrapper, it's more complex + // the simplest way: just exec, the new iris will handle the terminal + err := syscall.Exec(exe, os.Args, os.Environ()) + if err != nil { + fmt.Printf("Reload failed: %v\n", err) + } + } + } +} + func runWrapper() { r, w, err := os.Pipe() if err != nil {