diff --git a/Makefile b/Makefile index b4f8aef..f912452 100644 --- a/Makefile +++ b/Makefile @@ -20,14 +20,35 @@ RUNTIME=autoload/vimpager.vim autoload/vimpager_utils.vim plugin/vimpager.vim ma SRC=vimcat ${RUNTIME} -all: balance-shellvim-stamp standalone/vimpager standalone/vimcat docs +PROGRAMS=vimpager vimcat + +all: ${PROGRAMS:=-vertag-stamp} balance-shellvim-stamp standalone/vimpager standalone/vimcat docs + +# set tag from git or ChangeLog +%-vertag-stamp: % + @echo updating version tag in $< + @tag=`git tag 2>/dev/null | tail -1`; \ + [ -z "$$tag" ] && tag=`sed -n '/^[0-9][0-9.]* [0-9-]*:$$/{s/ .*//;p;q;}' ChangeLog_$<.yml`; \ + if [ -n "$$tag" ]; then \ + sed -e 's/^\( *version_tag=\).*/\1'"$$tag"'/' $< > $<.work; \ + mv $<.work $<; \ + fi + @chmod +x $< + @touch $@ + +# other recipes need the version, get it from git describe or ChangeLog +%-version.txt: % + @echo building $@ + @git describe >$<-version.txt 2>/dev/null \ + || sed -n '/^[0-9][0-9.]* [0-9-]*:$$/{s/ .*//;p;q;}' ChangeLog_$<.yml >$<-version.txt balance-shellvim-stamp: vimcat Makefile + @echo balanceing vimcat @chmod +x scripts/balance-shellvim @scripts/balance-shellvim @touch balance-shellvim-stamp -standalone/%: % ${SRC:=.uu} inc/* Makefile +standalone/%: % ${SRC:=.uu} inc/* Makefile %-version.txt @echo building $@ @${MKPATH} `dirname $@` @base="`basename $@`"; \ @@ -47,7 +68,7 @@ standalone/%: % ${SRC:=.uu} inc/* Makefile sed -n '/^# END OF BUNDLED SCRIPTS$$/,$$p' "$$base" >> $@; \ fi @cp $@ $@.work - @sed -e 's|^\( *\)version=.*|\1version="'"`git describe`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"|' \ + @sed -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat $<-version.txt`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"\2|' \ -e '/^ *\. .*inc\/prologue.sh"$$/{' \ -e 'r inc/prologue.sh' \ -e d \ @@ -59,12 +80,12 @@ standalone/%: % ${SRC:=.uu} inc/* Makefile fi @chmod +x $@ -vimcat.uu: vimcat +vimcat.uu: vimcat vimcat-version.txt @echo uuencoding $< @echo 'vimcat_script() {' > $@ @printf "\t(cat <<'EOF') | do_uudecode > bin/vimcat\n" >> $@ @sed \ - -e 's|^\( *\)version=.*|\1version="'"`git describe`"' (bundled, shell=\$$(command -v \$$POSIX_SHELL))"|' \ + -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat vimcat-version.txt`"' (bundled, shell=\$$(command -v \$$POSIX_SHELL))"\2|' \ -e '/^ *\. .*inc\/prologue.sh"$$/{' \ -e 'r inc/prologue.sh' \ -e d \ @@ -143,7 +164,7 @@ install: docs vimpager.configured vimcat.configured echo ${INSTALLCONF} vimpagerrc "$${SYSCONFDIR}/vimpagerrc"; \ ${INSTALLCONF} vimpagerrc "$${SYSCONFDIR}/vimpagerrc" -%.configured: % +%.configured: % %-version.txt @echo configuring $< @POSIX_SHELL="`scripts/find_shell`"; \ if [ '${PREFIX}' = /usr ]; then \ @@ -154,7 +175,7 @@ install: docs vimpager.configured vimcat.configured sed -e '1{ s|.*|#!'"$$POSIX_SHELL"'|; }' \ -e 's|\$$POSIX_SHELL|'"$$POSIX_SHELL|" \ -e '/^ *\. .*inc\/prologue.sh"$$/d' \ - -e 's|^\( *\)version=.*|\1version="'"`git describe`"' (configured, shell='"$$POSIX_SHELL"')"|' \ + -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat $<-version.txt`"' (configured, shell='"$$POSIX_SHELL"')"\2|' \ -e '/^# FIND REAL PARENT DIRECTORY$$/,/^# END OF FIND REAL PARENT DIRECTORY$$/d' \ -e 's!^\( *\)runtime=.*!\1runtime='\''${PREFIX}/share/vimpager'\''!' \ -e 's!^\( *\)vimcat=.*!\1vimcat='\''${PREFIX}/bin/vimcat'\''!' \ @@ -247,6 +268,6 @@ html/%.html: %.md.work fi realclean distclean clean: - rm -rf *.work */*.work *-stamp *.deb *.tar.gz *.configured *.uu */*.uu man html standalone */with_meta_* + rm -rf *.work */*.work *-stamp *-version.txt *.deb *.tar.gz *.configured *.uu */*.uu man html standalone */with_meta_* .PHONY: all install install-deb uninstall docs realclean distclean clean diff --git a/vimcat b/vimcat index 3d75d75..de4937a 100755 --- a/vimcat +++ b/vimcat @@ -1,12 +1,12 @@ #!/bin/sh #!/usr/bin/env vim #! -#! vimcat 2.06 -#! #! This is a bash script that executes itself as a vimscript to do its work #! Based on _v by Magnus Woldrich: https://github.com/trapd00r/utils/blob/master/_v : if 0 + version_tag=2.06 + link=$0 while [ -h "$link" ]; do @@ -23,7 +23,8 @@ . "$project_dir""/inc/prologue.sh" - version="$(cd "$project_dir"; git describe 2>/dev/null) (git)" + version="$(cd "$project_dir" && git describe 2>/dev/null) (git)" \ + || version="$version_tag (checkout)" if command -v vim >/dev/null; then vim=vim @@ -34,25 +35,6 @@ exit 1 fi - # Check if version was set correctly from git - case "$version" in - [0-9].*) - ;; - *) - # use the version from the comment at the top of the file instead - i=4 - while true; do - if [ $i -eq 1 ]; then - read _hash _progname version - break - else - read _line - fi - i=$((i-1)) - done < "$0" - ;; - esac - quit() { ( kill "$vim_pid" >/dev/null 2>&1 @@ -376,8 +358,6 @@ squeeze_blank_lines() { : endif : endif : endif -: endwhile -: endif : endif : endwhile : endif diff --git a/vimpager b/vimpager index 5991eac..4dccb25 100755 --- a/vimpager +++ b/vimpager @@ -1,11 +1,11 @@ #!/bin/sh # -# vimpager 2.06 -# # Script for using ViM as a PAGER. # Based on Bram's less.sh. # git://github.com/rkitover/vimpager.git +version_tag=2.06 + # Just pass through if not on a tty if [ ! -t 1 ]; then exec cat "$@" @@ -29,7 +29,8 @@ project_dir=`dirname "$link"` . "$project_dir/inc/prologue.sh" -version="$(cd "$project_dir"; git describe 2>/dev/null) (git)" +version="$(cd "$project_dir" && git describe 2>/dev/null) (git)" \ + || version="$version_tag (checkout)" runtime='$project_dir' vimcat='$project_dir/vimcat' system_vimpagerrc='$project_dir/vimpagerrc' @@ -61,8 +62,6 @@ main() { extra_cmd= line_numbers=0 - check_version - # Check for certain parameters to pass on to vim (or conceivably do something else) # Couldn't use getopt or getopts as neither supports options prepended with + while [ $# -gt 0 ] ; do @@ -937,27 +936,6 @@ fits_on_screen() { ' num_files=$# total_lines=$lines total_cols=$cols file_sep_lines=3 first_file_sep_lines=2 - } -check_version() { - # Check if version was set correctly from git - case "$version" in - [0-9].*) - ;; - *) - # use the version from the comment at the top of the file instead - i=3 - while true; do - if [ $i -eq 1 ]; then - read _hash _progname version - break - else - read _line - fi - i=$((i-1)) - done < "$0" - ;; - esac -} - # INCLUDE BUNDLED SCRIPTS HERE # END OF BUNDLED SCRIPTS