Skip to content

Fix preview of paths starting with ~/#892

Merged
junegunn merged 2 commits intojunegunn:masterfrom
ptzz:master
Nov 1, 2019
Merged

Fix preview of paths starting with ~/#892
junegunn merged 2 commits intojunegunn:masterfrom
ptzz:master

Conversation

@ptzz
Copy link
Copy Markdown
Contributor

@ptzz ptzz commented Oct 31, 2019

Fixes outstanding comments in #774 and #890.

@junegunn junegunn merged commit bce6588 into junegunn:master Nov 1, 2019
@junegunn junegunn mentioned this pull request Nov 1, 2019
@junegunn
Copy link
Copy Markdown
Owner

junegunn commented Nov 1, 2019

Thanks.

@tzhouhc
Copy link
Copy Markdown

tzhouhc commented Nov 25, 2019

On zsh when converting FILE this operation adds an extra backslash after the $HOME:

minecraft@nookie:~$ FILE='~/.dotfiles'
minecraft@nookie:~$ FILE="${FILE/#\~\//$HOME\/}"
minecraft@nookie:~$ echo $FILE
/home/minecraft/.dotfiles
minecraft@nookie:~$ zsh
nookie% FILE='~/.dotfiles'
nookie% FILE="${FILE/#\~\//$HOME\/}"
nookie% echo $FILE
/home/minecraft\/.dotfiles

Causing history preview to, instead of failing because it doesn't know about ~ in single quotes, fail because it doesn't know why there's a backtick in the middle:

File not found /Users/tingzhou\/.dotfiles/vim/testrc.vim

Setting shell in vim doesn't seem to help.

attached, minimal testing vimrc:

let vimDir = '$HOME/.vim'
let &runtimepath.=','.vimDir

set nocompatible
call plug#begin('~/.vim/bundle')

" fzf -- quick jump to file, tag and such
Plug 'junegunn/fzf', { 'dir': '~/.fzf' }
Plug 'junegunn/fzf.vim'

call plug#end()"}}}

" History preview with colorings and such
command! -bang -nargs=* History
  \ call fzf#vim#history(fzf#vim#with_preview(), <bang>0
  \ )

nnoremap <c-p> :History<cr>

Updating the line to

FILE="${FILE/#\~/$HOME/}"

seems to fix, and testing manually on the shell doesn't seem to break it either, but I do not know for sure.

@tzhouhc
Copy link
Copy Markdown

tzhouhc commented Nov 25, 2019

Seeing the history, I think if ensuring we only substitute ~/ instead of ~, the solution would be to use

FILE="${FILE/#\~\//$HOME/}"
# or
FILE="${FILE/#\~\//$HOME//}"
# since multiple slashes are ignored

@junegunn
Copy link
Copy Markdown
Owner

On zsh

It's a bash script.

@tzhouhc
Copy link
Copy Markdown

tzhouhc commented Nov 25, 2019

On zsh

It's a bash script.

I feel stupid.

But now I am out of ideas about why it behaves this way. I wonder if there's some obscure env var that changes the substitution rules, since while this (now) is obviously not a bash/zsh thing, the issue remains that I am getting an extra \ :(

@junegunn
Copy link
Copy Markdown
Owner

Does this correctly print bash version? /usr/bin/env bash --version

@tzhouhc
Copy link
Copy Markdown

tzhouhc commented Nov 25, 2019

Anyway, solved by installing bash 5 and having it on my path before the mac included one. If anyone somehow gets this same issue, GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19) (the one on Catalina) is the culprit. This behavior is not present on darwin18.

Thanks to @junegunn for helping out and pointing out the key to the problem!

(Your reply showed up while I was typing, so this came out kinda weird. Seems like I went the right direction though! :)

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

Successfully merging this pull request may close these issues.

4 participants