Fzf: ENV variable with space & preview

Created on 18 Jun 2018  路  3Comments  路  Source: junegunn/fzf

  • Category

    • [x] fzf binary

    • [ ] fzf-tmux script

    • [ ] Key bindings

    • [ ] Completion

    • [ ] Vim

    • [ ] Neovim

    • [ ] Etc.

  • OS

    • [ ] Linux

    • [x] Mac OS X

    • [ ] Windows

    • [ ] Windows Subsystem for Linux

    • [ ] Etc.

  • Shell

    • [ ] bash

    • [x] zsh

    • [ ] fish

I have an ENV variable for a path that has a space in it, export NOTE_DIR="~/path/to folder/" when I try to expand it inside the --preview flag it gets split into two.

    local file
    file=$(find "${NOTE_DIR}" -name "*.md" | \
      sed -e "s|${NOTE_DIR}/||" | \
      fzf-tmux \
      --multi \
      --select-1 \
      --exit-0 \
      --preview="cat ${NOTE_DIR}/{}" \ # $NOTE_DIR doesn't get expanded properly here
      --preview-window=right:70%:wrap)
    [[ -n $file ]] && \
      ${EDITOR:-vim} "${NOTE_DIR}/${file}"

Most helpful comment

This is default behaviour with bash and zsh. In your example ls ${NOTE_DIR} will also fail.

Adding double quotes around the brace expansion will fix it.

Try this

local file
    file=$(find "${NOTE_DIR}" -name "*.md" | \
      sed -e "s|${NOTE_DIR}/||" | \
      fzf-tmux \
      --multi \
      --select-1 \
      --exit-0 \
      --preview="cat \"${NOTE_DIR}\"/{}" \
      --preview-window=right:70%:wrap)
    [[ -n $file ]] && \
      ${EDITOR:-vim} "${NOTE_DIR}/${file}"

All 3 comments

This is default behaviour with bash and zsh. In your example ls ${NOTE_DIR} will also fail.

Adding double quotes around the brace expansion will fix it.

Try this

local file
    file=$(find "${NOTE_DIR}" -name "*.md" | \
      sed -e "s|${NOTE_DIR}/||" | \
      fzf-tmux \
      --multi \
      --select-1 \
      --exit-0 \
      --preview="cat \"${NOTE_DIR}\"/{}" \
      --preview-window=right:70%:wrap)
    [[ -n $file ]] && \
      ${EDITOR:-vim} "${NOTE_DIR}/${file}"

@deepredsky Thanks!

Thanks @deepredsky 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aleclarson picture aleclarson  路  3Comments

leonklingele picture leonklingele  路  3Comments

jan-warchol picture jan-warchol  路  3Comments

kit494way picture kit494way  路  3Comments

chrisamow picture chrisamow  路  3Comments