From a71f8c8cb75dcd0cfbf620737f335d0dc135874a Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Dec 16 2020 11:22:05 +0000 Subject: fix 'vim' alias on 'vi'-only system Despite the fact that user installed 'vim-enhanced' package, the alias didn't stop notifying user that 'vim' is not installed till the shell was restarted. Newly, if /usr/bin/vim suddenly appears (vim-enhanced is freshly installed) the alias is mostly no-op and vim is used directly. On top of ^, if user touches the ~/.i-know-vim-is-vi file, 'vi' is silently started instead of 'vim' without the warning. Resolves: rhbz#1907800 --- diff --git a/vim.sh b/vim.sh index 58c3300..42282dc 100644 --- a/vim.sh +++ b/vim.sh @@ -1,3 +1,20 @@ +__vi_internal_vim_alias() +( + # if user installs vim-enanced and alias is already set + test -f /usr/bin/vim && exec vim "$@" + + # if user hates the "No vim found .." interrupting message + test -f "$HOME"/.i-know-vim-is-vi && exec vi "$@" + + if [ -n "${ZSH_VERSION-}" ]; then + read -t 10 -s -k 1 '?No vim found, using vi, press ENTER to continue...' && echo '' + else + read -rep $'No vim found, using vi, press ENTER to continue...\n' -n1 -t 10 -s + fi + exec vi "$@" +) + + if [ -n "${BASH_VERSION-}" -o -n "${KSH_VERSION-}" -o -n "${ZSH_VERSION-}" ]; then # This will avoid user defined aliases and possibly stuff defined earlier in the PATH. case "$(command -v vim)-$(command -v vi)" in @@ -8,11 +25,7 @@ if [ -n "${BASH_VERSION-}" -o -n "${KSH_VERSION-}" -o -n "${ZSH_VERSION-}" ]; th ;; -/usr/bin/vi) # apply only if founded vi is in expected dir from distro - if [ -n "${ZSH_VERSION-}" ]; then - alias vim="read -t 10 -s -k 1 '?No vim found, using vi, press ENTER to continue...' && echo '' && vi" - else - alias vim="read -rep $'No vim found, using vi, press ENTER to continue...\n' -n1 -t 10 -s && vi" - fi + alias vim=__vi_internal_vim_alias ;; esac fi