__fzf_parse_commandline.fish 856 B

1234567891011121314151617181920212223
  1. function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath and rest of token'
  2. # eval is used to do shell expansion on paths
  3. set -l commandline (eval "printf '%s' "(commandline -t))
  4. if [ -z $commandline ]
  5. # Default to current directory with no --query
  6. set dir '.'
  7. set fzf_query ''
  8. else
  9. set dir (__fzf_get_dir $commandline)
  10. if [ "$dir" = "." -a (string sub -l 1 $commandline) != '.' ]
  11. # if $dir is "." but commandline is not a relative path, this means no file path found
  12. set fzf_query $commandline
  13. else
  14. # Also remove trailing slash after dir, to "split" input properly
  15. set fzf_query (string replace -r "^$dir/?" '' "$commandline")
  16. end
  17. end
  18. echo $dir
  19. echo $fzf_query
  20. end