Skip to content

Comments

feat: add z -- to jump to last rested directory#1182

Closed
douglasjsellers wants to merge 1 commit intoajeetdsouza:mainfrom
douglasjsellers:feat/z-dash-dash-rest-tracking
Closed

feat: add z -- to jump to last rested directory#1182
douglasjsellers wants to merge 1 commit intoajeetdsouza:mainfrom
douglasjsellers:feat/z-dash-dash-rest-tracking

Conversation

@douglasjsellers
Copy link

Summary

  • Adds z -- command that jumps back to the last directory the user stayed in for at least 5 seconds
  • Threshold is configurable via _ZO_REST_THRESHOLD environment variable (default: 5 seconds)
  • Implemented entirely in shell templates — no Rust binary changes
  • Supported across all 9 shells: bash, zsh, fish, posix, powershell, elvish, nushell, tcsh, xonsh

How it works

Each shell hook now tracks how long the user stays in a directory. When the user changes directories, if they were in the previous directory for >= _ZO_REST_THRESHOLD seconds, that directory is saved as the "last rested" directory. Running z -- jumps to it.

State is session-local (shell variables), similar to how z - / $OLDPWD works.

Time sources (chosen to avoid unnecessary forking)

Shell Time Source
Bash $SECONDS
Zsh $SECONDS
Fish date +%s
POSIX date +%s
PowerShell [DateTimeOffset]::Now.ToUnixTimeSeconds()
Elvish (time:now)[unix]
Nushell date now | format date '%s' | into int
Tcsh `date +%s`
Xonsh time.time()

Test plan

  • Verify cargo test passes (template syntax validation)
  • Manual test: cd /tmp && sleep 6 && cd /var && z -- jumps to /tmp
  • Manual test: cd /tmp && sleep 1 && cd /var && z -- does NOT update last rested
  • Manual test: z -- with no prior rest prints error
  • Manual test: _ZO_REST_THRESHOLD=2 lowers the threshold

🤖 Generated with Claude Code

Add a new `z --` command that jumps back to the last directory the user
stayed in for at least 5 seconds. The threshold is configurable via the
`_ZO_REST_THRESHOLD` environment variable (default: 5).

This is implemented entirely in the shell templates with no Rust binary
changes. Each shell hook now tracks dwell time per directory and records
the last "rested" directory in a session-local variable.

Supported across all 9 shells: bash, zsh, fish, posix, powershell,
elvish, nushell, tcsh, and xonsh.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant