first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -24,7 +24,7 @@ set -g DCS_START \u1b\u50\u24
|
||||
# _warp_run_generator_command_internal, which instead end in 'e' (0x65).
|
||||
set -g DCS_JSON_MARKER 'd'
|
||||
|
||||
set -g DCS_END \u9c
|
||||
set -g DCS_END \x1b\x5c
|
||||
|
||||
set -g OSC_START (printf '\e]9278;')
|
||||
|
||||
@@ -159,13 +159,13 @@ end
|
||||
# Run before a command is executed.
|
||||
function warp_preexec --on-event fish_preexec
|
||||
set -l command (warp_escape_json "$argv")
|
||||
warp_send_json_message "{\"hook\": \"Preexec\", \"value\": {\"command\": \"$command\"}}"
|
||||
warp_send_json_message "{\"hook\": \"Preexec\", \"value\": {\"command\": \"$command\", \"session_id\": $WARP_SESSION_ID}}"
|
||||
warp_maybe_send_reset_grid_osc
|
||||
|
||||
# If this preexec is called for user command, kill ongoing generator command jobs.
|
||||
if test (! string match -q "warp_run_generator_command*" $argv[1])
|
||||
for pid in $_warp_generator_pids
|
||||
# Surpress stderr output; kill writes to stderr if any of the given
|
||||
# Suppress stderr output; kill writes to stderr if any of the given
|
||||
# PIDS are not running (which might rarely be the case due to race
|
||||
# conditions in checking which PIDS to cancel and this kill command.
|
||||
kill -9 $pids >/dev/null 2>/dev/null
|
||||
@@ -278,7 +278,8 @@ function warp_precmd --on-event fish_prompt --on-event fish_posterror
|
||||
set exit_code 1
|
||||
end
|
||||
|
||||
warp_send_json_message "{\"hook\": \"CommandFinished\", \"value\": {\"exit_code\": $exit_code, \"next_block_id\": \"precmd-$WARP_SESSION_ID-$block_id\"}}"
|
||||
set -l next_block_id "precmd-$WARP_SESSION_ID-$block_id"
|
||||
warp_send_json_message "{\"hook\": \"CommandFinished\", \"value\": {\"exit_code\": $exit_code, \"next_block_id\": \"$next_block_id\", \"session_id\": $WARP_SESSION_ID}}"
|
||||
warp_maybe_send_reset_grid_osc
|
||||
|
||||
set block_id (math $block_id + 1)
|
||||
@@ -286,6 +287,8 @@ function warp_precmd --on-event fish_prompt --on-event fish_posterror
|
||||
if ! test -z $_WARP_GENERATOR_COMMAND
|
||||
set -e _WARP_GENERATOR_COMMAND
|
||||
set -l escaped_json "{\"hook\": \"Precmd\", \"value\": {
|
||||
\"exit_code\": $exit_code,
|
||||
\"next_block_id\": \"$next_block_id\",
|
||||
\"pwd\": \"\",
|
||||
\"ps1\": \"\",
|
||||
\"git_head\": \"\",
|
||||
@@ -347,37 +350,63 @@ function warp_precmd --on-event fish_prompt --on-event fish_posterror
|
||||
set escaped_conda_env (warp_escape_json "$CONDA_DEFAULT_ENV")
|
||||
end
|
||||
|
||||
# Get Node.js version if node is available and we're in a Node.js project
|
||||
if command -v node > /dev/null 2>&1
|
||||
# Get the Node.js version, but only when the Node.js Version chip is enabled.
|
||||
# Warp sets WARP_PROMPT_NODE_VERSION_ENABLED to "0" when the chip is not in the
|
||||
# prompt (defaulting to enabled when unset), so we avoid spawning `node` on
|
||||
# every prompt when the chip is not shown.
|
||||
if test "$WARP_PROMPT_NODE_VERSION_ENABLED" != "0"; and command -v node > /dev/null 2>&1
|
||||
# Check for package.json in current directory and parent directories
|
||||
set current_dir (pwd)
|
||||
set found_package_json false
|
||||
set package_json_dir ""
|
||||
while test "$current_dir" != "/"
|
||||
while test -n "$current_dir"
|
||||
if test -f "$current_dir/package.json"
|
||||
set found_package_json true
|
||||
set package_json_dir "$current_dir"
|
||||
break
|
||||
end
|
||||
set current_dir (dirname "$current_dir")
|
||||
if test "$current_dir" = "/"
|
||||
break
|
||||
end
|
||||
# Strip the last path segment without spawning `dirname`.
|
||||
set current_dir (string replace -r '/[^/]*$' '' -- "$current_dir")
|
||||
if test -z "$current_dir"
|
||||
set current_dir "/"
|
||||
end
|
||||
end
|
||||
|
||||
# Only show node version if package.json is within a git repository
|
||||
if test "$found_package_json" = true
|
||||
set git_dir "$package_json_dir"
|
||||
set in_git_repo false
|
||||
while test "$git_dir" != "/"
|
||||
while test -n "$git_dir"
|
||||
if test -d "$git_dir/.git"
|
||||
set in_git_repo true
|
||||
break
|
||||
end
|
||||
set git_dir (dirname "$git_dir")
|
||||
if test "$git_dir" = "/"
|
||||
break
|
||||
end
|
||||
set git_dir (string replace -r '/[^/]*$' '' -- "$git_dir")
|
||||
if test -z "$git_dir"
|
||||
set git_dir "/"
|
||||
end
|
||||
end
|
||||
|
||||
if test "$in_git_repo" = true
|
||||
set node_version (node --version 2>/dev/null)
|
||||
if test -n "$node_version"
|
||||
set escaped_node_version (warp_escape_json "$node_version")
|
||||
# Cache the resolved version keyed on PWD + PATH so we only spawn
|
||||
# `node --version` when the directory or PATH changes (PATH changes
|
||||
# on `nvm use`). Use global cache vars so they persist across calls.
|
||||
set -l node_cache_key "$PWD:$PATH"
|
||||
if test "$node_cache_key" = "$_WARP_NODE_VERSION_CACHE_KEY"
|
||||
set escaped_node_version "$_WARP_NODE_VERSION_CACHE_VALUE"
|
||||
else
|
||||
set -l node_version (node --version 2>/dev/null)
|
||||
if test -n "$node_version"
|
||||
set escaped_node_version (warp_escape_json "$node_version")
|
||||
end
|
||||
set -g _WARP_NODE_VERSION_CACHE_KEY "$node_cache_key"
|
||||
set -g _WARP_NODE_VERSION_CACHE_VALUE "$escaped_node_version"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -401,7 +430,7 @@ function warp_precmd --on-event fish_prompt --on-event fish_posterror
|
||||
warp_update_prompt_vars
|
||||
# This is used solely for prompt previews, when we're using prompt markers with combined grid.
|
||||
# We need to use this since fish does not have a way to ignore printable characters for cursor
|
||||
# positioning (unlike zsh/bash), so we need a separate mechansim to send the prompt to Warp
|
||||
# positioning (unlike zsh/bash), so we need a separate mechanism to send the prompt to Warp
|
||||
# in the case of Warp prompt (for previewing the PS1). We send an escaped version of the raw prompt
|
||||
# bytes via a hex string (in a JSON payload) to Warp.
|
||||
# Note that we are CALLING the `warp_original_fish_prompt` function on the next line and assigning the
|
||||
@@ -414,6 +443,8 @@ function warp_precmd --on-event fish_prompt --on-event fish_posterror
|
||||
if test "$WARP_HONOR_PS1" = "1"
|
||||
# Don't send lprompt or rprompt in this case - we'll use prompt markers for both directly!
|
||||
set escaped_json "{\"hook\": \"Precmd\", \"value\": {
|
||||
\"exit_code\": $exit_code,
|
||||
\"next_block_id\": \"$next_block_id\",
|
||||
\"pwd\": \"$escaped_pwd\",
|
||||
\"ps1\": \"\",
|
||||
\"rprompt\": \"\",
|
||||
@@ -427,6 +458,8 @@ function warp_precmd --on-event fish_prompt --on-event fish_posterror
|
||||
else
|
||||
# We send an lprompt to use for prompt preview purposes only (we still use prompt markers for active prompts).
|
||||
set escaped_json "{\"hook\": \"Precmd\", \"value\": {
|
||||
\"exit_code\": $exit_code,
|
||||
\"next_block_id\": \"$next_block_id\",
|
||||
\"pwd\": \"$escaped_pwd\",
|
||||
\"ps1\": \"$escaped_prompt\",
|
||||
\"rprompt\": \"\",
|
||||
@@ -513,7 +546,7 @@ function warp_bootstrapped
|
||||
# part of its builtins (e.g. "for", "while", etc.).
|
||||
set -l escaped_editor (warp_escape_json "$EDITOR")
|
||||
set -l escaped_shell_path (warp_escape_json (status fish-path))
|
||||
set -l escaped_json "{\"hook\": \"Bootstrapped\", \"value\": {\"histfile\": \"$escaped_histfile\", \"shell\": \"fish\", \"home_dir\": \"$HOME\", \"path\": \"$PATH\", \"editor\": \"$escaped_editor\", \"abbreviations\": \"$escaped_abbr\", \"aliases\": \"$escaped_aliases\", \"function_names\": \"$function_names\", \"env_var_names\": \"$env_var_names\", \"builtins\": \"$escaped_builtins\", \"keywords\": \"\", \"shell_version\": \"$FISH_VERSION\", \"vi_mode_enabled\": \"$vi_mode_enabled\", \"os_category\": \"$os_category\", \"linux_distribution\": \"$linux_distribution\", \"wsl_name\": \"$WSL_DISTRO_NAME\", \"shell_path\": \"$escaped_shell_path\"}}"
|
||||
set -l escaped_json "{\"hook\": \"Bootstrapped\", \"value\": {\"histfile\": \"$escaped_histfile\", \"session_id\": $WARP_SESSION_ID, \"shell\": \"fish\", \"home_dir\": \"$HOME\", \"path\": \"$PATH\", \"editor\": \"$escaped_editor\", \"abbreviations\": \"$escaped_abbr\", \"aliases\": \"$escaped_aliases\", \"function_names\": \"$function_names\", \"env_var_names\": \"$env_var_names\", \"builtins\": \"$escaped_builtins\", \"keywords\": \"\", \"shell_version\": \"$FISH_VERSION\", \"vi_mode_enabled\": \"$vi_mode_enabled\", \"os_category\": \"$os_category\", \"linux_distribution\": \"$linux_distribution\", \"wsl_name\": \"$WSL_DISTRO_NAME\", \"shell_path\": \"$escaped_shell_path\"}}"
|
||||
warp_send_json_message $escaped_json
|
||||
end
|
||||
|
||||
@@ -529,18 +562,18 @@ end
|
||||
# Binding to ESC-1 caused bootstrap failures with vi keybindings.
|
||||
function warp_report_input
|
||||
set -l escaped_input (warp_escape_json (commandline))
|
||||
warp_send_json_message "{ \"hook\": \"InputBuffer\", \"value\": { \"buffer\": \"$escaped_input\" } }"
|
||||
warp_send_json_message "{ \"hook\": \"InputBuffer\", \"value\": { \"buffer\": \"$escaped_input\", \"session_id\": $WARP_SESSION_ID } }"
|
||||
# This prevents fish from rendering typeahead as background output once we've collected it.
|
||||
commandline ''
|
||||
end
|
||||
|
||||
function clear
|
||||
warp_send_json_message "{\"hook\": \"Clear\", \"value\": {}}"
|
||||
warp_send_json_message "{\"hook\": \"Clear\", \"value\": {\"session_id\": $WARP_SESSION_ID}}"
|
||||
end
|
||||
|
||||
function warp_finish_update
|
||||
set -l update_id "$argv[1]"
|
||||
warp_send_json_message "{\"hook\": \"FinishUpdate\", \"value\": { \"update_id\": \"$update_id\"}}"
|
||||
warp_send_json_message "{\"hook\": \"FinishUpdate\", \"value\": { \"update_id\": \"$update_id\", \"session_id\": $WARP_SESSION_ID}}"
|
||||
end
|
||||
|
||||
|
||||
@@ -598,10 +631,45 @@ if test "$WARP_IS_LOCAL_SHELL_SESSION" = "1"
|
||||
function warp_ssh_helper
|
||||
set -l init_shell_zsh (warp_init_shell "zsh")
|
||||
set -l init_shell_bash (warp_init_shell "bash")
|
||||
set -l remote_session_id (command od -An -N8 -tu8 /dev/urandom 2>/dev/null | command tr -d ' \n')
|
||||
if test -z "$remote_session_id"; or test "$remote_session_id" = "0"
|
||||
# If we cannot generate a non-zero random token, run plain SSH instead.
|
||||
command ssh $argv
|
||||
return
|
||||
end
|
||||
# Hex-encode the ZSH environment script we use to bootstrap remote zsh b/c it contains control characters
|
||||
# We decode on the SSH server using xxd if its available, otherwise fall back to a for-loop over each byte
|
||||
# and use printf to convert back to plaintext
|
||||
set -l zsh_env_script (printf '%s' 'unsetopt ZLE; unset RCS; unset GLOBAL_RCS; WARP_SESSION_ID="$(command -p date +%s)$RANDOM"; WARP_USING_WINDOWS_CON_PTY=@@USING_CON_PTY_BOOLEAN@@; WARP_HONOR_PS1='$WARP_HONOR_PS1'; _hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || uname -n); _user=$(command -pv whoami >/dev/null 2>&1 && command -p whoami 2>/dev/null || echo $USER); _msg=$(printf "{\"hook\": \"InitShell\", \"value\": {\"session_id\": $WARP_SESSION_ID, \"shell\": \"zsh\", \"user\": \"%s\", \"hostname\": \"%s\"}}" "$_user" "$_hostname" | command -p od -An -v -tx1 | command -p tr -d " \n"); printf '"'"'\x1b\x50\x24\x64%s\x9c'"'"' $_msg; unset _hostname _user _msg' | command od -An -v -tx1 | command tr -d ' \n')
|
||||
set -l zsh_env_script (printf '%s' 'unsetopt ZLE; unset RCS; unset GLOBAL_RCS; WARP_SESSION_ID='$remote_session_id'; WARP_USING_WINDOWS_CON_PTY=@@USING_CON_PTY_BOOLEAN@@; WARP_HONOR_PS1='$WARP_HONOR_PS1'; _hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || uname -n); _user=$(command -pv whoami >/dev/null 2>&1 && command -p whoami 2>/dev/null || echo $USER); _msg=$(printf "{\"hook\": \"InitShell\", \"value\": {\"session_id\": $WARP_SESSION_ID, \"shell\": \"zsh\", \"user\": \"%s\", \"hostname\": \"%s\"}}" "$_user" "$_hostname" | command -p od -An -v -tx1 | command -p tr -d " \n"); printf '"'"'\x1b\x50\x24\x64%s\x1b\x5c'"'"' $_msg; unset _hostname _user _msg' | command od -An -v -tx1 | command tr -d ' \n')
|
||||
|
||||
# Optionally attach to an existing ControlMaster the user already
|
||||
# runs for this destination instead of creating our own. Resolve
|
||||
# the user's configured ControlPath with `ssh -G` (which expands
|
||||
# tokens like %h/%p/%r/%C into a literal path), then verify the
|
||||
# master is alive with `ssh -O check`. Both probes are local-only
|
||||
# commands. On any failure we fall back to creating a Warp-owned
|
||||
# master, preserving the existing behavior.
|
||||
set -l control_path "$SSH_SOCKET_DIR/$WARP_SESSION_ID"
|
||||
set -l control_master_mode "yes"
|
||||
set -l external_control_master "false"
|
||||
if test "$WARP_SSH_REUSE_CONTROL_MASTER" = "1"
|
||||
set -l user_control_path (command ssh -G $argv 2>/dev/null | command sed -n 's/^controlpath //p')
|
||||
# Skip when no ControlPath is configured, and reject resolved
|
||||
# paths containing characters we cannot safely embed in the SSH
|
||||
# hook JSON below (e.g. an unexpanded % token, quotes, or
|
||||
# whitespace); in those cases fall back to a Warp-owned master.
|
||||
if test -n "$user_control_path"
|
||||
and test "$user_control_path" != "none"
|
||||
and string match --quiet --regex '^[A-Za-z0-9._/~@:+,-]+$' -- "$user_control_path"
|
||||
if command ssh -O check -o ControlPath="$user_control_path" $argv >/dev/null 2>&1
|
||||
# A live master exists: multiplex through it and let the
|
||||
# client know Warp does not own it.
|
||||
set control_path "$user_control_path"
|
||||
set control_master_mode "no"
|
||||
set external_control_master "true"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Note that in this command, we're passing a string to the remote shell. Any variable expansions need to be
|
||||
# escaped with "''" to avoid the local shell from expanding them before they're passed to the remote shell.
|
||||
@@ -609,14 +677,14 @@ if test "$WARP_IS_LOCAL_SHELL_SESSION" = "1"
|
||||
# determine what shell is the login shell on the remote machine. We perform a preliminary check to see if
|
||||
# the remote shell is the Bourne shell to avoid asking it to parse later lines that use syntax it doesn't
|
||||
# support.
|
||||
command ssh -o ControlMaster=yes -o ControlPath=$SSH_SOCKET_DIR/$WARP_SESSION_ID \
|
||||
command ssh -o ControlMaster=$control_master_mode -o ControlPath="$control_path" \
|
||||
-t $argv \
|
||||
"
|
||||
export TERM_PROGRAM='WarpTerminal'
|
||||
test -n '$WARP_CLIENT_VERSION' && export WARP_CLIENT_VERSION='$WARP_CLIENT_VERSION'
|
||||
# Only forward the protocol version if it was set locally (i.e. the HOANotifications feature flag is on).
|
||||
test -n '$WARP_CLI_AGENT_PROTOCOL_VERSION' && export WARP_CLI_AGENT_PROTOCOL_VERSION='$WARP_CLI_AGENT_PROTOCOL_VERSION'
|
||||
hook="'$(printf "{\"hook\": \"SSH\", \"value\": {\"socket_path\": \"'$SSH_SOCKET_DIR/$WARP_SESSION_ID'\", \"remote_shell\": \"%s\"}}" "${SHELL##*/}" | command od -An -v -tx1 | command tr -d " \n")'"
|
||||
hook="'$(printf "{\"hook\": \"SSH\", \"value\": {\"socket_path\": \"'$control_path'\", \"remote_shell\": \"%s\", \"session_id\": '"$WARP_SESSION_ID"', \"remote_session_id\": '"$remote_session_id"', \"external_control_master\": '"$external_control_master"'}}" "${SHELL##*/}" | command od -An -v -tx1 | command tr -d " \n")'"
|
||||
printf '$DCS_START$DCS_JSON_MARKER%s$DCS_END' "'$hook'"
|
||||
|
||||
if test "'"${SHELL##*/}" != "bash" -a "${SHELL##*/}" != "zsh"'"; then
|
||||
@@ -651,14 +719,14 @@ bash)
|
||||
stty raw
|
||||
HISTCONTROL=ignorespace
|
||||
HISTIGNORE=" *"
|
||||
WARP_SESSION_ID="$(command -p date +%s)$RANDOM"
|
||||
WARP_SESSION_ID='$remote_session_id'
|
||||
WARP_HONOR_PS1="'$WARP_HONOR_PS1'"
|
||||
_hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || uname -n)
|
||||
_user=$(command -pv whoami >/dev/null 2>&1 && command -p whoami 2>/dev/null || echo $USER)
|
||||
_msg=$(printf "{\"hook\": \"InitShell\", \"value\": {\"session_id\": $WARP_SESSION_ID, \"shell\": \"bash\", \"user\": \"%s\", \"hostname\": \"%s\"}}" "$_user" "$_hostname" | command -p od -An -v -tx1 | command -p tr -d " \n")'"
|
||||
WARP_USING_WINDOWS_CON_PTY=@@USING_CON_PTY_BOOLEAN@@
|
||||
if [[ "'$OS'" == Windows_NT ]]; then WARP_IN_MSYS2=true; else WARP_IN_MSYS2=false; fi
|
||||
printf '\''"'\eP$d%s\x9c'"'\'' \""'$_msg'"\"'
|
||||
printf '\''"'\x1b\x50\x24\x64%s\x1b\x5c'"'\'' \""'$_msg'"\"'
|
||||
unset _hostname _user _msg
|
||||
)
|
||||
;;
|
||||
@@ -683,7 +751,7 @@ esac
|
||||
|
||||
function ssh
|
||||
if is_interactive_ssh_session $argv
|
||||
warp_send_json_message '{"hook": "PreInteractiveSSHSession", "value": {}}'
|
||||
warp_send_json_message "{\"hook\": \"PreInteractiveSSHSession\", \"value\": {\"session_id\": $WARP_SESSION_ID}}"
|
||||
|
||||
if [ "$WARP_USE_SSH_WRAPPER" = "1" ]
|
||||
if test $WARP_SHELL_DEBUG_MODE
|
||||
|
||||
Reference in New Issue
Block a user