DEV Community

Discussion on: Passing a parameter to a zsh keyboard-shortcut

Collapse
 
jesusgollonet profile image
jesús gollonet

Nice! I've been using and loving simple bindkey for a few shortcuts in my zsh/tmux/vim setup.

I didn't know about the $BUFFER variable! It will come in handy for a problem i didn't know how to solve: Often times halfway through typing a command I think "this would be better ran in its own tmux pane", but then I would have to go to the beginning of the command and add the tmux split-window etc. Too much to bother. Having a shortcut I can press after finishing typing the command is much more ergonomic. Thanks for sharing!

Collapse
 
riscie profile image
riscie

Thats a really nice usecase! Thank you too for sharing it.

Collapse
 
jesusgollonet profile image
jesús gollonet

btw, the code in your example doesn't display any output for me. The branch gets created but I can't see the output from echo or git checkout. After some googling I suspect it might have to do with using a multiline prompt.

for some reason that I don't fully understand, adding a newline after git checkout makes it display for me:

function featbranch() {
    branch_name=$BUFFER
    zle backward-kill-line
    echo "git checkout -b feat/$branch_name"
    git checkout -b "feat/${branch_name}"
    echo "\n" #¯\_(ツ)_/¯
    zle reset-prompt
    zle redisplay
}
Thread Thread
 
riscie profile image
riscie

Thanks for the follow up!

    echo "\n" #¯\_(ツ)_/¯

🤷‍♂️😂