0

I am intending to write a shell script (if specifics are required, it will be executed in Zsh) that will determine the latest Vim patch via running:

git pull origin master
vernew=$(git describe --tags | sed 's/^v//;s/-/./g')

with a local copy of Vim's git repository, compare it to the version of Vim I have presently installed and if the two are different it will modify the patch level defined in the spec file I have in my Open Build Service (OBS) Vim repository. To be able to do this I need to know how to define a variable as being equal to the version of Vim presently installed. Defining it as:

verold=$(vim --version)

is not an option as running vim --version for me, at least, returns:

VIM - Vi IMproved 7.4 (2013 Aug 10)
Included patches: 1-1304
Compiled by 'http://www.opensuse.org/'
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +tag_binary
+arabic          +file_in_path    +mouse_sgr       +tag_old_static
+autocmd         +find_in_path    -mouse_sysmouse  -tag_any_white
-balloon_eval    +float           +mouse_urxvt     -tcl
-browse          +folding         +mouse_xterm     +terminfo
++builtin_terms  -footer          +multi_byte      +termresponse
+byte_offset     +fork()          +multi_lang      +textobjects
+channel         +gettext         -mzscheme        +title
+cindent         -hangul_input    +netbeans_intg   -toolbar
+clientserver    +iconv           +path_extra      +user_commands
+clipboard       +insert_expand   +perl/dyn        +vertsplit
+cmdline_compl   +job             +persistent_undo +virtualedit
+cmdline_hist    +jumplist        +postscript      +visual
+cmdline_info    +keymap          +printer         +visualextra
+comments        +langmap         +profile         +viminfo
+conceal         +libcall         +python/dyn      +vreplace
+cryptv          +linebreak       +python3/dyn     +wildignore
+cscope          +lispindent      +quickfix        +wildmenu
+cursorbind      +listcmds        +reltime         +windows
+cursorshape     +localmap        +rightleft       +writebackup
+dialog_con      +lua/dyn         +ruby/dyn        +X11
+diff            +menu            +scrollbind      +xfontset
+digraphs        +mksession       +signs           -xim
-dnd             +modify_fname    +smartindent     +xsmp_interact
-ebcdic          +mouse           +sniff           +xterm_clipboard
+emacs_tags      -mouseshape      +startuptime     -xterm_save
+eval            +mouse_dec       +statusline      -xpm
+ex_extra        -mouse_gpm       -sun_workshop    
+extra_search    -mouse_jsbterm   +syntax          
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/current"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=1 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -Wall -pipe -fno-strict-aliasing      
Linking: gcc   -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.22.0/x86_64-linux-thread-multi/CORE   -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE -lXt -lX11 -lSM -lICE  -lm -lnsl    -ltinfo -lacl -lattr -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.22.0/x86_64-linux-thread-multi/CORE  -L/usr/local/lib64 -fstack-protector-strong  -L/usr/lib/perl5/5.22.0/x86_64-linux-thread-multi/CORE -lperl -lm -ldl -lcrypt -lpthread  

the second line of this output contains what I am interested in, the patch level. But I do not know how to define verold as being equal to just the patch level. The full version (i.e., 7.4.1304) is also an acceptable verold value too, if you know how to give me this value.

2
verold=$(vim --version |sed -n 's/^Included patches:\s1-*//p')
  • Almost, this returns 1-1304, I just want 1304, so vim --version |sed -n 's/^Included patches:\s1-*//p' does the job. I tried to edit your answer but there's not enough characters between the correct code and yours for this edit to be acceptable. – BH2017 Feb 13 '16 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.