first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -12,8 +12,8 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
# Appended to $DCS_START to signal that the following message is JSON-encoded.
|
||||
DCS_JSON_MARKER="d"
|
||||
|
||||
# Byte used to signal the end of a DCS.
|
||||
DCS_END="$(printf '\x9c')"
|
||||
# Byte sequence used to signal the end of a DCS (7-bit ST: ESC \).
|
||||
DCS_END="$(printf '\x1b\x5c')"
|
||||
|
||||
OSC_START="$(printf '\e]9278;')"
|
||||
|
||||
@@ -280,10 +280,11 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
if [ "$WARP_IN_MSYS2" = true ]; then
|
||||
warp_send_hook_via_kv_pairs_start "Preexec"
|
||||
warp_send_hook_kv_pair "command" "$BASH_COMMAND"
|
||||
warp_send_hook_kv_pair "session_id" "$WARP_SESSION_ID"
|
||||
warp_send_hook_via_kv_pairs_end
|
||||
else
|
||||
local truncated_command=$(warp_escape_json "$BASH_COMMAND")
|
||||
warp_send_json_message "{\"hook\": \"Preexec\", \"value\": {\"command\": \"$truncated_command\"}}"
|
||||
warp_send_json_message "{\"hook\": \"Preexec\", \"value\": {\"command\": \"$truncated_command\", \"session_id\": $WARP_SESSION_ID}}"
|
||||
fi
|
||||
warp_maybe_send_reset_grid_osc
|
||||
|
||||
@@ -325,7 +326,7 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
|
||||
# If the array is not empty, kill the ongoing pids.
|
||||
if [[ ! -z $pids ]]; then
|
||||
# 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
|
||||
@@ -362,7 +363,7 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
fi
|
||||
|
||||
# Note that in older versions of bash (the one builtin with MacOS) the `~` character is just that,
|
||||
# howerver, when used within `""` (double quotes) on a newer (homebrew) bash version,
|
||||
# however, when used within `""` (double quotes) on a newer (homebrew) bash version,
|
||||
# it automatically EXPANDS to the actual value of $HOME and needs to be escaped to give a proper
|
||||
# tilde character. So instead, we have it as a separate variable that uses `''` (single quote)
|
||||
# to avoid expanding, and use it later within the new bash term title. This way both old and
|
||||
@@ -434,13 +435,15 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
# executed within this block instead of the actual last
|
||||
# command that was run.
|
||||
local exit_code=$?
|
||||
local next_block_id="precmd-$WARP_SESSION_ID-$((block_id++))"
|
||||
if [ "$WARP_IN_MSYS2" = true ]; then
|
||||
warp_send_hook_via_kv_pairs_start "CommandFinished"
|
||||
warp_send_hook_kv_pair "exit_code" "$exit_code"
|
||||
warp_send_hook_kv_pair "next_block_id" "precmd-$WARP_SESSION_ID-$((block_id++))"
|
||||
warp_send_hook_kv_pair "next_block_id" "$next_block_id"
|
||||
warp_send_hook_kv_pair "session_id" "$WARP_SESSION_ID"
|
||||
warp_send_hook_via_kv_pairs_end
|
||||
else
|
||||
warp_send_json_message "{\"hook\": \"CommandFinished\", \"value\": {\"exit_code\": $exit_code, \"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}}"
|
||||
fi
|
||||
|
||||
warp_maybe_send_reset_grid_osc
|
||||
@@ -463,6 +466,8 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
|
||||
unset _WARP_GENERATOR_COMMAND
|
||||
warp_send_json_message "{\"hook\": \"Precmd\", \"value\": {
|
||||
\"exit_code\": $exit_code,
|
||||
\"next_block_id\": \"$next_block_id\",
|
||||
\"pwd\": \"\",
|
||||
\"ps1\": \"\",
|
||||
\"git_head\": \"\",
|
||||
@@ -574,37 +579,56 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
escaped_conda_env=$(warp_escape_json "$CONDA_DEFAULT_ENV")
|
||||
fi
|
||||
|
||||
# Get Node.js version if node is available and we're in a Node.js project
|
||||
if command -v node > /dev/null 2>&1 && [ "$WARP_IN_MSYS2" = false ]; then
|
||||
# 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 [[ "$WARP_PROMPT_NODE_VERSION_ENABLED" != "0" ]] && command -v node > /dev/null 2>&1 && [ "$WARP_IN_MSYS2" = false ]; then
|
||||
# Check for package.json in current directory and parent directories
|
||||
local current_dir="$PWD"
|
||||
local found_package_json=false
|
||||
local package_json_dir=""
|
||||
while [[ "$current_dir" != "/" ]]; do
|
||||
while [[ -n "$current_dir" ]]; do
|
||||
if [[ -f "$current_dir/package.json" ]]; then
|
||||
found_package_json=true
|
||||
package_json_dir="$current_dir"
|
||||
break
|
||||
fi
|
||||
current_dir=$(dirname "$current_dir")
|
||||
[[ "$current_dir" == "/" ]] && break
|
||||
# Strip the last path segment without spawning `dirname`.
|
||||
current_dir="${current_dir%/*}"
|
||||
[[ -z "$current_dir" ]] && current_dir="/"
|
||||
done
|
||||
|
||||
# Only show node version if package.json is within a git repository
|
||||
if [[ "$found_package_json" = true ]]; then
|
||||
local git_dir="$package_json_dir"
|
||||
local in_git_repo=false
|
||||
while [[ "$git_dir" != "/" ]]; do
|
||||
while [[ -n "$git_dir" ]]; do
|
||||
if [[ -d "$git_dir/.git" ]]; then
|
||||
in_git_repo=true
|
||||
break
|
||||
fi
|
||||
git_dir=$(dirname "$git_dir")
|
||||
[[ "$git_dir" == "/" ]] && break
|
||||
git_dir="${git_dir%/*}"
|
||||
[[ -z "$git_dir" ]] && git_dir="/"
|
||||
done
|
||||
|
||||
if [[ "$in_git_repo" = true ]]; then
|
||||
local node_version=$(node --version 2>/dev/null)
|
||||
if [[ -n "$node_version" ]]; then
|
||||
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`). The cache vars are global (no `local`) so they
|
||||
# persist across precmd invocations.
|
||||
local node_cache_key="$PWD:$PATH"
|
||||
if [[ "$node_cache_key" == "$_WARP_NODE_VERSION_CACHE_KEY" ]]; then
|
||||
escaped_node_version="$_WARP_NODE_VERSION_CACHE_VALUE"
|
||||
else
|
||||
local node_version=$(node --version 2>/dev/null)
|
||||
if [[ -n "$node_version" ]]; then
|
||||
escaped_node_version=$(warp_escape_json "$node_version")
|
||||
fi
|
||||
_WARP_NODE_VERSION_CACHE_KEY="$node_cache_key"
|
||||
_WARP_NODE_VERSION_CACHE_VALUE="$escaped_node_version"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -649,6 +673,8 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
# We send the escaped PS1, if we are in active Warp prompt mode, for prompt preview rendering (note the shell's PS1 is unset in this case).
|
||||
if [ "$WARP_IN_MSYS2" = true ]; then
|
||||
warp_send_hook_via_kv_pairs_start "Precmd"
|
||||
warp_send_hook_kv_pair "exit_code" "$exit_code"
|
||||
warp_send_hook_kv_pair "next_block_id" "$next_block_id"
|
||||
warp_send_hook_kv_pair "pwd" "$PWD"
|
||||
warp_send_hook_kv_pair_escaped "ps1" "$deref_ps1"
|
||||
warp_send_hook_kv_pair "ps1_is_encoded" "false"
|
||||
@@ -662,6 +688,8 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
warp_send_hook_via_kv_pairs_end
|
||||
else
|
||||
local escaped_json="{\"hook\": \"Precmd\", \"value\": {
|
||||
\"exit_code\": $exit_code,
|
||||
\"next_block_id\": \"$next_block_id\",
|
||||
\"pwd\": \"$escaped_pwd\",
|
||||
\"ps1\": \"$escaped_ps1\",
|
||||
\"honor_ps1\": $honor_ps1,
|
||||
@@ -761,10 +789,11 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
if [ "$WARP_IN_MSYS2" = true ]; then
|
||||
warp_send_hook_via_kv_pairs_start "InputBuffer"
|
||||
warp_send_hook_kv_pair "buffer" "$READLINE_LINE"
|
||||
warp_send_hook_kv_pair "session_id" "$WARP_SESSION_ID"
|
||||
warp_send_hook_via_kv_pairs_end
|
||||
else
|
||||
local escaped_input="$(warp_escape_json "$READLINE_LINE")"
|
||||
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 } }"
|
||||
fi
|
||||
# This prevents bash from re-printing typeahead after we've removed it.
|
||||
READLINE_LINE=""
|
||||
@@ -888,9 +917,10 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
function clear() {
|
||||
if [ "$WARP_IN_MSYS2" = true ]; then
|
||||
warp_send_hook_via_kv_pairs_start "Clear"
|
||||
warp_send_hook_kv_pair "session_id" "$WARP_SESSION_ID"
|
||||
warp_send_hook_via_kv_pairs_end
|
||||
else
|
||||
warp_send_json_message "{\"hook\": \"Clear\", \"value\": {}}"
|
||||
warp_send_json_message "{\"hook\": \"Clear\", \"value\": {\"session_id\": $WARP_SESSION_ID}}"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -899,9 +929,10 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
if [ "$WARP_IN_MSYS2" = true ]; then
|
||||
warp_send_hook_via_kv_pairs_start "FinishUpdate"
|
||||
warp_send_hook_kv_pair "update_id" "$update_id"
|
||||
warp_send_hook_kv_pair "session_id" "$WARP_SESSION_ID"
|
||||
warp_send_hook_via_kv_pairs_end
|
||||
else
|
||||
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} }"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -972,11 +1003,51 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
function warp_ssh_helper() {
|
||||
init_shell_bash=$(init_shell_hook "bash")
|
||||
init_shell_zsh=$(init_shell_hook "zsh")
|
||||
local remote_session_id=$(command -p od -An -N8 -tu8 /dev/urandom 2>/dev/null | command -p tr -d ' \n')
|
||||
if [[ -z "$remote_session_id" || "$remote_session_id" == "0" ]]; then
|
||||
# If we cannot generate a non-zero random token, run plain SSH instead.
|
||||
command ssh "${@:1}"
|
||||
return
|
||||
fi
|
||||
|
||||
# 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
|
||||
local 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 || command -p 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 '"'"'\e]9278;d;%s\x07'"'"' $_msg; unset _hostname _user _msg' | command -p od -An -v -tx1 | command -p tr -d ' \n')
|
||||
local 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 || command -p 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 '"'"'\e]9278;d;%s\x07'"'"' $_msg; unset _hostname _user _msg' | command -p od -An -v -tx1 | command -p 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.
|
||||
local control_path="$SSH_SOCKET_DIR/$WARP_SESSION_ID"
|
||||
local control_master_mode="yes"
|
||||
local external_control_master="false"
|
||||
if [[ "$WARP_SSH_REUSE_CONTROL_MASTER" == "1" ]]; then
|
||||
local user_control_path=$(command ssh -G "${@:1}" 2>/dev/null | command -p sed -n 's/^controlpath //p')
|
||||
case "$user_control_path" in
|
||||
"" | none)
|
||||
# No ControlPath configured for this destination.
|
||||
;;
|
||||
*[![:alnum:]._/~@:+,-]*)
|
||||
# The resolved path contains characters we cannot safely
|
||||
# embed in the SSH hook JSON below (e.g. an unexpanded %
|
||||
# token, quotes, or whitespace); fall back to a
|
||||
# Warp-owned master.
|
||||
;;
|
||||
*)
|
||||
if command ssh -O check -o ControlPath="$user_control_path" "${@:1}" >/dev/null 2>&1; then
|
||||
# A live master exists: multiplex through it and let
|
||||
# the client know Warp does not own it.
|
||||
control_path="$user_control_path"
|
||||
control_master_mode="no"
|
||||
external_control_master="true"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Keep remote commands up-to-date with shell.rs & bash.sh.
|
||||
# Note that in this command, we're passing a string to the remote shell. Any variable expansions need to be
|
||||
@@ -985,7 +1056,7 @@ if [ -z "$WARP_BOOTSTRAPPED" ]; then
|
||||
# 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 "${@:1}" \
|
||||
"
|
||||
export TERM_PROGRAM='WarpTerminal'
|
||||
@@ -997,7 +1068,7 @@ test -n '$WARP_CLIENT_VERSION' && export WARP_CLIENT_VERSION='$WARP_CLIENT_VERSI
|
||||
# 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 -p od -An -v -tx1 | command -p 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 -p od -An -v -tx1 | command -p tr -d " \n")'"
|
||||
printf '$OSC_START$DCS_JSON_MARKER$OSC_PARAM_SEPARATOR%s$OSC_END' "'$hook'"
|
||||
|
||||
if test "'"${SHELL##*/}" != "bash" -a "${SHELL##*/}" != "zsh"'"; then
|
||||
@@ -1032,7 +1103,7 @@ case "'${SHELL##*/}'" in
|
||||
command -p 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 || command -p uname -n)
|
||||
_user=$(command -v whoami >/dev/null 2>&1 && command whoami 2>/dev/null || echo $USER)
|
||||
@@ -1063,7 +1134,7 @@ esac
|
||||
|
||||
function ssh() {
|
||||
if is_interactive_ssh_session "$@"; then
|
||||
warp_send_json_message "{\"hook\": \"PreInteractiveSSHSession\", \"value\": {}}"
|
||||
warp_send_json_message "{\"hook\": \"PreInteractiveSSHSession\", \"value\": {\"session_id\": $WARP_SESSION_ID}}"
|
||||
|
||||
# If the SSH wrapper is not enabled for this session, don't use it.
|
||||
if [ "$WARP_USE_SSH_WRAPPER" = "1" ]; then
|
||||
@@ -1133,17 +1204,22 @@ esac
|
||||
rcfiles_end_time="$(LC_ALL="C"; echo $EPOCHREALTIME)"
|
||||
fi
|
||||
|
||||
# Unset HISTFILESIZE if the user rcfiles didn't change it away from our
|
||||
# very large sentinel value. We need to set the initial value of HISTSIZE
|
||||
# to ensure that the user's history file doesn't get truncated when we spawn
|
||||
# the shell, but once bootstrap has completes, we want the value to be what
|
||||
# it would have been if we hadn't set an initial value.
|
||||
# Unset HISTFILESIZE and HISTSIZE if the user rcfiles didn't change them
|
||||
# away from our very large sentinel values. We need to set the initial
|
||||
# values to ensure that the user's history file and in-memory history list
|
||||
# don't get truncated when we spawn the shell, but once bootstrap has
|
||||
# completed, we want the values to be what they would have been if we hadn't
|
||||
# set initial values.
|
||||
#
|
||||
# For more context, see: https://github.com/warpdotdev/Warp/issues/1262
|
||||
if [[ $HISTFILESIZE == $WARP_INITIAL_HISTFILESIZE ]]; then
|
||||
unset HISTFILESIZE
|
||||
fi
|
||||
unset WARP_INITIAL_HISTFILESIZE
|
||||
if [[ $HISTSIZE == $WARP_INITIAL_HISTSIZE ]]; then
|
||||
unset HISTSIZE
|
||||
fi
|
||||
unset WARP_INITIAL_HISTSIZE
|
||||
|
||||
# Save the value of HISTCONTROL as it existed just after reading the user's
|
||||
# rcfiles.
|
||||
@@ -1318,6 +1394,7 @@ esac
|
||||
warp_send_hook_kv_pair "user" "$_user"
|
||||
warp_send_hook_kv_pair "hostname" "$_hostname"
|
||||
warp_send_hook_kv_pair "path" "$PATH"
|
||||
warp_send_hook_kv_pair "cdpath" "$CDPATH"
|
||||
warp_send_hook_kv_pair_escaped "env_var_names" "$env_var_names"
|
||||
warp_send_hook_kv_pair "abbreviations" ""
|
||||
warp_send_hook_kv_pair_escaped "aliases" "$aliases"
|
||||
@@ -1338,7 +1415,8 @@ esac
|
||||
else
|
||||
local escaped_editor="$(warp_escape_json "$EDITOR")"
|
||||
local escaped_shell_path="$(warp_escape_json "$BASH")"
|
||||
local escaped_json="{\"hook\": \"Bootstrapped\", \"value\": {\"histfile\": \"$escaped_histfile\", \"session_id\": $WARP_SESSION_ID, \"shell\": \"bash\", \"home_dir\": \"$HOME\", \"user\":\"$_user\", \"host\":\"$_hostname\", \"path\": \"$escaped_path\", \"editor\": \"$escaped_editor\", \"env_var_names\": \"$escaped_env_var_names\", \"abbreviations\": \"$escaped_abbrs\", \"aliases\": \"$escaped_aliases\", \"function_names\": \"$escaped_function_names\", \"builtins\": \"$escaped_builtins\", \"keywords\": \"$escaped_keywords\", \"shell_version\": \"$BASH_VERSION\", \"shell_options\": \"$escaped_shell_options\", \"rcfiles_start_time\": \"$rcfiles_start_time\", \"rcfiles_end_time\": \"$rcfiles_end_time\", \"vi_mode_enabled\": \"$vi_mode_enabled\", \"os_category\": \"$os_category\", \"linux_distribution\": \"$linux_distribution\", \"wsl_name\": \"$WSL_DISTRO_NAME\", \"shell_path\": \"$escaped_shell_path\"}}"
|
||||
local escaped_cdpath="$(warp_escape_json "$CDPATH")"
|
||||
local escaped_json="{\"hook\": \"Bootstrapped\", \"value\": {\"histfile\": \"$escaped_histfile\", \"session_id\": $WARP_SESSION_ID, \"shell\": \"bash\", \"home_dir\": \"$HOME\", \"user\":\"$_user\", \"host\":\"$_hostname\", \"path\": \"$escaped_path\", \"cdpath\": \"$escaped_cdpath\", \"editor\": \"$escaped_editor\", \"env_var_names\": \"$escaped_env_var_names\", \"abbreviations\": \"$escaped_abbrs\", \"aliases\": \"$escaped_aliases\", \"function_names\": \"$escaped_function_names\", \"builtins\": \"$escaped_builtins\", \"keywords\": \"$escaped_keywords\", \"shell_version\": \"$BASH_VERSION\", \"shell_options\": \"$escaped_shell_options\", \"rcfiles_start_time\": \"$rcfiles_start_time\", \"rcfiles_end_time\": \"$rcfiles_end_time\", \"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"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
command -p stty raw
|
||||
HISTCONTROL=ignorespace
|
||||
HISTIGNORE=" *"
|
||||
WARP_SESSION_ID="$(command -p date +%s)$RANDOM"
|
||||
WARP_SESSION_ID=@@WARP_SESSION_ID@@
|
||||
_hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || command -p uname -n)
|
||||
_user=$(command -pv whoami >/dev/null 2>&1 && command -p whoami 2>/dev/null || echo $USER)
|
||||
if [[ "$OS" == Windows_NT ]]; then WARP_IN_MSYS2=true; else WARP_IN_MSYS2=false; fi
|
||||
@@ -11,5 +11,5 @@ if [[ "$OS" == Windows_NT ]]; then WARP_IN_MSYS2=true; else WARP_IN_MSYS2=false;
|
||||
if [ "$WARP_IN_MSYS2" = true ]; then _msg="\e]9278;k;A;InitShell\a\e]9278;k;B;session_id;$WARP_SESSION_ID\a\e]9278;k;B;shell;bash\a\e]9278;k;B;user;$_user\a\e]9278;k;B;hostname;$_hostname\a\e]9278;k;C\a"; else _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"); fi
|
||||
WARP_USING_WINDOWS_CON_PTY=@@USING_CON_PTY_BOOLEAN@@
|
||||
# We send the InitShell hook via OSCs when on Windows and via DCSs otherwise.
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then if [ "$WARP_IN_MSYS2" = true ]; then printf "$_msg"; else printf '\e]9278;d;%s\x07' "$_msg"; fi; else printf '\e\x50\x24\x64%s\x9c' "$_msg"; fi
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then if [ "$WARP_IN_MSYS2" = true ]; then printf "$_msg"; else printf '\e]9278;d;%s\x07' "$_msg"; fi; else printf '\x1b\x50\x24\x64%s\x1b\x5c' "$_msg"; fi
|
||||
unset _hostname _user _msg
|
||||
|
||||
@@ -5,11 +5,11 @@ unset PROMPT_COMMAND
|
||||
HISTCONTROL=ignorespace
|
||||
HISTIGNORE=" *"
|
||||
WARP_IS_SUBSHELL=1
|
||||
WARP_SESSION_ID="$(command -p date +%s)$RANDOM"
|
||||
WARP_SESSION_ID=@@WARP_SESSION_ID@@
|
||||
_hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || command -p 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\", \"is_subshell\": true}}" "$_user" "$_hostname" | command -p od -An -v -tx1 | command -p tr -d " \n")
|
||||
if [[ "$OS" == Windows_NT ]]; then WARP_IN_MSYS2=true; else WARP_IN_MSYS2=false; fi
|
||||
WARP_USING_WINDOWS_CON_PTY=@@USING_CON_PTY_BOOLEAN@@
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then printf '\e]9278;d;%s\x07' "$_msg"; else printf '\e\x50\x24\x64%s\x9c' "$_msg"; fi
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then printf '\e]9278;d;%s\x07' "$_msg"; else printf '\x1b\x50\x24\x64%s\x1b\x5c' "$_msg"; fi
|
||||
unset _hostname _user _msg
|
||||
|
||||
@@ -1 +1 @@
|
||||
echo -e '\n# Auto-Warpify\n[[ "$-" == *i* ]] && printf '\''\eP$f{"hook": "SourcedRcFileForWarp", "value": { "shell": "%", "uname": "'$(uname)'"% }}\x9c'\'' ' >> %
|
||||
echo -e '\n# Auto-Warpify\n[[ "$-" == *i* ]] && printf '\''\eP$f{"hook": "SourcedRcFileForWarp", "value": { "shell": "%", "uname": "'$(uname)'" }}\x1b\x5c'\'' ' >> %
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
set -g WARP_SESSION_ID (random)
|
||||
set -g WARP_SESSION_ID @@WARP_SESSION_ID@@
|
||||
set _hostname (command -v hostname >/dev/null 2>&1 && command hostname 2>/dev/null || uname -n)
|
||||
set _user (command -v whoami >/dev/null 2>&1 && command whoami 2>/dev/null || echo $USER)
|
||||
set -g WARP_IN_MSYS2 (test "$OS" = Windows_NT; and echo true; or echo false)
|
||||
if test "$WARP_IN_MSYS2" = true; set _msg "\e]9278;k;A;InitShell\a\e]9278;k;B;session_id;$WARP_SESSION_ID\a\e]9278;k;B;shell;fish\a\e]9278;k;B;user;$_user\a\e]9278;k;B;hostname;$_hostname\a\e]9278;k;C\a"; else; set _msg (printf "{\"hook\": \"InitShell\", \"value\": {\"session_id\": $WARP_SESSION_ID, \"shell\": \"fish\", \"user\": \"%s\", \"hostname\": \"%s\"}}" "$_user" "$_hostname" | command od -An -v -tx1 | command tr -d " \n"); end
|
||||
set WARP_USING_WINDOWS_CON_PTY @@USING_CON_PTY_BOOLEAN@@
|
||||
# We send the InitShell hook via OSCs when on Windows and via DCSs otherwise.
|
||||
if test "$WARP_USING_WINDOWS_CON_PTY" = true; if test "$WARP_IN_MSYS2" = true; printf "$_msg"; else; printf '\e]9278;d;%s\x07' "$_msg"; end; else; printf '\e\x50\x24\x64%s\x9c' "$_msg"; end
|
||||
if test "$WARP_USING_WINDOWS_CON_PTY" = true; if test "$WARP_IN_MSYS2" = true; printf "$_msg"; else; printf '\e]9278;d;%s\x07' "$_msg"; end; else; printf '\x1b\x50\x24\x64%s\x1b\x5c' "$_msg"; end
|
||||
set -e _hostname _user _msg
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
set -g WARP_SESSION_ID (random)
|
||||
set -g WARP_SESSION_ID @@WARP_SESSION_ID@@
|
||||
set _hostname (command -v hostname >/dev/null 2>&1 && command hostname 2>/dev/null || uname -n)
|
||||
set _user (command -v whoami >/dev/null 2>&1 && command whoami 2>/dev/null || echo $USER)
|
||||
set -g WARP_IN_MSYS2 (test "$OS" = Windows_NT; and echo true; or echo false)
|
||||
if test "$WARP_IN_MSYS2" = true; set _msg "\e]9278;k;A;InitShell\a\e]9278;k;B;session_id;$WARP_SESSION_ID\a\e]9278;k;B;shell;fish\a\e]9278;k;B;user;$_user\a\e]9278;k;B;hostname;$_hostname\a\e]9278;k;B;is_subshell;true\a\e]9278;k;C\a"; else; set _msg (printf "{\"hook\": \"InitShell\", \"value\": {\"session_id\": $WARP_SESSION_ID, \"user\": \"%s\", \"hostname\": \"%s\", \"shell\": \"fish\", \"is_subshell\": true, \"wsl_name\": \"$WSL_DISTRO_NAME\"}}" "$_user" "$_hostname" | command od -An -v -tx1 | command tr -d " \n"); end
|
||||
set WARP_USING_WINDOWS_CON_PTY @@USING_CON_PTY_BOOLEAN@@
|
||||
if test "$WARP_USING_WINDOWS_CON_PTY" = true; if test "$WARP_IN_MSYS2" = true; printf "$_msg"; else; printf '\e]9278;d;%s\x07' "$_msg"; end; else; printf '\e\x50\x24\x64%s\x9c' "$_msg"; end
|
||||
if test "$WARP_USING_WINDOWS_CON_PTY" = true; if test "$WARP_IN_MSYS2" = true; printf "$_msg"; else; printf '\e]9278;d;%s\x07' "$_msg"; end; else; printf '\x1b\x50\x24\x64%s\x1b\x5c' "$_msg"; end
|
||||
set -e _hostname _user _msg
|
||||
|
||||
@@ -1 +1 @@
|
||||
echo -e '\n# Auto-Warpify\nstatus --is-interactive; and printf '\''\eP$f{"hook": "SourcedRcFileForWarp", "value": { "shell": "%", "uname": "'$(uname)'"% }}\x9c'\'' ' >> %
|
||||
echo -e '\n# Auto-Warpify\nstatus --is-interactive; and printf '\''\eP$f{"hook": "SourcedRcFileForWarp", "value": { "shell": "%", "uname": "'$(uname)'" }}\x1b\x5c'\'' ' >> %
|
||||
|
||||
@@ -142,9 +142,27 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
(Get-Variable | Select-Object -ExpandProperty Name) -join ' '
|
||||
$aliasesRaw = Get-Command -CommandType Alias | Select-Object -ExpandProperty DisplayName
|
||||
$aliases = $aliasesRaw -join [Environment]::NewLine
|
||||
$functionNamesRaw = Get-Command -CommandType Function | Where-Object { -not $_.Name.StartsWith('Warp') } | Select-Object -ExpandProperty Name
|
||||
# Only query modules that ship with PowerShell itself. This keeps bootstrap fast by
|
||||
# avoiding Windows system modules and third-party modules from the Gallery. The rest are
|
||||
# loaded asynchronously later.
|
||||
$corePsModules = @(
|
||||
'Microsoft.PowerShell.*', # All built-in PS modules (cross-platform)
|
||||
'Microsoft.WSMan.*', # WS-Management (Windows PS)
|
||||
'CimCmdlets', # CIM/WMI (Windows)
|
||||
'PackageManagement', # Package management
|
||||
'PowerShellGet', # Package get
|
||||
'PSReadLine', # Line editor bundled with PS
|
||||
'ThreadJob', # Thread jobs (PS 7)
|
||||
'PSDiagnostics', # PS diagnostics
|
||||
'PSDesiredStateConfiguration', # DSC (Windows PS)
|
||||
'PSWorkflow', # Legacy workflow (Windows PS 5)
|
||||
'PSWorkflowUtility' # Legacy workflow utility (Windows PS 5)
|
||||
)
|
||||
$functionNamesRaw = Get-Command -CommandType Function -Module $corePsModules |
|
||||
Where-Object { -not $_.Name.StartsWith('Warp') } |
|
||||
Select-Object -ExpandProperty Name
|
||||
$functionNames = $functionNamesRaw -join [Environment]::NewLine
|
||||
$builtinsRaw = Get-Command -CommandType Cmdlet | Select-Object -ExpandProperty Name
|
||||
$builtinsRaw = Get-Command -CommandType Cmdlet -Module $corePsModules | Select-Object -ExpandProperty Name
|
||||
$builtins = $builtinsRaw -join [Environment]::NewLine
|
||||
$shellVersion = $PSVersionTable.PSVersion.ToString()
|
||||
# PowerShell wasn't cross-platform until version 6. Anything before that is definitely on Windows.
|
||||
@@ -200,6 +218,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$bootstrappedMsg = @{
|
||||
hook = 'Bootstrapped'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
histfile = $(Get-PSReadLineOption).HistorySavePath
|
||||
shell = 'pwsh'
|
||||
home_dir = "$HOME"
|
||||
@@ -230,6 +249,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$preexecMsg = @{
|
||||
hook = 'Preexec'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
command = $command
|
||||
}
|
||||
}
|
||||
@@ -243,7 +263,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
}
|
||||
|
||||
# Clean up any completed warp jobs so they do not show up on the user's 'get-job'
|
||||
# comands
|
||||
# commands
|
||||
Warp-Clean-CompletedThread
|
||||
|
||||
# Remove any instance of the 'Warp-Run-GeneratorCommand' call from the user's history
|
||||
@@ -254,6 +274,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$updateMsg = @{
|
||||
hook = 'FinishUpdate'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
update_id = $updateId
|
||||
}
|
||||
}
|
||||
@@ -288,7 +309,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
# 2. We need to make sure that we are calling the Application git, and not
|
||||
# an alias or cmdlet named Git
|
||||
#
|
||||
# NOTE: Inlining this call in the function has a weird side effect of outputing
|
||||
# NOTE: Inlining this call in the function has a weird side effect of outputting
|
||||
# an escape sequence '^[i'. Since it made it more convenient to have a wrapper
|
||||
# function anyway, I have not investigated this, but in case someone is working
|
||||
# on this in the future, beware attempting to inline this function.
|
||||
@@ -344,6 +365,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$inputBufferMsg = @{
|
||||
hook = 'InputBuffer'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
buffer = $inputBuffer
|
||||
}
|
||||
}
|
||||
@@ -386,7 +408,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
Warp-Disable-PSPrediction
|
||||
}
|
||||
|
||||
# Force use of the Inline PredictionViewStyle. The ListView style can occassionally cause some
|
||||
# Force use of the Inline PredictionViewStyle. The ListView style can occasionally cause some
|
||||
# flickering when using Warp and it doesn't matter what the value of this setting is because
|
||||
# Warp has its own input editor.
|
||||
function Warp-Disable-PSPrediction {
|
||||
@@ -434,11 +456,13 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$HOST.UI.RawUI.WindowTitle = $newTitle
|
||||
|
||||
$blockId = $script:nextBlockId++
|
||||
$nextBlockId = "precmd-${global:_warpSessionId}-$blockId"
|
||||
$commandFinishedMsg = @{
|
||||
hook = 'CommandFinished'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
exit_code = $exitCode
|
||||
next_block_id = "precmd-${global:_warpSessionId}-$blockId"
|
||||
next_block_id = $nextBlockId
|
||||
}
|
||||
}
|
||||
Warp-Send-JsonMessage $commandFinishedMsg
|
||||
@@ -457,6 +481,8 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$precmdMsg = @{
|
||||
hook = 'Precmd'
|
||||
value = @{
|
||||
exit_code = $exitCode
|
||||
next_block_id = $nextBlockId
|
||||
pwd = ''
|
||||
ps1 = ''
|
||||
git_head = ''
|
||||
@@ -493,39 +519,52 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$kubeConfig = $env:KUBECONFIG
|
||||
}
|
||||
|
||||
# Compute Node.js version if node is available and we're in a Node project within a Git repo.
|
||||
$hasNodeCommand = Get-Command -CommandType Application node 2>$null
|
||||
# Compute the Node.js version only when the Node.js Version chip is enabled
|
||||
# (WARP_PROMPT_NODE_VERSION_ENABLED is '0' when the chip is not shown; default
|
||||
# enabled when unset) and node is available. Cache the result keyed on the
|
||||
# current location + PATH so we only spawn node when the directory or PATH
|
||||
# changes (PATH changes on version-manager switches like `nvm use`).
|
||||
$nodeChipEnabled = "$env:WARP_PROMPT_NODE_VERSION_ENABLED" -ne '0'
|
||||
$hasNodeCommand = if ($nodeChipEnabled) { Get-Command -CommandType Application node 2>$null } else { $null }
|
||||
if ($hasNodeCommand) {
|
||||
try {
|
||||
# Walk up from the current directory to find a package.json
|
||||
$dir = Get-Item -LiteralPath (Get-Location).Path
|
||||
$foundPackageJson = $false
|
||||
$packageJsonDir = $null
|
||||
while ($null -ne $dir) {
|
||||
$candidate = Join-Path $dir.FullName 'package.json'
|
||||
if (Test-Path -LiteralPath $candidate) {
|
||||
$foundPackageJson = $true
|
||||
$packageJsonDir = $dir.FullName
|
||||
break
|
||||
}
|
||||
$dir = $dir.Parent
|
||||
}
|
||||
|
||||
if ($foundPackageJson) {
|
||||
# Verify package.json resides within a Git repository by walking up to find a .git directory
|
||||
$probe = Get-Item -LiteralPath $packageJsonDir
|
||||
$inGitRepo = $false
|
||||
while ($null -ne $probe) {
|
||||
if (Test-Path -LiteralPath (Join-Path $probe.FullName '.git')) {
|
||||
$inGitRepo = $true
|
||||
$nodeCacheKey = "$((Get-Location).Path)|$env:PATH"
|
||||
if ($nodeCacheKey -eq $script:warpNodeVersionCacheKey) {
|
||||
$nodeVersion = $script:warpNodeVersionCacheValue
|
||||
} else {
|
||||
# Walk up from the current directory to find a package.json
|
||||
$dir = Get-Item -LiteralPath (Get-Location).Path
|
||||
$foundPackageJson = $false
|
||||
$packageJsonDir = $null
|
||||
while ($null -ne $dir) {
|
||||
$candidate = Join-Path $dir.FullName 'package.json'
|
||||
if (Test-Path -LiteralPath $candidate) {
|
||||
$foundPackageJson = $true
|
||||
$packageJsonDir = $dir.FullName
|
||||
break
|
||||
}
|
||||
$probe = $probe.Parent
|
||||
$dir = $dir.Parent
|
||||
}
|
||||
|
||||
if ($inGitRepo) {
|
||||
$nodeVersion = Warp-TryGet-NodeVersion
|
||||
if ($foundPackageJson) {
|
||||
# Verify package.json resides within a Git repository by walking up to find a .git directory
|
||||
$probe = Get-Item -LiteralPath $packageJsonDir
|
||||
$inGitRepo = $false
|
||||
while ($null -ne $probe) {
|
||||
if (Test-Path -LiteralPath (Join-Path $probe.FullName '.git')) {
|
||||
$inGitRepo = $true
|
||||
break
|
||||
}
|
||||
$probe = $probe.Parent
|
||||
}
|
||||
|
||||
if ($inGitRepo) {
|
||||
$nodeVersion = Warp-TryGet-NodeVersion
|
||||
}
|
||||
}
|
||||
|
||||
$script:warpNodeVersionCacheKey = $nodeCacheKey
|
||||
$script:warpNodeVersionCacheValue = $nodeVersion
|
||||
}
|
||||
} catch {
|
||||
# Log at verbose level so the catch block is not empty and diagnostics are available when needed.
|
||||
@@ -558,6 +597,8 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$precmdMsg = @{
|
||||
hook = 'Precmd'
|
||||
value = @{
|
||||
exit_code = $exitCode
|
||||
next_block_id = $nextBlockId
|
||||
pwd = (Get-Location).Path
|
||||
# TODO(PLAT-687) - honor the PS1
|
||||
ps1 = ''
|
||||
@@ -896,7 +937,9 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
function Clear-Host() {
|
||||
$inputBufferMsg = @{
|
||||
hook = 'Clear'
|
||||
value = @{}
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
}
|
||||
}
|
||||
Warp-Send-JsonMessage $inputBufferMsg
|
||||
}
|
||||
@@ -904,7 +947,9 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
function clear() {
|
||||
$inputBufferMsg = @{
|
||||
hook = 'Clear'
|
||||
value = @{}
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
}
|
||||
}
|
||||
Warp-Send-JsonMessage $inputBufferMsg
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ function prompt {
|
||||
# Reset the prompt back to the default to avoid infinite loops if sourcing the bootstrap script has an error.
|
||||
$function:global:prompt = $global:_warpOriginalPrompt
|
||||
$username = [Environment]::UserName
|
||||
$epoch = [int](New-TimeSpan -Start ([DateTime]::new(1970, 1, 1, 0, 0, 0, 0)) -End ([DateTime]::UtcNow)).TotalSeconds
|
||||
$random = Get-Random -Maximum 32768
|
||||
$global:_warpSessionId = [int64]"$epoch$random"
|
||||
$global:_warpSessionId = [uint64]@@WARP_SESSION_ID@@
|
||||
$msg = ConvertTo-Json -Compress -InputObject @{ hook = 'InitShell'; value = @{ session_id = $_warpSessionId; shell = 'pwsh'; user = $username; hostname = [System.Net.Dns]::GetHostName() } }
|
||||
$encodedMsg = [BitConverter]::ToString([System.Text.Encoding]::UTF8.GetBytes($msg)).Replace('-', '')
|
||||
$oscStart = "$([char]0x1b)]9278;"
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
# Thankfully, we don't need curly braces around the first expression, so we can put the fish check
|
||||
# first and it early exits. This runs correctly in sh, bash, zsh, and fish.
|
||||
# Replace `HOOK_NAME` with the appropriate hook name.
|
||||
[ -z $WARP_BOOTSTRAPPED ] && printf "\\e]9278;f;{\"hook\": \"HOOK_NAME\", \"value\": { \"shell\": \"%s\", \"uname\": \"%s\" }}\\a" $([ $FISH_VERSION ] && echo "fish" || { echo $0 | command -p grep -q zsh && echo "zsh"; } || { echo $0 | command -p grep -q bash && echo "bash"; } || echo "unknown") $(uname)
|
||||
[ -z $WARP_BOOTSTRAPPED ] && printf "\\e]9278;f;{\"hook\": \"HOOK_NAME\", \"value\": { \"shell\": \"%s\", \"uname\": \"%s\", \"session_id\": @@WARP_SESSION_ID@@ }}\\a" $([ $FISH_VERSION ] && echo "fish" || { echo $0 | command -p grep -q zsh && echo "zsh"; } || { echo $0 | command -p grep -q bash && echo "bash"; } || echo "unknown") $(uname)
|
||||
|
||||
@@ -21,8 +21,8 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
# Appended to $DCS_START to signal that the following message is JSON-encoded.
|
||||
DCS_JSON_MARKER="d"
|
||||
|
||||
# Byte used to signal the end of a DCS.
|
||||
DCS_END="$(printf '\x9c')"
|
||||
# Byte sequence used to signal the end of a DCS (7-bit ST: ESC \).
|
||||
DCS_END="$(printf '\x1b\x5c')"
|
||||
|
||||
# OSC used to mark the start of in-band command output.
|
||||
#
|
||||
@@ -168,14 +168,14 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
local -a command
|
||||
command=("${@:2}")
|
||||
# Declare raw_output prior to actually assigning it, because `local` is a command itself, which
|
||||
# inteferes with capturing the exit code via $? (it overwrites $? with the 0, because the
|
||||
# interferes with capturing the exit code via $? (it overwrites $? with the 0, because the
|
||||
# 'local' command always succeeds).
|
||||
local raw_output
|
||||
# Command substitution only captures stdout, so redirect stderr to stdout.
|
||||
# Note that we use `eval` here to actually execute the command, because some shell syntax
|
||||
# that may be used in the command might not be valid in a command substitution (e.g. the
|
||||
# '$(<command>)' syntax).
|
||||
# Also note that zsh variables can contain null charcters, so this doesn't require any special
|
||||
# Also note that zsh variables can contain null characters, so this doesn't require any special
|
||||
# handling.
|
||||
raw_output=$(eval "$command" 2>&1)
|
||||
local exit_code=$?
|
||||
@@ -253,7 +253,7 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
# invoke any external commands in here.
|
||||
warp_preexec () {
|
||||
local warp_escaped_command="$(warp_escape_json $1)"
|
||||
warp_send_json_message "{\"hook\": \"Preexec\", \"value\": {\"command\": \"$warp_escaped_command\"}}"
|
||||
warp_send_json_message "{\"hook\": \"Preexec\", \"value\": {\"command\": \"$warp_escaped_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 and clean
|
||||
@@ -277,7 +277,7 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
|
||||
# If the array is not empty, kill the ongoing pids.
|
||||
if [[ ! -z $pids ]]; then
|
||||
# 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 2>&1) >/dev/null
|
||||
@@ -306,8 +306,9 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
# previously run user command (as opposed to any of the commands executed
|
||||
# in this function below).
|
||||
local exit_code=$?
|
||||
local next_block_id="precmd-$WARP_SESSION_ID-$((block_id++))"
|
||||
|
||||
warp_send_json_message "{\"hook\": \"CommandFinished\", \"value\": {\"exit_code\": $exit_code, \"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
|
||||
|
||||
# If this is being called for a generator command, short circuit and send an unpopulated
|
||||
@@ -320,6 +321,8 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
|
||||
_WARP_GENERATOR_COMMAND=""
|
||||
warp_send_json_message "{\"hook\": \"Precmd\", \"value\": {
|
||||
\"exit_code\": $exit_code,
|
||||
\"next_block_id\": \"$next_block_id\",
|
||||
\"pwd\": \"\",
|
||||
\"ps1\": \"\",
|
||||
\"git_head\": \"\",
|
||||
@@ -394,37 +397,56 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
escaped_conda_env=$(warp_escape_json $CONDA_DEFAULT_ENV)
|
||||
fi
|
||||
|
||||
# Get Node.js version if node is available and we're in a Node.js project
|
||||
if command -v node > /dev/null 2>&1; then
|
||||
# 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 [[ "$WARP_PROMPT_NODE_VERSION_ENABLED" != "0" ]] && command -v node > /dev/null 2>&1; then
|
||||
# Check for package.json in current directory and parent directories
|
||||
local current_dir="$PWD"
|
||||
local found_package_json=false
|
||||
local package_json_dir=""
|
||||
while [[ "$current_dir" != "/" ]]; do
|
||||
while [[ -n "$current_dir" ]]; do
|
||||
if [[ -f "$current_dir/package.json" ]]; then
|
||||
found_package_json=true
|
||||
package_json_dir="$current_dir"
|
||||
break
|
||||
fi
|
||||
current_dir=$(dirname "$current_dir")
|
||||
[[ "$current_dir" == "/" ]] && break
|
||||
# Strip the last path segment without spawning `dirname`.
|
||||
current_dir="${current_dir%/*}"
|
||||
[[ -z "$current_dir" ]] && current_dir="/"
|
||||
done
|
||||
|
||||
# Only show node version if package.json is within a git repository
|
||||
if [[ "$found_package_json" = true ]]; then
|
||||
local git_dir="$package_json_dir"
|
||||
local in_git_repo=false
|
||||
while [[ "$git_dir" != "/" ]]; do
|
||||
while [[ -n "$git_dir" ]]; do
|
||||
if [[ -d "$git_dir/.git" ]]; then
|
||||
in_git_repo=true
|
||||
break
|
||||
fi
|
||||
git_dir=$(dirname "$git_dir")
|
||||
[[ "$git_dir" == "/" ]] && break
|
||||
git_dir="${git_dir%/*}"
|
||||
[[ -z "$git_dir" ]] && git_dir="/"
|
||||
done
|
||||
|
||||
if [[ "$in_git_repo" = true ]]; then
|
||||
local node_version=$(node --version 2>/dev/null)
|
||||
if [[ -n "$node_version" ]]; then
|
||||
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`). The cache vars are global (no `local`) so they
|
||||
# persist across precmd invocations.
|
||||
local node_cache_key="$PWD:$PATH"
|
||||
if [[ "$node_cache_key" == "$_WARP_NODE_VERSION_CACHE_KEY" ]]; then
|
||||
escaped_node_version="$_WARP_NODE_VERSION_CACHE_VALUE"
|
||||
else
|
||||
local node_version=$(node --version 2>/dev/null)
|
||||
if [[ -n "$node_version" ]]; then
|
||||
escaped_node_version=$(warp_escape_json "$node_version")
|
||||
fi
|
||||
_WARP_NODE_VERSION_CACHE_KEY="$node_cache_key"
|
||||
_WARP_NODE_VERSION_CACHE_VALUE="$escaped_node_version"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -461,6 +483,8 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
fi
|
||||
|
||||
local escaped_json="{\"hook\": \"Precmd\", \"value\": {
|
||||
\"exit_code\": $exit_code,
|
||||
\"next_block_id\": \"$next_block_id\",
|
||||
\"pwd\": \"$escaped_pwd\",
|
||||
\"ps1\": \"\",
|
||||
\"honor_ps1\": $honor_ps1,
|
||||
@@ -622,19 +646,19 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
|
||||
function warp_report_input {
|
||||
local escaped_input="$(warp_escape_json "$BUFFER")"
|
||||
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 zsh from printing typeahead as background output after we've fetched it.
|
||||
BUFFER=""
|
||||
}
|
||||
zle -N warp_report_input
|
||||
|
||||
function clear() {
|
||||
warp_send_json_message "{\"hook\": \"Clear\", \"value\": {}}"
|
||||
warp_send_json_message "{\"hook\": \"Clear\", \"value\": {\"session_id\": $WARP_SESSION_ID}}"
|
||||
}
|
||||
|
||||
function warp_finish_update {
|
||||
local update_id="$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} }"
|
||||
}
|
||||
|
||||
# Check if the warp apt source file has been renamed to `warpdotdev.list.distUpgrade` due to an ubuntu version update.
|
||||
@@ -661,6 +685,21 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
fi
|
||||
}
|
||||
|
||||
# Strips prompt constructs that zsh counts as visible "glitch" columns even
|
||||
# when they appear inside a %{...%} zero-width region, returning the result
|
||||
# in $REPLY. The explicit-width form %n{ is rewritten to %{ (preserving the
|
||||
# brace pairing), and the %G, %nG, and %-nG forms are removed entirely.
|
||||
# Neither change affects the rendered prompt bytes, only zsh's internal
|
||||
# width accounting. Literal %% escapes are matched first so that they cannot
|
||||
# form false positives (e.g. %%1{ renders as literal text and must be left
|
||||
# alone).
|
||||
function warp_strip_glitch_width_constructs() {
|
||||
setopt localoptions extendedglob
|
||||
local match mbegin mend
|
||||
REPLY=${1:-}
|
||||
REPLY=${REPLY//(#b)(%%|%<->\{|%(-|)(<->|)G)/${${match[1]:#%(-|)(<->|)G}/(#s)%<->\{(#e)/%\{}}
|
||||
}
|
||||
|
||||
# Check whether the prompt-related variables have OSC prompt marker sequences,
|
||||
# and if not, wrap them with the appropriate markers so that we can direct the
|
||||
# prompt bytes to the appropriate grids.
|
||||
@@ -712,7 +751,7 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
# markers. If they exist, we remove the first occurrence of the prefix
|
||||
# and the last occurrence of the suffix, which should be the ones that
|
||||
# Warp has added, to avoid duplicating the prefix and suffix. Shell
|
||||
# parameter expansion is used to remove the first and last occurences.
|
||||
# parameter expansion is used to remove the first and last occurrences.
|
||||
# Specifically note that virtualenvs can add content to the prompt, so we need to
|
||||
# remove the markers before re-adding them.
|
||||
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
|
||||
@@ -742,7 +781,21 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
PROMPT=$preceding_suffix$following_suffix
|
||||
fi
|
||||
|
||||
ORIGINAL_PROMPT=$PROMPT
|
||||
# If the prompt we extracted is exactly the glitch-stripped value that we
|
||||
# installed on a previous refresh, keep the existing ORIGINAL_PROMPT: it
|
||||
# holds the pristine value, whose width annotations are still needed if
|
||||
# we later switch to honoring the PS1.
|
||||
if [[ "$PROMPT" != "${WARP_STRIPPED_ORIGINAL_PROMPT:-}" ]]; then
|
||||
if [[ -n "${WARP_STRIPPED_ORIGINAL_PROMPT:-}" && "$PROMPT" == *"$WARP_STRIPPED_ORIGINAL_PROMPT"* ]]; then
|
||||
# Another hook added content around the stripped prompt that we
|
||||
# installed (e.g. a virtualenv prefix). Rehydrate the stripped
|
||||
# portion back to its pristine value before saving, so that the
|
||||
# width annotations survive alongside the added content.
|
||||
ORIGINAL_PROMPT=${PROMPT//$WARP_STRIPPED_ORIGINAL_PROMPT/$ORIGINAL_PROMPT}
|
||||
else
|
||||
ORIGINAL_PROMPT=$PROMPT
|
||||
fi
|
||||
fi
|
||||
PROMPT="$prompt_prefix$PROMPT$suffix"
|
||||
fi
|
||||
|
||||
@@ -762,14 +815,26 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
# If we are using the Warp prompt, we pass a "hidden left prompt" to the prompt
|
||||
# preview grid (the hidden prompt grid) with cursor markers surrounding the entire prompt.
|
||||
if [[ "$WARP_HONOR_PS1" != "1" ]]; then
|
||||
if [[ "$PROMPT" != "%{$prompt_prefix$ORIGINAL_PROMPT$suffix%}" ]]; then
|
||||
# Even though the entire prompt is surrounded by cursor markers below,
|
||||
# zsh still counts explicit-width constructs (%n{...%} and %G) within it
|
||||
# as visible "glitch" columns. Since the prompt is routed to the hidden
|
||||
# prompt grid and occupies zero columns of the combined prompt/command
|
||||
# grid, any nonzero counted width desyncs zle's internal cursor position
|
||||
# from the physical one, which corrupts partial redraws of the command
|
||||
# (e.g. when zsh-syntax-highlighting recolors individual tokens). Strip
|
||||
# those constructs before wrapping; this only changes zsh's width
|
||||
# accounting, never the rendered prompt bytes.
|
||||
local REPLY
|
||||
warp_strip_glitch_width_constructs "$ORIGINAL_PROMPT"
|
||||
WARP_STRIPPED_ORIGINAL_PROMPT=$REPLY
|
||||
if [[ "$PROMPT" != "%{$prompt_prefix$WARP_STRIPPED_ORIGINAL_PROMPT$suffix%}" ]]; then
|
||||
# We purposefully surround this entire prompt with cursor markers to prevent
|
||||
# the shell from moving its internal state of the cursor position, for purposes
|
||||
# of printing the command with the Warp prompt.
|
||||
# Note that the Warp prompt is always ABOVE the combined grid in finished blocks
|
||||
# (same line prompt only affects the input editor with Warp prompt, not
|
||||
# finished blocks).
|
||||
PROMPT="%{$prompt_prefix$ORIGINAL_PROMPT$suffix%}"
|
||||
PROMPT="%{$prompt_prefix$WARP_STRIPPED_ORIGINAL_PROMPT$suffix%}"
|
||||
fi
|
||||
# Otherwise, if we are using the PS1, we use the normal prompt markers.
|
||||
else
|
||||
@@ -780,7 +845,9 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${RPROMPT:-}" != "%{"*"%}" ]]; then
|
||||
# Do not synthesize an empty right prompt. Even without visible content, zsh reserves
|
||||
# right-prompt layout space and may corrupt wrapped command redraws in the command grid.
|
||||
if [[ -n "${RPROMPT:-}" && "${RPROMPT:-}" != "%{"*"%}" ]]; then
|
||||
RPROMPT="%{${RPROMPT:-}%}"
|
||||
fi
|
||||
|
||||
@@ -864,10 +931,50 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
}
|
||||
|
||||
function warp_ssh_helper() {
|
||||
local remote_session_id=$(command -p od -An -N8 -tu8 /dev/urandom 2>/dev/null | command -p tr -d ' \n')
|
||||
if [[ -z "$remote_session_id" || "$remote_session_id" == "0" ]]; then
|
||||
# If we cannot generate a non-zero random token, run plain SSH instead.
|
||||
command ssh "${@:1}"
|
||||
return
|
||||
fi
|
||||
# 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
|
||||
local 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@@; _hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || command -p 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 '"'"'\e]9278;d;%s\x07'"'"' $_msg; unset _hostname _user _msg' | command -p od -An -v -tx1 | command -p tr -d ' \n')
|
||||
local 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@@; _hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || command -p 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 '"'"'\e]9278;d;%s\x07'"'"' $_msg; unset _hostname _user _msg' | command -p od -An -v -tx1 | command -p 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.
|
||||
local control_path="$SSH_SOCKET_DIR/$WARP_SESSION_ID"
|
||||
local control_master_mode="yes"
|
||||
local external_control_master="false"
|
||||
if [[ "$WARP_SSH_REUSE_CONTROL_MASTER" == "1" ]]; then
|
||||
local user_control_path=$(command ssh -G "${@:1}" 2>/dev/null | command -p sed -n 's/^controlpath //p')
|
||||
case "$user_control_path" in
|
||||
"" | none)
|
||||
# No ControlPath configured for this destination.
|
||||
;;
|
||||
*[![:alnum:]._/~@:+,-]*)
|
||||
# The resolved path contains characters we cannot safely
|
||||
# embed in the SSH hook JSON below (e.g. an unexpanded %
|
||||
# token, quotes, or whitespace); fall back to a
|
||||
# Warp-owned master.
|
||||
;;
|
||||
*)
|
||||
if command ssh -O check -o ControlPath="$user_control_path" "${@:1}" >/dev/null 2>&1; then
|
||||
# A live master exists: multiplex through it and let
|
||||
# the client know Warp does not own it.
|
||||
control_path="$user_control_path"
|
||||
control_master_mode="no"
|
||||
external_control_master="true"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Keep remote commands up-to-date with shell.rs & bash.sh.
|
||||
# Note that in this command, we're passing a string to the remote shell. Any variable expansions need to be
|
||||
@@ -876,7 +983,7 @@ if [[ -z $WARP_BOOTSTRAPPED ]]; then
|
||||
# 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 "${@:1}" \
|
||||
"
|
||||
export TERM_PROGRAM='WarpTerminal'
|
||||
@@ -887,7 +994,7 @@ export WARP_IS_SSH='1'
|
||||
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 -p od -An -v -tx1 | command -p 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 -p od -An -v -tx1 | command -p tr -d " \n")'"
|
||||
printf '$OSC_START$DCS_JSON_MARKER$OSC_PARAM_SEPARATOR%s$OSC_END' "'$hook'"
|
||||
|
||||
if test "'"${SHELL##*/}" != "bash" -a "${SHELL##*/}" != "zsh"'"; then
|
||||
@@ -922,7 +1029,7 @@ case "'${SHELL##*/}'" in
|
||||
command -p 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 || command -p uname -n)
|
||||
_user=$(command -pv whoami >/dev/null 2>&1 && command -p whoami 2>/dev/null || echo $USER)
|
||||
@@ -955,7 +1062,7 @@ esac
|
||||
|
||||
function ssh() {
|
||||
if is_interactive_ssh_session "$@"; then
|
||||
warp_send_json_message "{\"hook\": \"PreInteractiveSSHSession\", \"value\": {}}"
|
||||
warp_send_json_message "{\"hook\": \"PreInteractiveSSHSession\", \"value\": {\"session_id\": $WARP_SESSION_ID}}"
|
||||
|
||||
# If the SSH wrapper is not enabled for this session, don't use it.
|
||||
if [ "$WARP_USE_SSH_WRAPPER" = "1" ]; then
|
||||
@@ -1169,6 +1276,12 @@ esac
|
||||
fi
|
||||
fi
|
||||
|
||||
# Restore the built-in bracketed-paste widget. This works around a buggy interaction we observed
|
||||
# with the bracketed-paste-magic plugin (included in oh-my-zsh by default), zsh's "allexport"
|
||||
# option (set -a), and Warp's bootstrapping code.
|
||||
# https://github.com/warpdotdev/warp/issues/11520
|
||||
zle -A .bracketed-paste bracketed-paste
|
||||
|
||||
precmd_functions+=(warp_precmd warp_update_prompt_vars)
|
||||
preexec_functions+=(warp_preexec)
|
||||
|
||||
@@ -1395,7 +1508,8 @@ esac
|
||||
|
||||
local escaped_editor="$(warp_escape_json "$EDITOR")"
|
||||
local escaped_shell_path="$(warp_escape_json "${commands[zsh]}")"
|
||||
local escaped_json="{\"hook\": \"Bootstrapped\", \"value\": {\"histfile\": \"$escaped_histfile\", \"shell\": \"zsh\", \"home_dir\": \"$HOME\", \"path\": \"$escaped_path\", \"editor\": \"$escaped_editor\", \"env_var_names\": \"$env_var_names\", \"abbreviations\": \"$escaped_abbrs\", \"aliases\": \"$escaped_aliases\", \"function_names\": \"$function_names\", \"builtins\": \"$escaped_builtins\", \"keywords\": \"$escaped_keywords\", \"shell_version\": \"$ZSH_VERSION\", \"shell_options\": \"$shell_options\", \"rcfiles_start_time\": \"$rcfiles_start_time\", \"rcfiles_end_time\": \"$rcfiles_end_time\", \"shell_plugins\": \"$escaped_shell_plugins\", \"os_category\": \"$os_category\", \"linux_distribution\": \"$linux_distribution\", \"wsl_name\": \"${WSL_DISTRO_NAME:-}\", \"shell_path\": \"$escaped_shell_path\"}}"
|
||||
local escaped_cdpath="$(warp_escape_json "$CDPATH")"
|
||||
local escaped_json="{\"hook\": \"Bootstrapped\", \"value\": {\"histfile\": \"$escaped_histfile\", \"session_id\": $WARP_SESSION_ID, \"shell\": \"zsh\", \"home_dir\": \"$HOME\", \"path\": \"$escaped_path\", \"cdpath\": \"$escaped_cdpath\", \"editor\": \"$escaped_editor\", \"env_var_names\": \"$env_var_names\", \"abbreviations\": \"$escaped_abbrs\", \"aliases\": \"$escaped_aliases\", \"function_names\": \"$function_names\", \"builtins\": \"$escaped_builtins\", \"keywords\": \"$escaped_keywords\", \"shell_version\": \"$ZSH_VERSION\", \"shell_options\": \"$shell_options\", \"rcfiles_start_time\": \"$rcfiles_start_time\", \"rcfiles_end_time\": \"$rcfiles_end_time\", \"shell_plugins\": \"$escaped_shell_plugins\", \"os_category\": \"$os_category\", \"linux_distribution\": \"$linux_distribution\", \"wsl_name\": \"${WSL_DISTRO_NAME:-}\", \"shell_path\": \"$escaped_shell_path\"}}"
|
||||
warp_send_json_message "$escaped_json"
|
||||
}
|
||||
warp_bootstrapped
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
# command -p resolves the given command with the system default PATH, ensuring the shell
|
||||
# can find them even if the user has a clobbered PATH value.
|
||||
unsetopt ZLE
|
||||
WARP_SESSION_ID="$(command -p date +%s)$RANDOM"
|
||||
WARP_SESSION_ID=@@WARP_SESSION_ID@@
|
||||
_hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || command -p 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")
|
||||
WARP_USING_WINDOWS_CON_PTY=@@USING_CON_PTY_BOOLEAN@@
|
||||
# We send the InitShell hook via OSCs when on Windows and via DCSs otherwise.
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then printf '\e]9278;d;%s\x07' "$_msg"; else printf '\e\x50\x24\x64%s\x9c' "$_msg"; fi
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then printf '\e]9278;d;%s\x07' "$_msg"; else printf '\x1b\x50\x24\x64%s\x1b\x5c' "$_msg"; fi
|
||||
unset _hostname _user _msg
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
setopt hist_ignore_space
|
||||
unsetopt ZLE
|
||||
WARP_IS_SUBSHELL=1
|
||||
WARP_SESSION_ID="$(command -p date +%s)$RANDOM"
|
||||
WARP_SESSION_ID=@@WARP_SESSION_ID@@
|
||||
_hostname=$(command -pv hostname >/dev/null 2>&1 && command -p hostname 2>/dev/null || command -p 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\", \"is_subshell\": true, \"wsl_name\": \"$WSL_DISTRO_NAME\"}}" "$_user" "$_hostname" | command -p od -An -v -tx1 | command -p tr -d " \n")
|
||||
WARP_USING_WINDOWS_CON_PTY=@@USING_CON_PTY_BOOLEAN@@
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then printf '\e]9278;d;%s\x07' "$_msg"; else printf '\e\x50\x24\x64%s\x9c' "$_msg"; fi
|
||||
if [ "$WARP_USING_WINDOWS_CON_PTY" = true ]; then printf '\e]9278;d;%s\x07' "$_msg"; else printf '\x1b\x50\x24\x64%s\x1b\x5c' "$_msg"; fi
|
||||
unset _hostname _user _msg
|
||||
|
||||
Reference in New Issue
Block a user