Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
in vifm by

TLDR I'm trying to make this work :

command! FZFCd : set noquickview
                \| let $FZF_PICK = term('fd --type file | fzf-tmux -p 80%% --prompt "Files> " --header "CTRL-T: Switch between Files/Directories" --bind "ctrl-t:transform:[[ ! $FZF_PROMPT =~ Files ]] &&
                \  echo \"change-prompt(Files> )+reload(fd --type file --hidden)\" ||
                \  echo \"change-prompt(Dirs > )+reload(fd --type directory --hidden)\"" 2>/dev/tty')
                \| if $FZF_PICK != ''
                \|     execute 'goto' fnameescape($FZF_PICK)
                \| endif

I'm basically tring to add ++ctrl+t++ key bind to reload and toggle between files and dirs and writing it across multiple lines so for now.

I'd also make it easier if there was a way to access fzf functions declared in "fzf/shell/key_binding.bash" in vifm fzf for execution

Also my next step is to add this conglomorate in vifm which is now located in the "fzf/shell/key_binding.bash" would there be any functionality issues integrating it using the same philosophy as in this function in vifm? what is recommanded to do in porting such a function to vifm?

 fzfCd() {
    
      local FILE_PICKER_CMD="fd --hidden"
      # set -x
      local SearchPath=~
      local dir=""
      local Cwd="$(pwd)/"
    

      dir=$(fd --type directory --hidden . | fzf-tmux --ansi \
        --bind "start:transform-header(echo ${Cwd})+execute-silent(echo "$Cwd" | tee /tmp/fpicker-dir)" \
        --bind "ctrl-r:transform([[ -n {q} ]] && echo \"execute-silent(echo {q} | tee /tmp/fpicker-dir)\" || echo \"execute-silent(echo ${Cwd} | tee /tmp/fpicker-dir)\")+transform-query(cat /tmp/fpicker-dir)+transform-header(cat /tmp/fpicker-dir)+transform:[[ {fzf:prompt} =~ Files ]] &&
          echo \"reload(${FILE_PICKER_CMD} --type file . {q})+transform-header(cat /tmp/fpicker-dir)+change-query()\" ||
          echo \"reload(${FILE_PICKER_CMD} --type directory . {q})+transform-header(cat /tmp/fpicker-dir)+change-query()\"" \
        --bind "ctrl-e:execute-silent(echo \"/\" > /tmp/fpicker-dir)+transform-header(cat /tmp/fpicker-dir)+transform:[[ {fzf:prompt} =~ Files ]] &&
          echo \"reload(${FILE_PICKER_CMD} --type file . \"/\")+transform-header(cat /tmp/fpicker-dir)\" ||
          echo \"reload(${FILE_PICKER_CMD} --type directory . \"/\")+transform-header(cat /tmp/fpicker-dir)\"" \
        --bind "ctrl-d:execute-silent(echo \"/home/pong/\" > /tmp/fpicker-dir)+transform-header(cat /tmp/fpicker-dir)+transform:[[ {fzf:prompt} =~ Files ]] &&
          echo \"reload(${FILE_PICKER_CMD} --type file . \"/home/pong/.config\")+transform-header(cat /tmp/fpicker-dir)\" ||
          echo \"reload(${FILE_PICKER_CMD} --type directory . \"/home/pong/.config\")+transform-header(cat /tmp/fpicker-dir)\"" \
        --bind "ctrl-b:execute-silent(echo \"$Cwd\" > /tmp/fpicker-dir)+transform-header(cat /tmp/fpicker-dir)+transform:[[ {fzf:prompt} =~ Files ]] &&
          echo \"reload(${FILE_PICKER_CMD} --type file . \"/home/pong/.config\")+transform-header(cat /tmp/fpicker-dir)\" ||
          echo \"reload(${FILE_PICKER_CMD} --type directory . \"/home/pong/.config\")+transform-header(cat /tmp/fpicker-dir)\"" \
        --bind "ctrl-t:transform(echo {fzf:query} > /tmp/fzf-q)+transform-query(cat /tmp/fpicker-dir)+transform:[[ ! {fzf:prompt} =~ Files ]] && 
          echo \"change-prompt(Files >)+reload(${FILE_PICKER_CMD} --type file . {q})+transform-header(cat /tmp/fpicker-dir)+transform-query(cat /tmp/fzf-q)\" ||
          echo \"change-prompt(Dirs  >)+reload(${FILE_PICKER_CMD} --type directory . {q})+transform-header(cat /tmp/fpicker-dir)+transform-query(cat /tmp/fzf-q)\"" \
        --bind "ctrl-f:transform:[[ ! {fzf:prompt} =~ Files ]] && 
          echo \"change-prompt(Files >)+reload(${FILE_PICKER_CMD} --type file . \$\(cat /tmp/fpicker-dir\))+transform-header(cat /tmp/fpicker-dir)+transform-query(cat /tmp/fzf-q)\" ||
          echo \"change-prompt(Dirs  >)+reload(${FILE_PICKER_CMD} --type directory . \$\(cat /tmp/fpicker-dir\))+transform-header(cat /tmp/fpicker-dir)+transform-query(cat /tmp/fzf-q)\"" \
        --preview '[[ $FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}' \
        --prompt "Dirs  >" \
        --border "rounded" \
        --border-label "CD Tool" \
        +m)

   [[ -d ${dir} ]] && builtin cd "$dir" &> /dev/null || builtin cd $(echo ${dir} | awk -F '/[^/]*$' '{print $1}') &> /dev/null
   
      return 0

    }

1 Answer

0 votes
by
selected by
 
Best answer

I'm trying to make this work :

Looks correct to me, is there an error?

I'd also make it easier if there was a way to access fzf functions declared in "fzf/shell/key_binding.bash" in vifm fzf for execution

You can add source fzf/shell/key_binding.bash && in front of the command.

what is recommanded to do in porting such a function to vifm?

I would keep it in a separate file and just invoked from there.

by

What the way to invoke it from an external file?

Also no this doesn't toggle the reload and promp between files and dirs might not call them or certain characters there are interpolated differently in vifm than in bash

by
edited by

What the way to invoke it from an external file?

Along the lines of

term('source ~/fzf/shell/key_binding.bash && fzfCd 2>/dev/tty'`)

Also no this doesn't toggle the reload and promp between files and dirs might not call them or certain characters there are interpolated differently in vifm than in bash

You have [[ ! $FZF_PROMPT =~ Files ]] in double quotes, $FZF_PROMPT gets replaced with empty value, put \ in front of $, then it will probably work.

by

Yeah you were right the $ needed to be escaped like \$ so the overall working code to toggle between files and dir search is as follows:

command! FZFCd : set noquickview
                \| let $FZF_PICK = term('fd --type file | fzf-tmux -p 80%% --prompt "Files> " --header "CTRL-T: Switch between Files/Directories" --bind "ctrl-t:transform:[[ ! \$FZF_PROMPT =~ Files ]] &&
                \  echo \"change-prompt(Files> )+reload(fd --type file --hidden)\" ||
                \  echo \"change-prompt(Dirs > )+reload(fd --type directory --hidden)\"" 2>/dev/tty')
                \| if $FZF_PICK != ''
                \|     execute 'goto' fnameescape($FZF_PICK)
                \| endif

And got it sourcing other function is being done through inline bash

well that leaves me fully satisfied with the solution for the problem
Thank you very much!

...