#!/bin/bash WIKIROOT=/home/hugo/wiki/ WIKI_LIST=$(ls $WIKIROOT | grep -v html) # A simple script for managing a vimwiki git repo. # Allows slightly simpler edits and commits. wiki_list="" # # Adds all files to git, and commits with either the arguments as # message, or with the current time as the message. # Assumes that PWD is a git repo. # function commit { if [ $# -lt 2 ]; then msg="$(date)" else msg="$*" fi git add -A git commit -m "$msg" } # # Like commit above, but ammends # function ammend { if [ $# -eq 1 ]; then git commit --amend else msg="$*" git commit --amend -m "$msg" fi } # # Run function on wiki # function wiki_do { wiki=$1 command=$2 pushd $WIKIROOT/$wiki shift case $command in commit) shift commit $@ ;; ammend) shift ammend $@ ;; g|go) commit $@ git push ;; echo) echo "-- $wiki --" ;; *) eval "git $@" ;; esac } # == MAIN == # # Parse command line options # while [ $# -ne 0 ]; do case $1 in -w|--wiki) shift wiki_list="$1 $wiki_list" shift ;; -l|--list) shift echo "Available Wikis:" echo "================" for w in $WIKI_LIST; do echo " - $w" done exit ;; -h|--help|-?) shift cat - <<- EOF Wiki helper. Usage: --help | -h :: Display this help --list | -l :: Show available wikis --wiki | -w :: specify a specific wiki for operation Default acts on all wikis. wi commit [msg] :: Create a git commit on specified wikis wi ammend [msg] :: Change last commit wi g [msg] :: wi commit [msg]; wi push wi [git-command] :: run git commands on wikis EOF exit ;; *) break ;; esac done # Edit the given wiki if no further argument is given if [ $# -eq 0 ]; then set -- ${wiki_list:-$WIKI_LIST} vim $WIKIROOT/$1/index.* exit fi # Run given command for all wikis for wiki in ${wiki_list:-$WIKI_LIST}; do echo "== $wiki ==" wiki_do $wiki $@ & done wait