0

I've written a simple function to search the current folder when I press ctrl+f with exa and peco, after I choose a directory I want to cd into it.

(ll is modified version of ls)

pecofunc() {
  ll | peco --layout=bottom-up | read foo 
  foo="${foo##* }"
  if [ -n "$foo" ] 
  then
    builtin cd "$foo"
  fi
  # refresh terminal and end execution
}
zle -N pecofunc pecofunc
bindkey '^f' pecofunc

This part works well but after executing it my directory doesn't visually change until I press enter or use other command.

Picture 1 Terminal before doing anything

Picture 2 After pressing ctrl+f

Picture 3 Choosing test2 and pressing enter

Picture 4 Pressing enter again

Pressing enter again refreshes the folder which I'm in but creates another newline which is unacceptable.

How can I avoid this issue?

4
  • 1
    Have you tried the reset command ?
    – vinalti
    Jan 23, 2022 at 13:26
  • @vinalti Also needs another enter press and also takes quite long now to execute.
    – MikiS
    Jan 23, 2022 at 13:33
  • Can you try to add builtin echo "" OR to add to the shortcut && echo "" after executing the script ?
    – vinalti
    Jan 23, 2022 at 13:37
  • Doesn't fix the issue! :(
    – MikiS
    Jan 23, 2022 at 15:33

1 Answer 1

0

The key-handler function needs to call zle -I after returning from any interactive tools, to invalidate the current display and force ZSH to redraw the command line.

It seems that printing an empty line before running the tool can be useful, to avoid overwriting the current prompt in general.

pecofunc() {
    echo ""
    ll | peco | read foo
    zle -I
    if ... then cd ... fi
}
1
  • Thank you for the answer but unfortunately the same problem persists. "zle -I" didn't change behavior at all :/ 'echo ""' also just adds 1 more empty line (which I do not want) while not fixing anything.
    – MikiS
    Jan 23, 2022 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .