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

Have to select file twice in zsh #2

Closed
jebaum opened this issue Nov 6, 2013 · 9 comments
Closed

Have to select file twice in zsh #2

jebaum opened this issue Nov 6, 2013 · 9 comments

Comments

@jebaum
Copy link
Contributor

jebaum commented Nov 6, 2013

When invoking fzf with zsh, the first time you select a file and hit enter the selection seems to be ignored, and you have to do it again, then it behaves as expected. Works perfectly in bash.

@junegunn
Copy link
Owner

junegunn commented Nov 6, 2013

Hmm, I can't reproduce the problem. Tested it on zsh 5.0.2 (x86_64-apple-darwin13.0)
FYI, my .zshrc is empty as I don't use zsh.

@jebaum
Copy link
Contributor Author

jebaum commented Nov 6, 2013

Woops, my mistake, it only occurs when using oh-my-zsh. I'm gonna try to figure out exactly what it is, obviously not the fault of your script. Sorry for the false issue

@jebaum jebaum closed this as completed Nov 6, 2013
@jebaum
Copy link
Contributor Author

jebaum commented Nov 6, 2013

For the record, this function that's in a file getting sourced is causing the problem:

function title {
if [[ "$DISABLE_AUTO_TITLE" == "true" ]] || [[ "$EMACS" == term ]]; then
return
fi
if [[ "$TERM" == screen* ]]; then
print -Pn "\ek$1:q\e" #set screen hardstatus, usually truncated at 20 chars
elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ $TERM == ansi ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
print -Pn "\e]2;$2:q\a" #set window name
print -Pn "\e]1;$1:q\a" #set icon (=tab) name (will override window name on broken terminal)
fi
}

Specifically the print -Pn "\e]2;$2:q\a" line. I have no idea why

@junegunn
Copy link
Owner

junegunn commented Nov 6, 2013

No problem. Please let me know if you find out the cause, maybe I could mention it in the README page. Thanks.

@junegunn
Copy link
Owner

junegunn commented Nov 6, 2013

Oh, thanks. Did you find a workaround? I'll try to look into it, but I'm completely ignorant on zsh or oh-my-zsh.

@junegunn
Copy link
Owner

junegunn commented Nov 6, 2013

Did you use backticks to execute fzf?

I can see the problem you mentioned when I use backticks as follows.

vim `fzf`

However, the following works fine.

vim $(fzf)

junegunn added a commit that referenced this issue Nov 6, 2013
As reported in #2, backticks on oh-my-zsh (with TERM=xterm*)
makes fzf run twice. This should be a bug of oh-my-zsh,
but for now using $() seems to be a quick workaround.
@jebaum
Copy link
Contributor Author

jebaum commented Nov 6, 2013

Yep, I was using backticks and it works fine with $(), thanks!
Do you happen to know why? I can't find any documentation on the difference between the two

@junegunn
Copy link
Owner

junegunn commented Nov 7, 2013

Honestly I have no idea at all.
I've never used zsh/oh-my-zsh seriously before and trying with $() instead of backticks was just a lucky guess.
As far as I know, at least on bash, $() and backticks are equivalent except that $() can be nested,
and I don't think it should be any different on zsh.
I guess it's a bug of oh-my-zsh, but I'm not sure if I'm going to look into it since I myself don't use it.

junegunn added a commit that referenced this issue Apr 3, 2014
e.g.
  Match region #1: [-----------]
  Match region #2:       [---]
  Match region #3:         [------]
@lbolla
Copy link

lbolla commented Oct 25, 2017

I was happening to me too, before I removed the preexec hook:

# preexec is called just before any command line is executed
# Note: breaks fzf piping
# function preexec() {
#     title "$1" "%m:%35<...<%~"
# }

No idea why.

junegunn added a commit that referenced this issue Aug 2, 2022
Favors the line with shorter matched chunk. A chunk is a set of
consecutive non-whitespace characters.

Unlike the default `length`, this new scheme works well with tabular input.

  # length prefers item #1, because the whole line is shorter,
  # chunk prefers item #2, because the matched chunk ("foo") is shorter
  fzf --height=6 --header-lines=2 --tiebreak=chunk --reverse --query=fo << "EOF"
  N | Field1 | Field2 | Field3
  - | ------ | ------ | ------
  1 | hello  | foobar | baz
  2 | world  | foo    | bazbaz
  EOF

If the input does not contain any spaces, `chunk` is equivalent to
`length`. But we're not going to set it as the default because it is
computationally more expensive.

Close #2285
Close #2537
- Not the exact solution to --tiebreak=length not taking --nth into account,
  but this should work. And the added benefit is that it works well even
  when --nth is not provided.
- Adding a bonus point to the last character of a word didn't turn out great.
  The order of the result suddenly changes when you type in the last
  character in the word producing a jarring effect.
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

3 participants