diff --git a/src/shell-integration/bash/ghostty.bash b/src/shell-integration/bash/ghostty.bash index f13a7d378..205494c94 100644 --- a/src/shell-integration/bash/ghostty.bash +++ b/src/shell-integration/bash/ghostty.bash @@ -96,33 +96,16 @@ if [[ "$GHOSTTY_SHELL_FEATURES" == *"sudo"* && -n "$TERMINFO" ]]; then fi # SSH Integration -if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then +if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]] || [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then ssh() { - builtin local ssh_env ssh_opts ssh_exported_vars + builtin local ssh_env ssh_opts ssh_env=() ssh_opts=() - ssh_exported_vars=() # Configure environment variables for remote session - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]]; then + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]]; then ssh_opts+=(-o "SetEnv COLORTERM=truecolor") - - if [[ -n "${TERM_PROGRAM+x}" ]]; then - ssh_exported_vars+=("TERM_PROGRAM=${TERM_PROGRAM}") - else - ssh_exported_vars+=("TERM_PROGRAM") - fi - builtin export "TERM_PROGRAM=ghostty" - ssh_opts+=(-o "SendEnv TERM_PROGRAM") - - if [[ -n "$TERM_PROGRAM_VERSION" ]]; then - if [[ -n "${TERM_PROGRAM_VERSION+x}" ]]; then - ssh_exported_vars+=("TERM_PROGRAM_VERSION=${TERM_PROGRAM_VERSION}") - else - ssh_exported_vars+=("TERM_PROGRAM_VERSION") - fi - ssh_opts+=(-o "SendEnv TERM_PROGRAM_VERSION") - fi + ssh_opts+=(-o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION") ssh_env+=( "COLORTERM=truecolor" @@ -134,7 +117,7 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then fi # Install terminfo on remote host if needed - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-terminfo ]]; then + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then builtin local ssh_config ssh_user ssh_hostname ssh_config=$(builtin command ssh -G "$@" 2>/dev/null) @@ -146,7 +129,7 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then [[ -n "$ssh_user" && -n "$ssh_hostname" ]] && break done <<< "$ssh_config" - ssh_target="${ssh_user}@${ssh_hostname}" + builtin local ssh_target="${ssh_user}@${ssh_hostname}" if [[ -n "$ssh_hostname" ]]; then # Check if terminfo is already cached @@ -213,7 +196,7 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then ssh_env+=(TERM=xterm-256color) fi else - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]]; then + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]]; then ssh_env+=(TERM=xterm-256color) fi fi @@ -228,7 +211,7 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then fi done - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env && -z "$ssh_term_override" ]]; then + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* && -z "$ssh_term_override" ]]; then ssh_env+=(TERM=xterm-256color) ssh_term_override="xterm-256color" fi @@ -244,17 +227,6 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then local ssh_ret=$? fi - # Restore original environment variables - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]]; then - for ssh_v in "${ssh_exported_vars[@]}"; do - if [[ "$ssh_v" == *=* ]]; then - builtin export "${ssh_v?}" - else - builtin unset "${ssh_v}" - fi - done - fi - return $ssh_ret } fi @@ -286,8 +258,8 @@ function __ghostty_precmd() { # Cursor if [[ "$GHOSTTY_SHELL_FEATURES" == *"cursor"* ]]; then - PS1=$PS1'\[\e[5 q\]' # blinking bar for input - builtin printf "\e[0 q" # reset to default cursor + [[ "$PS1" != *'\[\e[5 q\]'* ]] && PS1=$PS1'\[\e[5 q\]' # input + [[ "$PS0" != *'\[\e[0 q\]'* ]] && PS0=$PS0'\[\e[0 q\]' # reset fi # Title (working directory) diff --git a/src/shell-integration/elvish/lib/ghostty-integration.elv b/src/shell-integration/elvish/lib/ghostty-integration.elv index 52d01e4fb..c2d187961 100644 --- a/src/shell-integration/elvish/lib/ghostty-integration.elv +++ b/src/shell-integration/elvish/lib/ghostty-integration.elv @@ -105,28 +105,11 @@ fn ssh {|@args| var ssh-env = [] var ssh-opts = [] - var ssh-exported-vars = [] # Configure environment variables for remote session if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-env) { set ssh-opts = [$@ssh-opts -o "SetEnv COLORTERM=truecolor"] - - if (has-env TERM_PROGRAM) { - set ssh-exported-vars = [$@ssh-exported-vars "TERM_PROGRAM="$E:TERM_PROGRAM] - } else { - set ssh-exported-vars = [$@ssh-exported-vars "TERM_PROGRAM"] - } - set-env TERM_PROGRAM ghostty - set ssh-opts = [$@ssh-opts -o "SendEnv TERM_PROGRAM"] - - if (has-env TERM_PROGRAM_VERSION) { - if (has-env TERM_PROGRAM_VERSION) { - set ssh-exported-vars = [$@ssh-exported-vars "TERM_PROGRAM_VERSION="$E:TERM_PROGRAM_VERSION] - } else { - set ssh-exported-vars = [$@ssh-exported-vars "TERM_PROGRAM_VERSION"] - } - set ssh-opts = [$@ssh-opts -o "SendEnv TERM_PROGRAM_VERSION"] - } + set ssh-opts = [$@ssh-opts -o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION"] set ssh-env = [ "COLORTERM=truecolor" @@ -288,18 +271,6 @@ } } - # Restore original environment variables - if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-env) { - for ssh-v $ssh-exported-vars { - if (str:contains $ssh-v =) { - var ssh-var-parts = (str:split &max=2 = $ssh-v) - set-env $ssh-var-parts[0] $ssh-var-parts[1] - } else { - unset-env $ssh-v - } - } - } - if (not-eq $ssh-ret 0) { fail ssh-failed } diff --git a/src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish b/src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish index 332675264..c45c20f92 100644 --- a/src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish +++ b/src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish @@ -91,28 +91,11 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration" function ssh --wraps=ssh --description "SSH wrapper with Ghostty integration" set -l ssh_env set -l ssh_opts - set -l ssh_exported_vars # Configure environment variables for remote session if string match -q '*ssh-env*' -- "$GHOSTTY_SHELL_FEATURES" set -a ssh_opts -o "SetEnv COLORTERM=truecolor" - - if set -q TERM_PROGRAM - set -a ssh_exported_vars "TERM_PROGRAM=$TERM_PROGRAM" - else - set -a ssh_exported_vars "TERM_PROGRAM" - end - set -gx TERM_PROGRAM ghostty - set -a ssh_opts -o "SendEnv TERM_PROGRAM" - - if test -n "$TERM_PROGRAM_VERSION" - if set -q TERM_PROGRAM_VERSION - set -a ssh_exported_vars "TERM_PROGRAM_VERSION=$TERM_PROGRAM_VERSION" - else - set -a ssh_exported_vars "TERM_PROGRAM_VERSION" - end - set -a ssh_opts -o "SendEnv TERM_PROGRAM_VERSION" - end + set -a ssh_opts -o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION" set -a ssh_env "COLORTERM=truecolor" set -a ssh_env "TERM_PROGRAM=ghostty" @@ -237,17 +220,6 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration" set ssh_ret $status end - # Restore original environment variables - if string match -q '*ssh-env*' -- "$GHOSTTY_SHELL_FEATURES" - for ssh_v in $ssh_exported_vars - if string match -q '*=*' -- $ssh_v - set -gx (string split -m1 '=' -- $ssh_v) - else - set -e $ssh_v - end - end - end - return $ssh_ret end end diff --git a/src/shell-integration/zsh/ghostty-integration b/src/shell-integration/zsh/ghostty-integration index 40ee58b49..37880e5f8 100644 --- a/src/shell-integration/zsh/ghostty-integration +++ b/src/shell-integration/zsh/ghostty-integration @@ -244,37 +244,20 @@ _ghostty_deferred_init() { } fi -# SSH Integration - if [[ "$GHOSTTY_SHELL_FEATURES" =~ (ssh-env|ssh-terminfo) ]]; then + # SSH Integration + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]] || [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then ssh() { emulate -L zsh setopt local_options no_glob_subst - local ssh_env ssh_opts ssh_exported_vars + local ssh_env ssh_opts ssh_env=() ssh_opts=() - ssh_exported_vars=() # Configure environment variables for remote session - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]]; then + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]]; then ssh_opts+=(-o "SetEnv COLORTERM=truecolor") - - if [[ -n "${TERM_PROGRAM+x}" ]]; then - ssh_exported_vars+=("TERM_PROGRAM=${TERM_PROGRAM}") - else - ssh_exported_vars+=("TERM_PROGRAM") - fi - export "TERM_PROGRAM=ghostty" - ssh_opts+=(-o "SendEnv TERM_PROGRAM") - - if [[ -n "$TERM_PROGRAM_VERSION" ]]; then - if [[ -n "${TERM_PROGRAM_VERSION+x}" ]]; then - ssh_exported_vars+=("TERM_PROGRAM_VERSION=${TERM_PROGRAM_VERSION}") - else - ssh_exported_vars+=("TERM_PROGRAM_VERSION") - fi - ssh_opts+=(-o "SendEnv TERM_PROGRAM_VERSION") - fi + ssh_opts+=(-o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION") ssh_env+=( "COLORTERM=truecolor" @@ -284,7 +267,7 @@ _ghostty_deferred_init() { fi # Install terminfo on remote host if needed - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-terminfo ]]; then + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then local ssh_config ssh_user ssh_hostname ssh_config=$(command ssh -G "$@" 2>/dev/null) @@ -296,7 +279,7 @@ _ghostty_deferred_init() { [[ -n "$ssh_user" && -n "$ssh_hostname" ]] && break done <<< "$ssh_config" - ssh_target="${ssh_user}@${ssh_hostname}" + local ssh_target="${ssh_user}@${ssh_hostname}" if [[ -n "$ssh_hostname" ]]; then # Check if terminfo is already cached @@ -360,7 +343,7 @@ _ghostty_deferred_init() { ssh_env+=(TERM=xterm-256color) fi else - [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]] && ssh_env+=(TERM=xterm-256color) + [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]] && ssh_env+=(TERM=xterm-256color) fi fi @@ -374,7 +357,7 @@ _ghostty_deferred_init() { fi done - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env && -z "$ssh_term_override" ]]; then + if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* && -z "$ssh_term_override" ]]; then ssh_env+=(TERM=xterm-256color) ssh_term_override="xterm-256color" fi @@ -391,17 +374,6 @@ _ghostty_deferred_init() { ssh_ret=$? fi - # Restore original environment variables - if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]]; then - for ssh_v in "${ssh_exported_vars[@]}"; do - if [[ "$ssh_v" == *=* ]]; then - export "${ssh_v}" - else - unset "${ssh_v}" - fi - done - fi - return $ssh_ret } fi