vim.sh, vim.csh - set aliases only for OS default vi and vim

Do not set them for locally built vi/vim or replace existing aliases.
This commit is contained in:
Zdenek Dohnal 2020-10-15 13:45:53 +02:00
parent cbc7da83e9
commit 17062c8b2d
3 changed files with 62 additions and 32 deletions

25
vim.csh
View File

@ -1,7 +1,20 @@
if ( -x /usr/bin/id ) then
if ( "`/usr/bin/id -u`" > 200 ) then
alias vi vim
alias view 'vim -R'
endif
endif
# we need to use which twice - first for checking if
# the command doesn't fail, the use it if doesn't fail
set vim_cond = `which vim >& /dev/null && which vim`
set vi_cond = `which vi >& /dev/null && which vi`
switch ( $vim_cond-$vi_cond )
case /usr/bin/vim-/usr/bin/vi:
# apply only when founded vim and vi are in expected dirs from distro
alias vi vim
alias view 'vim -R'
breaksw
case -/usr/bin/vi:
# apply only if founded vi is in expected dir from distro
alias vim "read -rep 'No vim found, using vi, press ENTER to continue' -n1 -t 20 -s && vi"
breaksw
endsw
# just in case
unset vim_cond
unset vi_cond

16
vim.sh
View File

@ -1,6 +1,14 @@
if [ -n "${BASH_VERSION-}" -o -n "${KSH_VERSION-}" -o -n "${ZSH_VERSION-}" ]; then
[ "`/usr/bin/id -u 2>/dev/null || echo 0`" -le 200 ] && return
# for bash and zsh, only if no alias is already set
alias vi >/dev/null 2>&1 || alias vi=vim
alias view >/dev/null 2>&1 || alias view="vim -R"
# This will avoid user defined aliases and possibly stuff defined earlier in the PATH.
case "$(which vim 2> /dev/null)-$(which vi 2> /dev/null)" in
/usr/bin/vim-/usr/bin/vi)
# apply only when founded vim and vi are in expected dirs from distro
alias vi=vim
alias view="vim -R"
;;
-/usr/bin/vi)
# apply only if founded vi is in expected dir from distro
alias vim="read -rep $'No vim found, using vi, press ENTER to continue\n' -n1 -t 20 -s && vi"
;;
esac
fi

View File

