Is it possible to write a zsh binding that would change the current directory and then update the p10k directory element without having to add a new line to the screen (like accept-line does)?
I've recently migrated from fish, and I miss one feature immensely, the ability to quickly cycle through the directory history with alt-left and alt-right. That behavior redraws the directory element on the current line's prompt.
Based on what I scanned from prior issues, it sounds like this would not be possible with p10k as it looks like you recommended the use of accept-line, but I wanted to confirm. I suppose using accept-line would not be terrible, just not as nice as the fish implementation I'm accustomed to.
Thanks again for all your efforts!
Yes, it's possible. Try this:
mkdir /tmp/zdotdir
cp ~/.p10k.zsh /tmp/zdotdir
curl -fsSLo /tmp/zdotdir/.zshrc https://raw.githubusercontent.com/romkatv/zsh4humans/master/.zshrc
ZDOTDIR=/tmp/zdotdir zsh
Then try alt-left, alt-right, alt-up and alt-down (the last is the coolest). There is also very nice tab completion (try git TAB or git checkout --TAB) and history on Ctrl-R.
Very cool. This is exactly what I was looking to emulate that fish behavior to cycle through directories. Now, I just need to look at z4h and see if I can just eliminate the various bundles I've stumbled across in my past day of zsh exploration! Thanks again.
For others that stumble upon this issue, here is the relevant code from zsh4humans that provides the fish-like cycling of directories. I've incorporated this into my config. Thanks again @romkatv!
setopt AUTO_PUSHD
# Widgets for changing current working directory.
function z4h-redraw-prompt() {
emulate -L zsh
local f
for f in chpwd $chpwd_functions precmd $precmd_functions; do
(( $+functions[$f] )) && $f &>/dev/null
done
zle .reset-prompt
zle -R
}
function z4h-cd-rotate() {
emulate -L zsh
while (( $#dirstack )) && ! pushd -q $1 &>/dev/null; do
popd -q $1
done
if (( $#dirstack )); then
z4h-redraw-prompt
fi
}
function z4h-cd-back() { z4h-cd-rotate +1 }
function z4h-cd-forward() { z4h-cd-rotate -0 }
zle -N z4h-cd-back
zle -N z4h-cd-forward
bindkey '^[[1;3D' z4h-cd-back # alt+left cd into the prev directory
bindkey '^[[1;3C' z4h-cd-forward # alt+right cd into the next directory
My goodness! Have you just taken perfectly fine code and replaced 2-space indentation with 4-space?! 馃槺
(Adding a clause to the license to prevent such madness.)
On a more serious note, I encourage you to explore tab completion and ctrl-r in zsh4humans. It's very good.
My goodness! Have you just taken perfectly fine code and replaced 2-space indentation with 4-space?! 馃槺
(Adding a clause to the license to prevent such madness.)
Haha. I'll have to go configure emacs properly. I didn't even notice it until you pointed it out.
Haha. I'll have to go configure emacs properly. I didn't even notice it until you pointed it out.
EMACS?!
Couldn't resist 馃ぃ
By the way, how do you find Zsh after Fish?
On a more serious note, I encourage you to explore tab completion and ctrl-r in zsh4humans. It's very good.
Will do. I'll go explore more and see how to configure z4h to my liking. There are a few things I want to add such as fast-syntax-highlighting and a few other plugins I've discovered like colored man pages and such.
There are a few things I want to add such as
fast-syntax-highlighting
It always fascinates me how powerful a name of a project can be. Some will assume it's fast because the name says so. Others will assume it's stupid because "fast" in the name of anything is stupid. None will be unmoved though.
Haha. I'll have to go configure emacs properly. I didn't even notice it until you pointed it out.
EMACS?!
Couldn't resist 馃ぃ
Does it matter that I use evil-mode? I've recently switched from vscode back to my roots in emacs and vim using Doom Emacs. I just find that when it comes to editing, nothing is faster for me than vim keybindings, and the fact that I can use them in emacs is even better given has flexible it is.
By the way, how do you find Zsh after Fish?
The only reason I went to fish was for the simplicity of the out of box configuration. It's autocompletion was fantastic and small goodies like the directory cycling. Unfortunately, I can't tell you how many times I've typed export VAR=something and been rebuked by it. Also, I can never remember a simple bourne-shell for loop.
With the discovery of your p10k, this directory cycling, and the many package managers that have improved startup time, I couldn't be happier with zsh. I have all the niceties of fish but with a sane shell 馃槂 It's like the old days back in college, when I flirted with tcsh instead of ksh. Same problem, bourne-shell derivatives just make more sense.
Seems like you have exciting days ahead!
By the way, if you enable instant prompt in powerlevel10k, you can forget about slow zsh startup. There are no fast or slow package managers for you. It's all the same now. You can notice that when you use zsh4humans, zsh starts faster than you can blink (assuming you've enabled instant prompt in p10k configure). Yet, it doesn't use any fancy plugin managers. It's a fairly straightforward config.
There are a few things I want to add such as
fast-syntax-highlightingIt always fascinates me how powerful a name of a project can be. Some will assume it's fast because the name says so. Others will assume it's stupid because "fast" in the name of anything is stupid. None will be unmoved though.
I didn't choose it because of the "fast" part, but rather it seemed to have better syntax highlighting than the other one although I didn't spend much time investigating. After spending all weekend long trying to configure zsh, I wish I would have discovered your z4h sooner :-)
Seems like you have exciting days ahead!
By the way, if you enable instant prompt in powerlevel10k, you can forget about slow zsh startup. There are no fast or slow package managers for you. It's all the same now. You can notice that when you use zsh4humans, zsh starts faster than you can blink (assuming you've enabled instant prompt in
p10k configure). Yet, it doesn't use any fancy plugin managers. It's a fairly straightforward config.
Nice. Everything I've read about zsh was about the startup times being slow due to plugins as well as completions. If I can avoid all that extra non-sense, that's awesome! Looks like I'll be redoing all of my zsh config I created yesterday thanks to instant prompt and z4h!
Thanks for the code @pkazmier, works great.
Could you also post the code for adding z4h-cd-up and z4h-cd-down?