User guide / Workspaces and persistent sessions

Change the shell directory on exit

Development reference · View source

Like Yazi, Runyte cannot change the directory of the shell that launched it. Start it through a shell function that passes --cwd-file; then :quit-here (:qh) exits and moves the shell.

CommandShell directory afterwards
:quit-here / :qhThe active explorer directory, or the active file’s parent
:quit-here! / :qh!The same, discarding unsaved changes
:quit from the last pane, :quit-allUnchanged; returns to another running session when possible

A pathless view uses the last explorer directory visited in that pane, then the working directory set by :cd. :quit-here keeps the normal unsaved-change protection.

Bash or Zsh

Add this to the shell configuration:

function runyte() {
    local runyte_tmp runyte_cwd runyte_exit
    runyte_tmp="$(mktemp -t 'runyte-cwd.XXXXXX')" || return
    command runyte --cwd-file "$runyte_tmp" "$@"
    runyte_exit=$?
    if [ "$runyte_exit" -eq 0 ] && IFS= read -r -d '' runyte_cwd < "$runyte_tmp"; then
        [ -n "$runyte_cwd" ] && [ "$runyte_cwd" != "$PWD" ] && [ -d "$runyte_cwd" ] && builtin cd -- "$runyte_cwd"
    fi
    command rm -f -- "$runyte_tmp"
    return "$runyte_exit"
}

Windows PowerShell 5.1

Save runyte.ps1 somewhere stable and dot-source it from your PowerShell profile:

. 'C:\Tools\Runyte\runyte.ps1'
  • The function starts runyte.exe and waits for it. :quit leaves the caller’s directory alone; a successful :quit-here changes it using a literal path.
  • It returns the editor’s status in $LASTEXITCODE, or a nonzero status if the wrapper fails.
  • The handoff needs private local NTFS temporary storage.
  • The destination needs an identity-equivalent ordinary local or UNC spelling shorter than 260 UTF-16 units, with valid Unicode components. Other paths are refused before quitting.
  • The bounded, versioned handoff record keeps UTF-16 code units; it differs from the Unix NUL-terminated byte format.
  • PowerShell 7 has not been validated for this wrapper.

How it behaves

  • After reloading the shell configuration, run runyte as usual.
  • --cwd-file is for shell integration. Runyte writes it only after a successful :quit-here.
  • Without the wrapper, :quit-here refuses to exit and explains how to enable it, rather than acting like :quit.
  • Session commands such as --session-list accept the option but leave the file alone, so they work through the same function.
  • Persistent sessions (Unix and Windows): :quit-here runs in the host, which reports the chosen directory, and the attached client writes the file. The same wrapper serves both modes, and the directory follows you across workspace switches.
  • The capability belongs to the client, not the host: a client launched without the wrapper is refused even if an earlier one had it.
  • On Windows, the frontend writes the handoff after restoring the terminal.
  • In mux mode :quit-here stops the session after the same checks as :quit. Use :detach to keep the host running.