@ -98,8 +98,8 @@ Summary: The common files needed by any version of the VIM editor
Conflicts: man-pages-fr < 0.9.7-14
Conflicts: man-pages-it < 0.3.0-17
Conflicts: man-pages-pl < 0.24-2
Requires: %{name}-filesystem
Conflicts: %{name}-minimal < %{epoch}:8.1.1-1
Requires: %{name}-filesystem
%description common
VIM (VIsual editor iMproved) is an updated and improved version of the
@ -122,10 +122,14 @@ many different languages.
%package minimal
Summary: A minimal version of the VIM editor
Provides: vi
Provides: %{_bindir}/vi
# conflicts in package because of manpage move (bug #1599663)
Conflicts: %{name}-common < %{epoch}:8.1.1-1
# now vim-minimal ships vim.sh, vim.csh and vim.fish too, so we need to conflict
Conflicts: vim-enhanced < 2:8.2.1815-2
Provides: vi
Provides: %{_bindir}/vi
# needed for profile script
Requires: which
%description minimal
VIM (VIsual editor iMproved) is an updated and improved version of the
@ -138,10 +142,17 @@ only available when the vim-common package is installed.
%package enhanced
Summary: A version of the VIM editor which includes recent enhancements
Requires: vim-common = %{epoch}:%{version}-%{release} which
# now vim-minimal ships vim.sh, vim.csh and vim.fish too, so we need to conflict
Conflicts: vim-minimal < 2:8.2.1815-2
# vim bundles libvterm, which is used during build - so we need to provide
# bundled libvterm for catching possible libvterm CVEs
Provides: bundled(libvterm)
Provides: vim
Provides: %{_bindir}/mergetool
Provides: %{_bindir}/vim
Requires: vim-common = %{epoch}:%{version}-%{release} which
# needed for profile script
Requires: which
# suggest python3, python2, lua, ruby and perl packages because of their
# embedded functionality in Vim/GVim
Suggests: python3 python3-libs
@ -152,9 +163,6 @@ Suggests: ruby-libs ruby
%if "%{withlua}" == "1"
Suggests: lua-libs
%endif
# vim bundles libvterm, which is used during build - so we need to provide
# bundled libvterm for catching possible libvterm CVEs
Provides: bundled(libvterm)
%description enhanced
VIM (VIsual editor iMproved) is an updated and improved version of the
@ -181,6 +189,7 @@ packages that add vim files, p.e. additional syntax files or filetypes.
Summary: The VIM version of the vi editor for the X Window System - GVim
# needed in configure script to have correct macros enabled for GUI (#1603272)
BuildRequires: gtk3-devel
BuildRequires: libappstream-glib
# for sound support
BuildRequires: libcanberra-devel
BuildRequires: libX11-devel
@ -189,12 +198,11 @@ BuildRequires: libXt-devel
BuildRequires: libXpm-devel
BuildRequires: libICE-devel
Requires: vim-common = %{epoch}:%{version}-%{release} libattr >= 2.4 gtk3
Provides: gvim
Provides: %{_bindir}/mergetool
Provides: %{_bindir}/gvim
BuildRequires: gtk3-devel libSM-devel libXt-devel libXpm-devel libappstream-glib
Requires: hicolor-icon-theme
Requires: vim-common = %{epoch}:%{version}-%{release} libattr >= 2.4 gtk3
# suggest python3, python2, lua, ruby and perl packages because of their
# embedded functionality in Vim/GVim
Suggests: python3 python3-libs
@ -221,12 +229,12 @@ vim-common package.
%package default-editor
Summary: Set vim as the default editor
Requires: vim-enhanced
BuildArch: noarch
Provides: system-default-editor
Conflicts: system-default-editor
# conflict with nano-default-editor which doesn't provide system-default-editor
Conflicts: nano-default-editor < 5.3-3
Provides: system-default-editor
Requires: vim-enhanced
%description default-editor
This subpackage contains files needed to set Vim as the default editor.
@ -532,15 +540,12 @@ chmod 644 %{buildroot}/%{_datadir}/%{name}/%{vimdir}/doc/vim2html.pl \
chmod 644 ../runtime/doc/vim2html.pl
mkdir -p %{buildroot}/%{_sysconfdir}/profile.d
cp %{SOURCE1} %{buildroot}/%{_sysconfdir}/profile.d/vim.sh
cp %{SOURCE2} %{buildroot}/%{_sysconfdir}/profile.d/vim.csh
cp %{SOURCE16} %{buildroot}/%{_sysconfdir}/profile.d/vim-default-editor.sh
cp %{SOURCE17} %{buildroot}/%{_sysconfdir}/profile.d/vim-default-editor.csh
chmod 0644 %{buildroot}/%{_sysconfdir}/profile.d/vim.*
chmod 0644 %{buildroot}/%{_sysconfdir}/profile.d/vim-default-editor.*
install -p -m644 %{SOURCE1} %{buildroot}/%{_sysconfdir}/profile.d/vim.sh
install -p -m644 %{SOURCE2} %{buildroot}/%{_sysconfdir}/profile.d/vim.csh
install -p -m644 %{SOURCE16} %{buildroot}/%{_sysconfdir}/profile.d/vim-default-editor.sh
install -p -m644 %{SOURCE17} %{buildroot}/%{_sysconfdir}/profile.d/vim-default-editor.csh
mkdir -p %{buildroot}/%{_datadir}/fish/vendor_conf.d/
cp %{SOURCE18} %{buildroot}/%{_datadir}/fish/vendor_conf.d/vim-default-editor.fish
chmod 0644 %{buildroot}/%{_datadir}/fish/vendor_conf.d/vim-default-editor.fish
install -p -m644 %{SOURCE18} %{buildroot}/%{_datadir}/fish/vendor_conf.d/vim-default-editor.fish
install -p -m644 %{SOURCE4} %{buildroot}/%{_sysconfdir}/virc
install -p -m644 %{SOURCE5} %{buildroot}/%{_sysconfdir}/vimrc
@ -739,6 +744,8 @@ touch %{buildroot}/%{_datadir}/%{name}/vimfiles/doc/tags
%endif
%files minimal
%dir %{_sysconfdir}/profile.d/
%config(noreplace) %{_sysconfdir}/profile.d/vim.*
%config(noreplace) %{_sysconfdir}/virc
%{_bindir}/ex
%{_bindir}/vi
@ -753,11 +760,12 @@ touch %{buildroot}/%{_datadir}/%{name}/vimfiles/doc/tags
%{_mandir}/man5/virc.*
%files enhanced
%dir %{_sysconfdir}/profile.d/
%config(noreplace) %{_sysconfdir}/profile.d/vim.*
%{_bindir}/vim
%{_bindir}/rvim
%{_bindir}/vimdiff
%{_bindir}/vimtutor
%config(noreplace) %{_sysconfdir}/profile.d/vim.*
%files filesystem
%{_rpmconfigdir}/macros.d/macros.vim
@ -807,14 +815,15 @@ touch %{buildroot}/%{_datadir}/%{name}/vimfiles/doc/tags
%{_datadir}/icons/locolor/*/apps/*
%files default-editor
%dir %{_datadir}/fish/vendor_conf.d
%{_datadir}/fish/vendor_conf.d/vim-default-editor.fish
%dir %{_sysconfdir}/profile.d
%config(noreplace) %{_sysconfdir}/profile.d/vim-default-editor.*
%dir %{_datadir}/fish/vendor_conf.d
%config(noreplace) %{_datadir}/fish/vendor_conf.d/vim-default-editor.fish
%changelog
* Thu Oct 15 2020 Zdenek Dohnal <zdohnal@redhat.com> - 2:8.2.1815-2
- vim-default-editor.fish - dont give EDITOR universal scope
- vim.sh, vim.csh - set aliases only for OS default vi and vim
* Mon Oct 12 2020 Zdenek Dohnal <zdohnal@redhat.com> - 2:8.2.1815-2
- fix installing fish profile, set virtual provide for default editor