From 97cfc2ddf846c2888afd363227ba0abe46099cd8 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 4 Mar 2014 15:44:02 -0800 Subject: [PATCH] swc-windows-installer.sh: Install nano source syntax highlighters Make writing Python source code (and a number of other languages) a bit more exciting for the eyes and easier on the brain by coloring strings, comments, and such. We need to install the source tarball because the compiled zip doesn't include the syntax highlighting scripts. To make that easier, I've extracted out the download / hash-check functionality into a new download(), which I use in both the old zip_install() and the new tar_install(). If the user doesn't have an existing ~/.nanorc, we populate it by adding 'include' options for each of the syntax files in the Nano tarball. If they do have an existing ~/.nanorc, I assume they know what they're doing ;). --- swc-windows-installer.sh | 64 +++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/swc-windows-installer.sh b/swc-windows-installer.sh index 8fc15f1..7ee61b1 100755 --- a/swc-windows-installer.sh +++ b/swc-windows-installer.sh @@ -6,6 +6,7 @@ # # The script: # * Installs nano and makes it accessible from msysGit +# * Creates ~/.nanorc with links to syntax highlighting configs # * Provides standard nosetests behavior (if Python and the nose # module are installed) for msysGit # @@ -28,25 +29,50 @@ die() exit 1 } +download() +{ + URL="${1}" + EXPECTED_MD5="${2}" + FILENAME=$(basename "${URL}") + msg "download ${URL} and install into ${INSTALL_DIRECTORY}" + curl -o "${FILENAME}" "${URL}" || die "couldn't download ${URL}" + MD5=$(md5sum "${FILENAME}" | cut -d ' ' -f 1) || die "couldn't hash ${FILENAME}" + if test "${MD5}" != "${EXPECTED_MD5}" + then + die "downloaded ${URL} has the wrong MD5 hash: ${MD5} != ${EXPECTED_MD5}" + fi +} + +tar_install() +{ + URL="${1}" + EXPECTED_MD5="${2}" + INSTALL_DIRECTORY="${3}" + shift 3 + TAR=$(basename "${URL}") + if test ! -d "${INSTALL_DIRECTORY}" + then + download "${URL}" "${EXPECTED_MD5}" + mkdir -p "${INSTALL_DIRECTORY}" || + die "couldn't create ${INSTALL_DIRECTORY}" + tar -xf "${FILENAME}" -C "${INSTALL_DIRECTORY}" "$@" || + die "couldn't unzip ${FILENAME} into ${INSTALL_DIRECTORY}" + fi +} + zip_install() { URL="${1}" EXPECTED_MD5="${2}" INSTALL_DIRECTORY="${3}" - ZIP=$(basename "${URL}") + FILENAME=$(basename "${URL}") if test ! -d "${INSTALL_DIRECTORY}" then - msg "download ${URL} and install into ${INSTALL_DIRECTORY}" - curl -o "${ZIP}" "${URL}" || die "couldn't download ${URL}" - MD5=$(md5sum "${ZIP}" | cut -d ' ' -f 1) || die "couldn't hash ${ZIP}" - if test "${MD5}" != "${EXPECTED_MD5}" - then - die "downloaded ${URL} has the wrong MD5 hash: ${MD5} != ${EXPECTED_MD5}" - fi + download "${URL}" "${EXPECTED_MD5}" mkdir -p "${INSTALL_DIRECTORY}" || die "couldn't create ${INSTALL_DIRECTORY}" - unzip "${ZIP}" -d "${INSTALL_DIRECTORY}" || - die "couldn't unzip ${ZIP} into ${INSTALL_DIRECTORY}" + unzip "${FILENAME}" -d "${INSTALL_DIRECTORY}" || + die "couldn't unzip ${FILENAME} into ${INSTALL_DIRECTORY}" fi } @@ -58,6 +84,22 @@ install_nano() "${INSTALL_DIRECTORY}" } +install_nanorc() +{ + INSTALL_DIRECTORY="${1}" + tar_install 'http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz' \ + '03233ae480689a008eb98feb1b599807' \ + "${INSTALL_DIRECTORY}" \ + --strip-components 1 && + if [ ! -f ~/.nanorc ] + then + for RCPATH in "${INSTALL_DIRECTORY}"/doc/syntax/*.nanorc + do + echo "include ${RCPATH}" >> ~/.nanorc + done + fi +} + # Creates a terminal-based nosetests entry point for msysGit create_nosetests_entry_point() { @@ -118,8 +160,10 @@ main() SWC_DIR=~/.swc BIN_DIR="${SWC_DIR}/bin" NANO_DIR="${SWC_DIR}/lib/nano" + NANORC_DIR="${SWC_DIR}/share/nanorc" create_nosetests_entry_point "${BIN_DIR}" || die "couldn't create nosetests" install_nano "${NANO_DIR}" || die "couldn't install nano" + install_nanorc "${NANORC_DIR}" || die "couldn't install nanorc" add_swc_paths "${NANO_DIR}" "${BIN_DIR}" || die "couldn't add SWC paths" set_default_editor nano || die "couldn't set EDITOR" } -- 2.26.2