From 585053bb8ed11ba237cbe1420ebebd533bcf5cc8 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 19 Jun 2019 13:34:02 +0200 Subject: [PATCH] Notify the terminal about the current toolbox container in use This will let GNOME Terminal preserve the current toolbox container, if any, when opening a new terminal. Since this is mainly beneficial to users of an interactive shell inside a toolbox container, the escape sequences are only emitted by 'toolbox enter', and not 'toolbox run'. The OSC 777 escape sequence is taken from Enlightenment's Terminology: https://phab.enlightenment.org/T1765 It's a VTE-specific extension until a standard escape sequence is agreed upon across multiple different terminal emulators [1]. [1] https://gitlab.freedesktop.org/terminal-wg/specifications/issues/17 https://github.com/debarshiray/toolbox/pull/199 --- toolbox | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/toolbox b/toolbox index 6c32ba6..d7eae12 100755 --- a/toolbox +++ b/toolbox @@ -839,7 +839,7 @@ create() enter() { - run true false "$SHELL" -l + run true true false "$SHELL" -l } @@ -967,10 +967,11 @@ EOF run() ( - fallback_to_bash="$1" - pedantic="$2" - program="$3" - shift 3 + emit_escape_sequence="$1" + fallback_to_bash="$2" + pedantic="$3" + program="$4" + shift 4 create_toolbox_container=false prompt_for_create=true @@ -1105,6 +1106,8 @@ run() echo "$base_toolbox_command: $i" >&3 done + $emit_escape_sequence && printf "\033]777;container;push;%s;toolbox\033\\" "$toolbox_container" + # shellcheck disable=SC2016 # for the command passed to capsh # shellcheck disable=SC2086 @@ -1115,6 +1118,11 @@ run() $set_environment \ "$toolbox_container" \ capsh --caps="" -- -c 'cd "$1"; shift; exec "$@"' /bin/sh "$PWD" "$program" "$@" 2>&3 + ret_val="$?" + + $emit_escape_sequence && printf "\033]777;container;pop;;\033\\" + + exit "$ret_val" ) @@ -1967,7 +1975,7 @@ case $op in if ! update_container_and_image_names; then exit 1 fi - run false true "$@" + run false false true "$@" exit ;; * )