diff options
Diffstat (limited to 'bin/li')
-rwxr-xr-x | bin/li | 104 |
1 files changed, 104 insertions, 0 deletions
@@ -0,0 +1,104 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + li [-I IMPL ] [-v] [OPTIONS...] + li -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -I IMPL use the given implementation (default: $LISP_CLI_IMPL) + -v verbose mode + -h, --help show this message + + OPTIONS options to be forwarded to cl(1) (lisp-cli) + + + Run the cl(1) executable with OPTIONS, but make sure an up-to-date + image exists and load it. + + + Examples: + + Launch a REPL from an image: + + $ li + + + Give options to cl(1): + + $ li -I sbcl -e '(print 123)' + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +VERBOSE=false +IMPL="${LISP_CLI_IMPL:-clisp}" +while getopts ':I:vh' flag; do + case "$flag" in + I) + IMPL="$OPTARG" + ;; + v) + VERBOSE=true + ;; + h) + usage + help + exit + ;; + *) + ;; + esac +done +if [ "${1:-}" = '--' ]; then + shift +fi + + +IMAGE="${XDG_DATA_HOME:-$HOME/.local/share}/lisp-cli/$IMPL.image" +BIN="$(command -v cl)" +INIT="${XDG_CONFIG_HOME:-$HOME/.config}/lisp-cli/init.lisp" +if [ ! -e "$IMAGE" ]; then + printf 'Bootstrapping a new "%s" image...\n' "$IMPL" >&2 + cl \ + -I "$IMPL" \ + -v \ + -e '(ql:quickload :trivial-dump-core)' \ + -E "(trivial-dump-core:dump-image \"$IMAGE\")" +elif [ -n "$(find "$0" "$BIN" "$INIT" -newer "$IMAGE")" ]; then + printf 'Refresh existing "%s" image...\n' "$IMPL" >&2 + cl \ + -M "$IMAGE" \ + -I "$IMPL" \ + -v \ + -e '(ql:quickload :trivial-dump-core)' \ + -E "(trivial-dump-core:dump-image \"$IMAGE\")" +fi + +if [ "$VERBOSE" = true ]; then + set -x +fi +exec cl -M "$IMAGE" "$@" |