mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 01:08:10 +02:00
Allow rc commands to control the exit code
This commit is contained in:
@@ -247,6 +247,16 @@ func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_i
|
||||
return
|
||||
}
|
||||
|
||||
var running_shell = false
|
||||
|
||||
type exit_error struct {
|
||||
exit_code int
|
||||
}
|
||||
|
||||
func (m *exit_error) Error() string {
|
||||
return fmt.Sprintf("Subprocess exit with code: %d", m.exit_code)
|
||||
}
|
||||
|
||||
func send_rc_command(io_data *rc_io_data) (err error) {
|
||||
err = setup_global_options(io_data.cmd)
|
||||
if err != nil {
|
||||
|
||||
@@ -203,6 +203,7 @@ func shell_main(cmd *cli.Command, args []string) (int, error) {
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
running_shell = true
|
||||
formatter = markup.New(true)
|
||||
fmt.Println("Welcome to the kitty shell!")
|
||||
fmt.Println("Use", formatter.Green("help"), "for assistance or", formatter.Green("exit"), "to quit.")
|
||||
|
||||
@@ -90,6 +90,9 @@ func run_CMD_NAME(cmd *cli.Command, args []string) (return_code int, err error)
|
||||
}
|
||||
|
||||
err = send_rc_command(&io_data)
|
||||
if ee, ok := err.(*exit_error); ok && !running_shell {
|
||||
return ee.exit_code, nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user