diff --git a/harpoon b/harpoon index bf53da7..89b8dad 100755 --- a/harpoon +++ b/harpoon @@ -62,7 +62,7 @@ _getFZFCmd() { return 0 fi if type fzf-tmux >/dev/null 2>&1; then - echo "fzf-tmux -p '50%,50%'" + echo "fzf-tmux -p 50%,50%" return 0 fi echo "fzf" @@ -138,7 +138,29 @@ switch() { done <"$cachefile" } -edit_file() { exec tmux popup -E "$EDITOR $cachefile"; } +# Tmux options (vim/nvim only): +# @tmux-harpoon-faithful-vim-controls bool, default true +# Remap `q` -> :q!, `:w` -> :wq, and -> jump to session on the +# current line, mirroring how harpoon's UI navigates. +# @tmux-harpoon-editor-args string, default empty +# Extra args appended to the editor command (e.g. `--clean`, `-u NONE`). +edit_file() { + cmd="$EDITOR $cachefile" + editor_basename="${EDITOR##*/}" + editor_basename="${editor_basename%% *}" + case "$editor_basename" in + vim | nvim) + faithful=$(tmux show-option -gqv "@tmux-harpoon-faithful-vim-controls" 2>/dev/null) + [ -z "$faithful" ] && faithful="true" + if [ "$faithful" = "true" ]; then + cmd="$cmd -c \"nnoremap q :q!\" -c \"cnoreabbrev w wq\" -c \"nnoremap :execute '!$0 -s ' . line('.') q!\"" + fi + vim_args=$(tmux show-option -gqv "@tmux-harpoon-editor-args" 2>/dev/null) + [ -n "$vim_args" ] && cmd="$cmd $vim_args" + ;; + esac + exec tmux popup -E "$cmd" +} sessions_has_match() { list_sessions | grep -wq "^$1"; }