Create a gist now

Instantly share code, notes, and snippets.

@xolox /
Last active Sep 27, 2015

Shell script to build the latest Vim directly from the Mercurial repository
#!/bin/bash -e
# Shell script to build Vim from sources according to my taste :-)
# Author: Peter Odding <>
# Last Change: June 22, 2014
# URL:
# This shell script compiles Vim from the latest available sources (cloned and
# updated via Mercurial) on Debian derived distributions (I've successfully
# used this script on Ubuntu 10.04 and 12.04).
# To build a debug version of Vim, edit src/Makefile:
# 1. Use the gcc -g command line argument to compile with debugging symbols.
# 2. Set STRIP to /bin/true so that debugging symbols are not stripped.
main () {
# Prepare environment.
export CONF_OPT_COMPBY="$(find_compiled_by)"
export CONF_OPT_FEAT='--with-features=huge'
export CONF_OPT_GUI='--enable-gnome-check'
export CONF_OPT_LUA='--enable-luainterp'
export CONF_OPT_LUA_PREFIX='--with-lua-prefix=/usr'
export CONF_OPT_MULTIBYTE='--enable-multibyte'
export CONF_OPT_PYTHON='--enable-pythoninterp'
# Find the local checkout of the remote Mercurial repository.
local LOCAL_REPO=$(find_local_checkout)
# Clone or update the local repository checkout.
if [ -z "$LOCAL_REPO" ]; then
standout "Cloning repository"
hg clone "$REMOTE_REPO" vim
cd vim
standout "Pulling updates"
hg pull
standout "Applying updates"
hg update -C
# Make sure build time dependencies are satisfied.
standout "Installing dependencies"
sudo apt-get build-dep vim-gnome
sudo apt-get install autoconf lua5.1 liblua5.1-0-dev
# Rebuild the configure script. This takes a while but skipping this can lead
# to breakage when an incoming update has changed things and you don't
# rebuild the configure script.
standout "Rebuilding ./configure script"
make -C src autoconf
# This is where the magic happens.
standout "Building binaries"
standout "Installing files"
sudo make install
find_compiled_by () {
# Automatically fill in --compiled-by=... based on ~/.gitconfig or ~/.hgrc.
if [ -n "$CONF_OPT_COMPBY" ]; then
# If the compiled-by value has already been set we have nothing to do.
if [ -e ~/.gitconfig ]; then
# Get the compiled-by value from the user's git configuration file.
local name="$(extract ~/.gitconfig name)"
local email="$(extract ~/.gitconfig email)"
if [ -n "$name" -a -n "$email" ]; then
echo "--with-compiledby=\"$name <$email>\""
if [ -e ~/.hgrc ]; then
# Get the compiled-by value from the user's Mercurial configuration file.
local value="$(extract ~/.hgrc username)"
if [ -n "$value" ]; then
echo "--with-compiledby=\"$value\""
find_local_checkout () {
# Find the local checkout of the remote Mercurial repository.
for hg_directory in $(locate "*/.hg"); do
local repository=$(dirname "$hg_directory")
local remote=$(hg -R "$repository" paths | awk -F = '/^default[ \t]*=/ {print $2}' | strip)
if [ "$remote" = "$REMOTE_REPO" ]; then
echo $repository
extract () {
# Extract the value of a field in a *.ini style file. Doesn't know about
# sections (will treat all values as being in the same section).
local filename="$1"
local field="$2"
awk -F = "/^[ \t]*$field[ \t]*=/ {print \$2}" $filename | head -n1 | strip
strip () {
# Strip whitespace from the start and end of each line.
perl -pe 's/^\s*(.*?)\s*$/\1/'
standout () {
# Print a message that will stand out amongst lots of output.
tput bold
echo && echo "$@" && echo
tput sgr0
main "$@"
# vim: ts=2 sw=2 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment