Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions crates/noa-pty/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,8 @@ mod tests {
collected.extend_from_slice(&chunk);
if collected.windows(7).any(|w| w == b"\x1b]133;A")
&& collected
.windows(11)
.any(|w| w == b"\x1b]7;file://".as_ref())
.windows(22)
.any(|w| w == b"\x1b]7;kitty-shell-cwd://".as_ref())
{
break;
}
Expand All @@ -844,7 +844,9 @@ mod tests {
"expected an OSC 133;A prompt mark in zsh output"
);
assert!(
collected.windows(11).any(|w| w == b"\x1b]7;file://"),
collected
.windows(22)
.any(|w| w == b"\x1b]7;kitty-shell-cwd://"),
"expected an OSC 7 cwd report in zsh output"
);
}
Expand Down Expand Up @@ -879,8 +881,8 @@ mod tests {
collected.extend_from_slice(&chunk);
if collected.windows(7).any(|w| w == b"\x1b]133;A")
&& collected
.windows(11)
.any(|w| w == b"\x1b]7;file://".as_ref())
.windows(22)
.any(|w| w == b"\x1b]7;kitty-shell-cwd://".as_ref())
{
break;
}
Expand All @@ -896,7 +898,9 @@ mod tests {
"expected an OSC 133;A prompt mark in bash output"
);
assert!(
collected.windows(11).any(|w| w == b"\x1b]7;file://"),
collected
.windows(22)
.any(|w| w == b"\x1b]7;kitty-shell-cwd://"),
"expected an OSC 7 cwd report in bash output"
);
}
Expand Down
19 changes: 7 additions & 12 deletions shell-integration/bash/noa.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ unset NOA_BASH_LOGIN NOA_BASH_INJECT NOA_BASH_RCFILE
# Only wire up integration for a real interactive terminal.
case "$-" in
*i*)
_noa_report_cwd() {
printf '\e]7;file://%s%s\a' "${HOSTNAME}" "$PWD"
}

# OSC 133 D (last command's exit status) + A (prompt start) + B (input
# start), plus OSC 7, emitted before each prompt. Runs first in
# PROMPT_COMMAND so `$?` is still the finished command's status.
# OSC 133 D (last command's exit status) + OSC 7 (cwd, raw path via the
# kitty-shell-cwd:// scheme — no encoding needed) + A (prompt start) +
# B (input start), emitted before each prompt in one builtin printf.
# Runs first in PROMPT_COMMAND so `$?` is still the finished command's
# status when it's expanded.
_noa_prompt() {
local ret="$?"
printf '\e]133;D;%s\a' "$ret"
_noa_report_cwd
printf '\e]133;A\a'
printf '\e]133;B\a'
builtin printf '\e]133;D;%s\a\e]7;kitty-shell-cwd://%s%s\a\e]133;A\a\e]133;B\a' \
"$?" "$HOSTNAME" "$PWD"
}
PROMPT_COMMAND="_noa_prompt${PROMPT_COMMAND:+; $PROMPT_COMMAND}"

Expand Down
18 changes: 6 additions & 12 deletions shell-integration/fish/vendor_conf.d/noa-integration.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@

status is-interactive; or exit 0

function _noa_report_cwd
# OSC 7: report cwd as a file:// URL.
printf '\e]7;file://%s%s\a' (hostname) "$PWD"
end

function _noa_preexec --on-event fish_preexec
# OSC 133 C: a command is about to run.
printf '\e]133;C\a'
end

function _noa_prompt --on-event fish_prompt
# OSC 133 D (last command's exit status) + A (prompt start) + B (input
# start), plus OSC 7, emitted before each prompt.
set -l ret $status
printf '\e]133;D;%s\a' $ret
_noa_report_cwd
printf '\e]133;A\a'
printf '\e]133;B\a'
# OSC 133 D (last command's exit status) + OSC 7 (cwd, raw path via the
# kitty-shell-cwd:// scheme) + A (prompt start) + B (input start), emitted
# before each prompt. One builtin printf and the $hostname variable — no
# command substitution, since this runs on every prompt.
printf '\e]133;D;%s\a\e]7;kitty-shell-cwd://%s%s\a\e]133;A\a\e]133;B\a' \
$status $hostname $PWD
end
7 changes: 5 additions & 2 deletions shell-integration/zsh/.zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
#
# The user's real ZDOTDIR (or $HOME) is carried in NOA_ZDOTDIR, set by noa.

# Plain (unexported) shell variables: later startup files in this same shell
# see them, but child processes don't inherit noa-only bookkeeping.
if [[ -n "$NOA_ZDOTDIR" ]]; then
export USER_ZDOTDIR="$NOA_ZDOTDIR"
USER_ZDOTDIR="$NOA_ZDOTDIR"
NOA_USER_HAD_ZDOTDIR=1
else
export USER_ZDOTDIR="$HOME"
USER_ZDOTDIR="$HOME"
fi
unset NOA_ZDOTDIR

Expand Down
42 changes: 16 additions & 26 deletions shell-integration/zsh/.zshrc
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
# noa shell integration (zsh) — interactive setup.
#
# Source the user's real .zshrc first so noa's hooks wrap their prompt, then
# restore ZDOTDIR so any zsh spawned later reads the user's config directly.
# restore ZDOTDIR (or unset it if the user never had one — Ghostty parity) so
# any zsh spawned later reads the user's config directly.

[[ -f "$USER_ZDOTDIR/.zshrc" ]] && source "$USER_ZDOTDIR/.zshrc"
ZDOTDIR="$USER_ZDOTDIR"
if [[ -n "$NOA_USER_HAD_ZDOTDIR" ]]; then
ZDOTDIR="$USER_ZDOTDIR"
unset NOA_USER_HAD_ZDOTDIR
else
unset ZDOTDIR
fi

# Only wire up integration for a real interactive terminal.
if [[ -o interactive ]]; then
# OSC 7: report the working directory as a file:// URL (percent-encoding the
# few characters that would otherwise break the URL).
_noa_report_cwd() {
local encoded="" c
local i=1
while (( i <= ${#PWD} )); do
c="${PWD[i]}"
case "$c" in
[a-zA-Z0-9/._~-]) encoded+="$c" ;;
*) encoded+=$(printf '%%%02X' "'$c") ;;
esac
(( i++ ))
done
printf '\e]7;file://%s%s\a' "${HOST}" "$encoded"
}

# OSC 133 D (previous command's exit status) + A (prompt start) + B (prompt
# end / input start), plus OSC 7, emitted just before each prompt.
# OSC 133 D (previous command's exit status) + OSC 7 (cwd) + OSC 133 A
# (prompt start) + B (prompt end / input start), emitted just before each
# prompt. This runs on every prompt, so it must stay cheap: one builtin
# printf, no subshells. The kitty-shell-cwd:// scheme carries the path raw
# (no percent-encoding), same as Ghostty/kitty.
_noa_precmd() {
local ret="$?"
printf '\e]133;D;%s\a' "$ret"
_noa_report_cwd
printf '\e]133;A\a'
printf '\e]133;B\a'
builtin printf '\e]133;D;%s\a\e]7;kitty-shell-cwd://%s%s\a\e]133;A\a\e]133;B\a' \
"$?" "$HOST" "$PWD"
}

# OSC 133 C: a command is about to run.
_noa_preexec() {
printf '\e]133;C\a'
builtin printf '\e]133;C\a'
}

autoload -Uz add-zsh-hook
Expand Down