#!/bin/sh

cd "${SNIPPETS_PATH:-${HOME}/dev/snippets}" || exit 1

# https://bluz71.github.io/2018/11/26/fuzzy-finding-in-bash-with-fzf.html#find-file-and-edit
file=$(
  fzf --print-query \
      --preview 'bat --color=always --line-range :500 {}'
  )

code=$?
if [ "${code}" -eq 130 ]; then
  cd || exit 1
  exit 1;
fi

if [ "${code}" -eq 0 ]; then 
  file=$(echo "${file}" | tail -n1)
  pbcopy < "${file}"

  cd || exit 1
  exit 0
fi

#searchterm=$(echo "${file}" | sed -e 's/\ /+/g')
#open "https://duckduckgo.com/?q=${searchterm}"

cd || exit 1
