patchlevel 2465

1918575 - Use wrappers for vi/vim instead of aliases
This commit is contained in:
Zdenek Dohnal 2021-02-04 09:46:48 +01:00
parent 54cbb9c68a
commit f3ef01b2e5
6 changed files with 86 additions and 136 deletions

10
view_wrapper Normal file
View File

@ -0,0 +1,10 @@
#!/usr/bin/sh
# run vim -R if available
if test -f /usr/libexec/vim
then
exec /usr/libexec/vim -R "$@"
fi
# run vi otherwise
exec /usr/libexec/vi "$@"

20
vim.csh
View File

@ -1,20 +0,0 @@
# 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 = `command -v vim`
set vi_cond = `command -v 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 vi
breaksw
endsw
# just in case
unset vim_cond
unset vi_cond

View File

@ -1,25 +0,0 @@
# This will avoid user defined aliases and possibly stuff defined earlier in the PATH.
# Redirecting is for the case when the binary is missing.
set vim_cond (command -v vim)
set vi_cond (command -v vi)
switch "$vim_cond-$vi_cond"
case /usr/bin/vim-/usr/bin/vi
# apply only if founded vim and vi are in the expected dir from distro
function vi
command vim $argv
end
function view
command vim -R $argv
end
case -/usr/bin/vi
# apply only when no vim is installed and founded vi is in the expected dir from distro
function vim
command vi $argv
end
end
# just in case
set -e vim_cond
set -e vi_cond

32
vim.sh
View File

@ -1,32 +0,0 @@
__vi_internal_vim_alias()
(
# run vim if installed
test -f /usr/bin/vim && exec /usr/bin/vim "$@"
# run vi otherwise
test -f /usr/bin/vi && exec /usr/bin/vi "$@"
)
__view_internal_vim_alias()
(
# run vim -R instead of view if vim installed
test -f /usr/bin/vim && exec /usr/bin/vim -R "$@"
# run view otherwise
test -f /usr/bin/view && exec /usr/bin/view "$@"
)
if [ -n "${BASH_VERSION-}" -o -n "${KSH_VERSION-}" -o -n "${ZSH_VERSION-}" ]; then
# This will avoid user defined aliases
case "$(command -v vim)-$(command -v vi)" in
"/usr/bin/vim-/usr/bin/vi" | "-/usr/bin/vi")
# apply only when founded vim and vi are in expected dirs from distro
# we need to call a shell function to avoid shell restarts when vi/vim
# is being installed/uninstalled
alias vi=__vi_internal_vim_alias
alias view=__view_internal_vim_alias
alias vim=__vi_internal_vim_alias
;;
esac
fi

125
vim.spec
View File

@ -24,23 +24,24 @@ Version: %{baseversion}.%{patchlevel}
Release: 1%{?dist}
License: Vim and MIT
Source0: ftp://ftp.vim.org/pub/vim/unix/vim-%{baseversion}-%{patchlevel}.tar.bz2
Source1: vim.sh
Source2: vim.csh
Source4: virc
Source5: vimrc
Source7: gvim16.png
Source8: gvim32.png
Source9: gvim48.png
Source10: gvim64.png
Source1: virc
Source2: vimrc
Source3: gvim16.png
Source4: gvim32.png
Source5: gvim48.png
Source6: gvim64.png
Source7: spec-template.new
Source8: macros.vim
Source9: vim-default-editor.sh
Source10: vim-default-editor.csh
Source11: vim-default-editor.fish
Source12: view_wrapper
Source13: vim_wrapper
%if %{withvimspell}
Source13: vim-spell-files.tar.bz2
Source100: vim-spell-files.tar.bz2
%endif
Source14: spec-template.new
Source15: macros.vim
Source16: vim-default-editor.sh
Source17: vim-default-editor.csh
Source18: vim-default-editor.fish
Source19: vim.fish
Patch2002: vim-7.0-fixkeys.patch
Patch2003: vim-7.4-specsyntax.patch
@ -125,11 +126,9 @@ Summary: A minimal version of the VIM editor
# conflicts in package because of manpage move (bug #1599663)
# remove when a new RHEL is released (current 8)
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
# remove when a new RHEL is released (current 8)
Conflicts: vim-enhanced < 2:8.2.2146-2
Provides: vi
Provides: %{_bindir}/vi
Requires: vim-wrappers
%description minimal
VIM (VIsual editor iMproved) is an updated and improved version of the
@ -142,9 +141,6 @@ only available when the vim-common package is installed.
%package enhanced
Summary: A version of the VIM editor which includes recent enhancements
# now vim-minimal ships vim.sh, vim.csh and vim.fish too, so we need to conflict
# remove when a new RHEL is released (current 8)
Conflicts: vim-minimal < 2:8.2.2146-2
# vim bundles libvterm, which is used during build - so we need to provide
# bundled libvterm for catching possible libvterm CVEs
Provides: bundled(libvterm)
@ -152,6 +148,7 @@ Provides: vim
Provides: %{_bindir}/mergetool
Provides: %{_bindir}/vim
Requires: vim-common = %{epoch}:%{version}-%{release} which
Requires: vim-wrappers
# suggest python3, python2, lua, ruby and perl packages because of their
# embedded functionality in Vim/GVim
Suggests: python3 python3-libs
@ -238,6 +235,18 @@ Requires: vim-enhanced
%description default-editor
This subpackage contains files needed to set Vim as the default editor.
%package wrappers
Summary: Ships shell wrappers defining vi/view/vim
BuildArch: noarch
Conflicts: vim-enhanced < 2:8.2.2465-1
Conflicts: vim-minimal < 2:8.2.2465-1
%description wrappers
The subpackage contains shell scripts, which are shipped as vi/view/vim.
The scripts provide the same functionality as aliases, but they work for sudo too.
They are shipped as a separate package because both vim-minimal and vim-enhanced need
them.
%prep
%setup -q -b 0 -n %{vimdir}
@ -255,7 +264,7 @@ perl -pi -e "s,bin/nawk,bin/awk,g" runtime/tools/mve.awk
# install spell files
%if %{withvimspell}
%{__tar} xjf %{SOURCE13}
%{__tar} xjf %{SOURCE100}
%endif
%patch3000 -p1
@ -402,7 +411,7 @@ cp vim enhanced-vim
mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}/%{_datadir}/%{name}/vimfiles/{after,autoload,colors,compiler,doc,ftdetect,ftplugin,indent,keymap,lang,plugin,print,spell,syntax,tutor}
mkdir -p %{buildroot}/%{_datadir}/%{name}/vimfiles/after/{autoload,colors,compiler,doc,ftdetect,ftplugin,indent,keymap,lang,plugin,print,spell,syntax,tutor}
cp -f %{SOURCE14} %{buildroot}/%{_datadir}/%{name}/vimfiles/template.spec
cp -f %{SOURCE7} %{buildroot}/%{_datadir}/%{name}/vimfiles/template.spec
cp runtime/doc/uganda.txt LICENSE
# Those aren't Linux info files but some binary files for Amiga:
rm -f README*.info
@ -413,21 +422,25 @@ cd src
# and put the stripped files into correct dirs. Build system (koji/brew)
# does it for us, so there is no need to do it in Vim
%make_install BINDIR=%{_bindir} VIMRCLOC=/etc VIMRUNTIMEDIR=/usr/share/vim/%{vimdir} STRIP=/bin/true
# make install creates vim binary and view symlink, they will be wrappers
# so remove them here
%{_bindir}/rm -f %{buildroot}%{_bindir}/{vim,view}
make installgtutorbin DESTDIR=%{buildroot} BINDIR=%{_bindir} VIMRCLOC=/etc VIMRUNTIMEDIR=/usr/share/vim/%{vimdir}
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/{16x16,32x32,48x48,64x64}/apps
install -m755 minimal-vim %{buildroot}%{_bindir}/vi
install -m755 enhanced-vim %{buildroot}%{_bindir}/vim
mkdir -p %{buildroot}%{_libexecdir}
install -m755 minimal-vim %{buildroot}%{_libexecdir}/vi
install -m755 enhanced-vim %{buildroot}%{_libexecdir}/vim
install -m755 gvim %{buildroot}%{_bindir}/gvim
install -p -m644 %{SOURCE7} \
install -m755 %{SOURCE12} %{buildroot}%{_bindir}/view
install -m755 %{SOURCE13} %{buildroot}%{_bindir}/vim
install -p -m644 %{SOURCE3} \
%{buildroot}%{_datadir}/icons/hicolor/16x16/apps/gvim.png
install -p -m644 %{SOURCE8} \
install -p -m644 %{SOURCE4} \
%{buildroot}%{_datadir}/icons/hicolor/32x32/apps/gvim.png
install -p -m644 %{SOURCE9} \
install -p -m644 %{SOURCE5} \
%{buildroot}%{_datadir}/icons/hicolor/48x48/apps/gvim.png
install -p -m644 %{SOURCE10} \
install -p -m644 %{SOURCE6} \
%{buildroot}%{_datadir}/icons/hicolor/64x64/apps/gvim.png
#cp -f %{SOURCE17} %{buildroot}/%{_datadir}/%{name}/%{vimdir}/ftplugin/spec.vim
#cp -f %{SOURCE18} %{buildroot}/%{_datadir}/%{name}/%{vimdir}/syntax/spec.vim
# Register as an application to be visible in the software center
#
@ -473,12 +486,12 @@ SentUpstream: 2014-05-22
EOF
( cd %{buildroot}
ln -sf vi ./%{_bindir}/rvi
ln -sf vi ./%{_bindir}/rview
ln -sf vi ./%{_bindir}/view
ln -sf vi ./%{_bindir}/ex
ln -sf vim ./%{_bindir}/rvim
ln -sf vim ./%{_bindir}/vimdiff
ln -sf %{_bindir}/vim .%{_bindir}/vi
ln -sf %{_libexecdir}/vi .%{_bindir}/rvi
ln -sf %{_libexecdir}/vi .%{_bindir}/rview
ln -sf %{_libexecdir}/vi .%{_bindir}/ex
ln -sf %{_libexecdir}/vim .%{_bindir}/rvim
ln -sf %{_libexecdir}/vim .%{_bindir}/vimdiff
perl -pi -e "s,%{buildroot},," .%{_mandir}/man1/vim.1 .%{_mandir}/man1/vimtutor.1
rm -f .%{_mandir}/man1/rvim.1
cp -p .%{_mandir}/man1/vim.1 .%{_mandir}/man1/vi.1
@ -539,19 +552,13 @@ chmod 644 %{buildroot}/%{_datadir}/%{name}/%{vimdir}/doc/vim2html.pl \
chmod 644 ../runtime/doc/vim2html.pl
mkdir -p %{buildroot}/%{_sysconfdir}/profile.d
install -p -m644 %{SOURCE1} %{buildroot}/%{_sysconfdir}/profile.d/vi.sh
install -p -m644 %{SOURCE1} %{buildroot}/%{_sysconfdir}/profile.d/vim.sh
install -p -m644 %{SOURCE2} %{buildroot}/%{_sysconfdir}/profile.d/vi.csh
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
install -p -m644 %{SOURCE9} %{buildroot}/%{_sysconfdir}/profile.d/vim-default-editor.sh
install -p -m644 %{SOURCE10} %{buildroot}/%{_sysconfdir}/profile.d/vim-default-editor.csh
mkdir -p %{buildroot}/%{_datadir}/fish/vendor_conf.d/
install -p -m644 %{SOURCE18} %{buildroot}/%{_datadir}/fish/vendor_conf.d/vim-default-editor.fish
install -p -m644 %{SOURCE11} %{buildroot}/%{_datadir}/fish/vendor_conf.d/vim-default-editor.fish
mkdir -p %{buildroot}/%{_datadir}/fish/vendor_functions.d/
install -p -m644 %{SOURCE19} %{buildroot}/%{_datadir}/fish/vendor_functions.d/vi.fish
install -p -m644 %{SOURCE19} %{buildroot}/%{_datadir}/fish/vendor_functions.d/vim.fish
install -p -m644 %{SOURCE4} %{buildroot}/%{_sysconfdir}/virc
install -p -m644 %{SOURCE5} %{buildroot}/%{_sysconfdir}/vimrc
install -p -m644 %{SOURCE1} %{buildroot}/%{_sysconfdir}/virc
install -p -m644 %{SOURCE2} %{buildroot}/%{_sysconfdir}/vimrc
# if Vim isn't built for Fedora, use redhat augroup
%if 0%{?rhel} >= 7
@ -560,7 +567,7 @@ sed -i -e "s/augroup fedora/augroup redhat/" %{buildroot}/%{_sysconfdir}/virc
%endif
mkdir -p %{buildroot}%{_rpmconfigdir}/macros.d/
install -p -m644 %{SOURCE15} %{buildroot}%{_rpmconfigdir}/macros.d/
install -p -m644 %{SOURCE8} %{buildroot}%{_rpmconfigdir}/macros.d/
(cd ../runtime; rm -rf doc; ln -svf ../../vim/%{vimdir}/doc docs;)
rm -f %{buildroot}/%{_datadir}/vim/%{vimdir}/macros/maze/maze*.c
@ -591,6 +598,7 @@ echo ".so man1/vim.1" > %{buildroot}/%{_mandir}/man5/vimrc.5
echo ".so man1/vi.1" > %{buildroot}/%{_mandir}/man5/virc.5
touch %{buildroot}/%{_datadir}/%{name}/vimfiles/doc/tags
# Refresh documentation helptags
%transfiletriggerin common -- %{_datadir}/%{name}/vimfiles/doc
%{_bindir}/vim -c ":helptags %{_datadir}/%{name}/vimfiles/doc" -c :q &> /dev/null || :
@ -747,16 +755,17 @@ touch %{buildroot}/%{_datadir}/%{name}/vimfiles/doc/tags
%lang(zu) %{_datadir}/%{name}/%{vimdir}/spell/zu.*
%endif
%files minimal
%dir %{_datadir}/fish/vendor_functions.d
%{_datadir}/fish/vendor_functions.d/vi.fish
%config(noreplace) %{_sysconfdir}/profile.d/vi.*
%config(noreplace) %{_sysconfdir}/virc
%{_bindir}/ex
%files wrappers
%{_bindir}/vi
%{_bindir}/view
%{_bindir}/vim
%files minimal
%config(noreplace) %{_sysconfdir}/virc
%{_bindir}/ex
%{_bindir}/rvi
%{_bindir}/rview
%{_libexecdir}/vi
%{_mandir}/man1/vi.*
%{_mandir}/man1/ex.*
%{_mandir}/man1/rvi.*
@ -765,13 +774,10 @@ touch %{buildroot}/%{_datadir}/%{name}/vimfiles/doc/tags
%{_mandir}/man5/virc.*
%files enhanced
%dir %{_datadir}/fish/vendor_functions.d
%{_datadir}/fish/vendor_functions.d/vim.fish
%config(noreplace) %{_sysconfdir}/profile.d/vim.*
%{_bindir}/vim
%{_bindir}/rvim
%{_bindir}/vimdiff
%{_bindir}/vimtutor
%{_libexecdir}/vim
%files filesystem
%{_rpmconfigdir}/macros.d/macros.vim
@ -829,6 +835,7 @@ touch %{buildroot}/%{_datadir}/%{name}/vimfiles/doc/tags
%changelog
* Thu Feb 04 2021 Zdenek Dohnal <zdohnal@redhat.com> - 2:8.2.2465-1
- patchlevel 2465
- 1918575 - Use wrappers for vi/vim instead of aliases
* Thu Feb 04 2021 Zdenek Dohnal <zdohnal@redhat.com> - 2:8.2.2451-2
- vim-update.sh: apply changes master->rawhide

10
vim_wrapper Normal file
View File

@ -0,0 +1,10 @@
#!/usr/bin/sh
# run vim if available
if test -f /usr/libexec/vim
then
exec /usr/libexec/vim "$@"
fi
# run vi otherwise
exec /usr/libexec/vi "$@"