-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zsh):
v
func redirects to available editor
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
1 parent
fb8a882
commit a493781
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |