Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature requrest: feed pushd stack with zi --special-flag #1029

Open
MartyMcFlyInTheSky opened this issue Mar 28, 2025 · 2 comments
Open

feature requrest: feed pushd stack with zi --special-flag #1029

MartyMcFlyInTheSky opened this issue Mar 28, 2025 · 2 comments

Comments

@MartyMcFlyInTheSky
Copy link

MartyMcFlyInTheSky commented Mar 28, 2025

It would be nice if I could invoke the zi command in a way that automatically also stores the current dir in the dir stack. I have my pushd mapped to keybindings so I can quickly rotate through the directories. Adding this flag would enable me to do so also with zoxide.

I propose zi --dirstack or something like this.

@azaleacolburn
Copy link
Contributor

There's a similar feature right now where z - take you back to the last directory where you invoked a the zoxide query command. However, this works by storing the last jump location, not creating a stack, since running z - also stores the current directory, meaning backtracking immediately loops you back and forth between directories.

What you're proposing would be a proper stack. We would actually need two flag-states, one where the stack is pushed to, and one where the stack is popped from. I'm guessing that your proposed zi --dirstack would push? Are you proposing that zi - should pop, or keep it's current functionality?

@MartyMcFlyInTheSky
Copy link
Author

MartyMcFlyInTheSky commented Mar 30, 2025

I'm not currently aware of the implementation details of pushd and popd. I'm not even sure if it's possible to access the dirstack as a shell external tool. But my use I have something like this to rotate through the dirstack:

dirstack_next() {
    pushd +1 >/dev/null
}

dirstack_prev() {
    pushd -0 >/dev/null
}

# Restore cl is universal
bind -x '"\201":"_restore_command_line"'

# Go up one directory
bind -x '"\204":"_save_command_line; cd .."'
bind '"\eh":"\204\n\201"'
# Rotate pushed directories
bind -x '"\202":"_save_command_line; dirstack_next"'
bind '"\ek":"\202\n\201"'
bind -x '"\203":"_save_command_line; dirstack_prev"'
bind '"\ej":"\203\n\201"'

But adding to the dirstack I do manually with an explicit pushd in the shell. For my usecase it would be nice if directory changes with zi would equally contribute to the dirstack (in case special options are given) just like pushd does, so I could rotate through them at the same time. For people interested in doing this I could imagine aliasing puzi to zi --dirstack or something, so I have the analogy:

cd -> zi
pushd -> puzi

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

No branches or pull requests

2 participants