Skip to content

Commit

Permalink
feat(zsh): v func redirects to available editor
Browse files Browse the repository at this point in the history
Fixes issue where `v` used invalid/moved/deleted editor since `v` alias
was set at start of zsh session.

Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
  • Loading branch information
vladdoster committed Sep 14, 2024
1 parent fb8a882 commit a493781
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions zsh/.config/zsh/completions/_v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#compdef v
# vim: ft=zsh sw=2 ts=2 et

_arguments \
'(-d --debug)'{-d,--debug}'[Enable debug mode]' \
'(-h --help)'{-h,--help}'[Show list of command-line options]' \
"*:files:_files"
40 changes: 40 additions & 0 deletions zsh/.config/zsh/functions/v
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#autoload
# vim: ft=zsh sw=2 ts=2 et

typeset -gx EDITOR='v'

v() {
emulate -L zsh

zmodload zsh/zutil || return

setopt typeset_silent
local debug editor help nvim_found

zparseopts -D -F -K -F -- \
{d,-debug}=debug \
{h,-help}=help \
|| return 1

if (( ${#debug} )); then
setopt xtrace
fi

if (( ${#help} )); then
print "Usage: $0 [options] [files...]"
print 'Options:'
print ' -d, --debug turn on execution tracing'
print ' -h, --help show list of command-line options'
fi

command -v nvim >/dev/null
nvim_found=$?
editor="${${(M)nvim_found:#0}:+n}vim"
if (( ${#debug} )); then
print -- "${editor}" "${@}"
else
${editor} ${@}
fi
}

v "$@"

0 comments on commit a493781

Please sign in to comment.