From 6935843cee898a18343d7eef21230c736995b129 Mon Sep 17 00:00:00 2001 From: "Andrew R. M" Date: Sat, 5 Apr 2025 16:37:09 -0400 Subject: [PATCH] Move vim option select to execute logic at alias def time Using the function would cause problems when trying to perform a `sudo vim`. The sudo command would run in a root shell which does not have my shells functions (but does have it's aliases) so then any attempt to sudo vim would fail with "vim_option_select: command not found" --- bash/.aliases | 8 ++++++++ bash/.functions | 10 ---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/bash/.aliases b/bash/.aliases index c1b6a99..a29b62d 100644 --- a/bash/.aliases +++ b/bash/.aliases @@ -5,6 +5,14 @@ # Allow alias expansion for commands executed with sudo alias sudo="sudo " +#{- VIM OPTION SELECT -}# +if which nvim &> /dev/null; then + export PREFERRED_VIM=nvim +else + export PREFERRED_VIM=vim +fi +alias vim="$PREFERRED_VIM " + #{- GNU COREUTILS -}# # Sort directories first and colorize output diff --git a/bash/.functions b/bash/.functions index c412f00..41c5043 100644 --- a/bash/.functions +++ b/bash/.functions @@ -21,13 +21,3 @@ cat_with_newline() cat "$@" && echo } alias cat="cat_with_newline" - -vim_option_select() -{ - if which nvim &> /dev/null; then - nvim "$@" - else - vim "$@" - fi -} -alias vim="vim_option_select "