#!/bin/sh
#
# select-text - start a minimalistic (n)vim displaying stdin,
# for keyboard text selection

if [ "${EDITOR}" != "nvim" ] && [ "${EDITOR}" != "vim" ]; then
  if command -v nvim; then
    EDITOR="nvim"
  elif command -v vim; then
    EDITOR="vim"
  else
    echo "This script needs either nvim or vim."
    exit 1
  fi
fi

# hide tildes in nvim since it has support for it, but do nothing for vim
if [ "${EDITOR}" = "nvim" ]; then
  hide_tildes='set fcs=eob:\ '
else
  hide_tildes='echo'
fi

"${EDITOR}" -u NONE \
  +'set nocompatible |
  set laststatus=0 |
  set shortmess=I  |
  set guicursor=a:ver100-blinkon0 |
  set noruler' \
  +"${hide_tildes}" \
  +'noremap y "+y' \
  +'nnoremap j gj' \
  +'nnoremap k gk' \
  +'nnoremap <C-c> :qa!<CR>' \
  +'nnoremap q :qa!<CR>' \
  +'nnoremap Q :qa!<CR>' \
  +'silent! ?^[^\s]? | nohl' "$@" -
