Skip to content

Instantly share code, notes, and snippets.

@icassina
Last active March 19, 2016 18:35
Show Gist options
  • Select an option

  • Save icassina/c5197a9086db38057cf8 to your computer and use it in GitHub Desktop.

Select an option

Save icassina/c5197a9086db38057cf8 to your computer and use it in GitHub Desktop.
csolve.bash - simple bash wrappers around cave resolve and cave resume
#!/bin/bash
# 2016 (c) Ilya Cassina
#
# simple wrapper functions for `cave resolve` and `cave resume`
# using CAVE_RESUME_DIR="$HOME/.cave/resume" to store resume files.
#
# Installation: source this file from your ~/.bash_profile (or something like that)
#
# Usage:
#
# solve <target>
# solve <target> <options>
# solve <options> <target>
# => cave resolve --resume-file $CAVE_RESUME_DIR/default $target $options
# dosolve
# => cave resume --resume-file $CAVE_RESUME_DIR/default
# abort
# => rm -i $CAVE_RESUME_DIR/default
#
# csolve <target> ~> csolve $target $target
# csolve <target> <options> ~> csolve $target $target $options
# csolve <profile> <target>
# csolve <profile> <target> <options>
# => cave resolve --resume-file $CAVE_RESUME_DIR/$profile $target $options
# cdosolve <profile>
# => cave resume --resume-file $CAVE_RESUME_DIR/$profile
# cabort <profile>
# => rm -i $CAVE_RESUME_DIR/$profile
# Enjoy!
CAVE_RESUME_DIR="$HOME/.cave/resume"
function _cave_sanitize_profile() {
echo "$1" | tr '/' '-'
}
function _cave_solve() {
local profile=$(_cave_sanitize_profile $1)
shift
echo "~-=> executing: cave resolve --resume-file ${CAVE_RESUME_DIR}/${profile} $@"
[[ -d "${CAVE_RESUME_DIR}" ]] || mkdir -p "${CAVE_RESUME_DIR}"
cave resolve --resume-file "${CAVE_RESUME_DIR}/$profile" $@
}
function _cave_resume() {
local profile=$1
shift
echo "~-=> executing: cave resume --resume-file ${CAVE_RESUME_DIR}/${profile} $@"
cave resume --resume-file "${CAVE_RESUME_DIR}/$profile" $@
}
function csolve() {
local p=$1
echo "~-=> csolve $@"
# csolve gcc => csolve gcc gcc [no shift]
# csolve gcc -c => csolve gcc gcc -c [no shift]
# csolve a b c … => csolve a b c … [shift]
if [[ $# -gt 1 ]] && [[ ! $2 == -* ]] || [[ $# -gt 2 ]]; then
shift
else
echo " => csolve $p $@"
fi
_cave_solve $p $@ && (
echo "~-=> to commit: cdosolve $p"
) || (
echo "~-=> failed: csolve $p"
)
}
function cdosolve() {
local p=$1
shift
echo "~-=> cdosolve $p $@"
_cave_resume $p $@ && (
echo "~-=> done."
) || (
echo "~-=> failed: cdosolve $p $@"
)
}
function cabort() {
local p=$1
shift
echo "~-=> cabort $p"
echo "~-=> executing: rm -i ${CAVE_RESUME_DIR}/${p}"
rm -i "${CAVE_RESUME_DIR}/${p}"
echo "~-=> done."
}
function solve() {
echo "~-=> solve $@"
_cave_solve default $@ && (
echo "~-=> to commit: dosolve"
) || (
echo "~-=> failed: solve $@"
)
}
function dosolve() {
echo "~-=> dosolve $@"
_cave_resume default $@ && (
echo "~-=> done."
) || (
echo "~-=> failed: dosolve"
)
}
function abort() {
cabort default
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment