diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 87c1c466d..630e8f628 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -360,6 +360,14 @@ The following variables can be set: Mouse support requires that ncurses itself support mouse events and that you have enabled mouse support in ~/.tigrc with `set mouse = true`. +'pgrp' (bool):: + + Make tig process-group leader when starting and clean all processes + when exiting. Off by default. Do not enable this option if you are + using a Zsh version affected by zsh-workers/43379. Run `xclip` with + `setsid` to keep clipboard content after exiting tig. If you are using + git-credential-cache helper, set option `credentialCache.ignoreSIGHUP`. + 'start-on-head' (bool):: Start with cursor on HEAD commit. diff --git a/include/tig/options.h b/include/tig/options.h index c43f4b877..4636e51a6 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -62,6 +62,7 @@ typedef struct view_column *view_settings; _(mouse_scroll, int, VIEW_NO_FLAGS) \ _(mouse_wheel_cursor, bool, VIEW_NO_FLAGS) \ _(pager_view, view_settings, VIEW_NO_FLAGS) \ + _(pgrp, bool, VIEW_NO_FLAGS) \ _(reference_format, struct ref_format **, VIEW_NO_FLAGS) \ _(refresh_interval, int, VIEW_NO_FLAGS) \ _(refresh_mode, enum refresh_mode, VIEW_NO_FLAGS) \ diff --git a/src/display.c b/src/display.c index a23d41a8c..2b742c158 100644 --- a/src/display.c +++ b/src/display.c @@ -573,9 +573,11 @@ done_display(void) free(opt_tty.attr); opt_tty.attr = NULL; } - signal(SIGTTOU, SIG_IGN); - tcsetpgrp(opt_tty.fd, opt_tty.opgrp); - signal(SIGTTOU, SIG_DFL); + if (opt_tty.opgrp != -1) { + signal(SIGTTOU, SIG_IGN); + tcsetpgrp(opt_tty.fd, opt_tty.opgrp); + signal(SIGTTOU, SIG_DFL); + } } static void @@ -603,12 +605,14 @@ init_tty(void) die("Failed allocation for tty attributes"); tcgetattr(opt_tty.fd, opt_tty.attr); - /* process-group leader */ - signal(SIGTTOU, SIG_IGN); - setpgid(getpid(), getpid()); - opt_tty.opgrp = tcgetpgrp(opt_tty.fd); - tcsetpgrp(opt_tty.fd, getpid()); - signal(SIGTTOU, SIG_DFL); + if (opt_pgrp) { + /* process-group leader */ + setpgid(getpid(), getpid()); + opt_tty.opgrp = tcgetpgrp(opt_tty.fd); + signal(SIGTTOU, SIG_IGN); + tcsetpgrp(opt_tty.fd, getpid()); + signal(SIGTTOU, SIG_DFL); + } die_callback = done_display; } diff --git a/src/tig.c b/src/tig.c index 44ad49de4..eedbf7906 100644 --- a/src/tig.c +++ b/src/tig.c @@ -807,10 +807,6 @@ main(int argc, const char *argv[]) enum request request = parse_options(argc, argv, pager_mode); struct view *view; - init_tty(); - - atexit(hangup_children); - if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) die("Failed to setup signal handler"); @@ -831,6 +827,11 @@ main(int argc, const char *argv[]) die_if_failed(load_options(), "Failed to load user config."); die_if_failed(load_git_config(), "Failed to load repo config."); + init_tty(); + + if (opt_pgrp) + atexit(hangup_children); + prompt_init(); /* Require a git repository unless when running in pager mode. */ diff --git a/tigrc b/tigrc index 5f03b3b7a..a54499095 100644 --- a/tigrc +++ b/tigrc @@ -140,6 +140,7 @@ set history-size = 500 # Size of persistent history, 0 to disable set mouse = no # Enable mouse support? set mouse-scroll = 3 # Number of lines to scroll via the mouse set mouse-wheel-cursor = no # Prefer moving the cursor to scrolling the view? +set pgrp = no # Make tig process-group leader # User-defined commands # ---------------------