diff options
| author | EuAndreh <eu@euandre.org> | 2022-10-24 15:41:50 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2022-10-24 15:41:50 -0300 |
| commit | abad340cfac10498cb71cff42b06cc5b1f2e525b (patch) | |
| tree | b33ddc64c46386c9440d8332baea87ad76b4d9de /bin/li | |
| parent | bin/cl: s/NIL/nil/ (diff) | |
| download | dotfiles-abad340cfac10498cb71cff42b06cc5b1f2e525b.tar.gz dotfiles-abad340cfac10498cb71cff42b06cc5b1f2e525b.tar.xz | |
bin/cl: Move automatic image handling out to bin/li
Diffstat (limited to 'bin/li')
| -rwxr-xr-x | bin/li | 106 |
1 files changed, 106 insertions, 0 deletions
@@ -0,0 +1,106 @@ +#!/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 (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=~/.usr/bin/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\")" \ + -e '(uiop:quit)' +elif [ "$0" -nt "$IMAGE" ] || [ "$BIN" -nt "$IMAGE" ] || [ "$INIT" -nt "$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\")" \ + -e '(uiop:quit)' +fi + +if [ "$VERBOSE" = true ]; then + set -x +fi +exec cl -M "$IMAGE" "$@" |
