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 | |
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
-rw-r--r-- | Makefile | 8 | ||||
-rwxr-xr-x | bin/cl | 14 | ||||
-rwxr-xr-x | bin/li | 106 |
3 files changed, 110 insertions, 18 deletions
@@ -39,12 +39,8 @@ $(XDG_DATA_HOME)/euandreh/e.list.txt: ~/Documents/txt/ opt/aux/gen-e-list.sh sh opt/aux/gen-e-list.sh > $@ $(lisp-images): $(XDG_CONFIG_HOME)/lisp-cli/init.lisp bin/cl - I=`echo $@ | awk -F/ '$$0=$$(NF)' | cut -d. -f1` && cl \ - -I $$I \ - -v \ - -e '(ql:quickload :trivial-dump-core)' \ - -e '(trivial-dump-core:dump-image "$@")' \ - -e '(uiop:quit)' + I=`echo $@ | awk -F/ '$$0=$$(NF)' | cut -d. -f1` && \ + li -vI $$I -e '(uiop:quit)' @@ -56,7 +56,6 @@ help() { -f FILE a file to be evaluated (can be given more than once) -p print the value of the last given expression -M IMAGE load the given Lisp image - -m disable looking for the default image under $XDG_DATA_HOME -I IMPL use the given implementation (default: $LISP_CLI_IMPL) -n skip loading the implementation's init file -v verbose mode @@ -138,9 +137,8 @@ SCRIPT="$(mkstemp)" LISP_CLI_RC="${XDG_CONFIG_HOME:-$HOME/.config}/lisp-cli/init.lisp" VERBOSE=false IMAGE='' -SKIP_DEFAULT_IMAGE=false IMPL="${LISP_CLI_IMPL:-}" -while getopts 'e:f:pM:mI:nvlh' flag; do +while getopts 'e:f:pM:I:nvlh' flag; do case "$flag" in e) printf '%s\n' "$OPTARG" >> "$SCRIPT" @@ -151,9 +149,6 @@ while getopts 'e:f:pM:mI:nvlh' flag; do M) IMAGE="$OPTARG" ;; - m) - SKIP_DEFAULT_IMAGE=true - ;; I) IMPL="$OPTARG" ;; @@ -223,15 +218,10 @@ if [ -z "$IMPL" ]; then fi fi -DEFAULT_IMAGE="${XDG_DATA_HOME:-$HOME/.local/share}/lisp-cli/$IMPL.image" -if [ "$SKIP_DEFAULT_IMAGE" = false ] && [ -z "$IMAGE" ] && - [ -e "$DEFAULT_IMAGE" ]; then - IMAGE="$DEFAULT_IMAGE" -fi - case "$IMPL" in abcl) + ... exit 4 ;; allegro) @@ -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" "$@" |