1
0
Fork 0

Add bash completion

This commit is contained in:
retropikzel 2025-11-07 16:07:31 +02:00
parent 0b82d376fa
commit e8311e1af4
4 changed files with 144 additions and 21 deletions

View File

@ -18,12 +18,15 @@ all: build-chibi
README.md: doc/compile-scheme.1 README.md: doc/compile-scheme.1
printf "<pre>\n$$(MANWIDTH=80 man -l doc/compile-scheme.1)\n</pre>" > README.md printf "<pre>\n$$(MANWIDTH=80 man -l doc/compile-scheme.1)\n</pre>" > README.md
build-chibi: replace-version:
sed 's/DEVELOPMENT_VERSION/${VERSION}/' compile-scheme.scm
build-chibi: replace-version
echo "#!/bin/sh" > compile-scheme echo "#!/bin/sh" > compile-scheme
echo "chibi-scheme -A ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme echo "chibi-scheme -A ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme
chmod +x compile-scheme chmod +x compile-scheme
build-chicken: build-chicken: replace-version
csc -R r7rs -X r7rs -static -c -J -unit libs.util -o libs.util.o libs/util.sld csc -R r7rs -X r7rs -static -c -J -unit libs.util -o libs.util.o libs/util.sld
ar rcs libs.util.a libs.util.o ar rcs libs.util.a libs.util.o
csc -R r7rs -X r7rs -static -c -J -unit libs.library-util -o libs.library-util.o libs/library-util.sld csc -R r7rs -X r7rs -static -c -J -unit libs.library-util -o libs.library-util.o libs/library-util.sld
@ -48,33 +51,33 @@ deb: build-chicken
dpkg-deb -b deb dpkg-deb -b deb
# FIXME # FIXME
#build-gauche: #build-gauche: replace-version
#echo "#!/bin/sh" > compile-scheme #echo "#!/bin/sh" > compile-scheme
#echo "gosh -r -I ${PREFIX}/lib/compile-scheme -I ${PREFIX}/lib/compile-scheme/libs ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compilescheme- #echo "gosh -r -I ${PREFIX}/lib/compile-scheme -I ${PREFIX}/lib/compile-scheme/libs ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compilescheme-
#chmod +x compile-scheme #chmod +x compile-scheme
build-guile: build-guile: replace-version
echo "#!/bin/sh" > compile-scheme echo "#!/bin/sh" > compile-scheme
echo "guile --r7rs --auto-compile -I -q -L ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme echo "guile --r7rs --auto-compile -I -q -L ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme
chmod +x compile-scheme chmod +x compile-scheme
# FIXME # FIXME
#build-kawa: #build-kawa: replace-version
#echo "#!/bin/sh" > compile-scheme #echo "#!/bin/sh" > compile-scheme
#echo "kawa -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED -J--enable-native-access=ALL-UNNAMED -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld:${PREFIX}/lib/compile-scheme/*.sld --r7rs ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\" 2> /dev/null" >> compile-scheme #echo "kawa -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED -J--enable-native-access=ALL-UNNAMED -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld:${PREFIX}/lib/compile-scheme/*.sld --r7rs ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\" 2> /dev/null" >> compile-scheme
#chmod +x compile-scheme #chmod +x compile-scheme
# FIXME # FIXME
#build-racket: #build-racket: replace-version
#echo "#!/bin/sh" > compile-scheme #echo "#!/bin/sh" > compile-scheme
#echo "racket -I r7rs -S ${PREFIX}/lib/compile-scheme --script ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme #echo "racket -I r7rs -S ${PREFIX}/lib/compile-scheme --script ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme
build-sagittarius: build-sagittarius: replace-version
echo "#!/bin/sh" > compile-scheme echo "#!/bin/sh" > compile-scheme
echo "sash -A ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme echo "sash -A ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme
chmod +x compile-scheme chmod +x compile-scheme
build-stklos: build-stklos: replace-version
echo "#!/bin/sh" > compile-scheme echo "#!/bin/sh" > compile-scheme
echo "stklos -I ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme echo "stklos -I ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme
chmod +x compile-scheme chmod +x compile-scheme
@ -85,6 +88,9 @@ install:
cp -r libs ${PREFIX}/lib/compile-scheme/ cp -r libs ${PREFIX}/lib/compile-scheme/
cp compile-scheme.scm ${PREFIX}/lib/compile-scheme/compile-scheme.scm cp compile-scheme.scm ${PREFIX}/lib/compile-scheme/compile-scheme.scm
install compile-scheme ${PREFIX}/bin/compile-scheme install compile-scheme ${PREFIX}/bin/compile-scheme
mkdir -p ${PREFIX}/share/man/man1
cp doc/compile-scheme.1 ${PREFIX}/share/man/man1/
if [ -d /etc/bash_completion.d ]; then cp bash_completion.sh /etc/bash_completion.d/compile-scheme; fi
uninstall: uninstall:
rm -rf ${PREFIX}/lib/compile-scheme rm -rf ${PREFIX}/lib/compile-scheme

101
bash_completion.sh Normal file
View File

@ -0,0 +1,101 @@
_compile_scheme()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
shortopts="-A -I"
longopts="--list-r6rs --list-r7rs --list-all --help --version"
targets="unix windows php"
outputfound=false
for i in "${COMP_WORDS[@]}"; do
if [[ "$i" == "-o" ]] ; then
outputfound=true
fi
done
targetfound=false
for i in "${COMP_WORDS[@]}"; do
if [[ "$i" == "-t" ]] ; then
targetfound=true
fi
done
if [[ "$outputfound" == "false" ]]; then
shortopts="${shortopts} -o"
fi
if [[ "$targetfound" == "false" ]]; then
shortopts="${shortopts} -t"
fi
opts="${shortopts} ${longopts}"
if [[ ${prev} == -o ]] ; then
COMPREPLY=( $(compgen -W "" -- ${cur}) )
return 0
elif [[ ${prev} == -I ]] ; then
COMPREPLY=()
return 0
elif [[ ${prev} == -A ]] ; then
COMPREPLY=()
return 0
elif [[ ${prev} == -t ]] ; then
COMPREPLY=( $(compgen -W "${targets}" -- ${cur}) )
return 0
elif [[ ${cur} == -o ]] ; then
COMPREPLY=("")
return 0
elif [[ ${cur} == -t ]] ; then
COMPREPLY=("")
return 0
elif [[ ${prev} == *.sps ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
elif [[ ${prev} == *.scm ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
elif [[ ${cur} == -* ]] ; then
for i in "${COMP_WORDS[@]}"; do
if [[ "$i" == *.sps ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
fi
if [[ "$i" == *.scm ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
fi
done
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
elif [[ ${cur} == --* ]] ; then
for i in "${COMP_WORDS[@]}"; do
if [[ "$i" == *.sps ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
fi
if [[ "$i" == *.scm ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
fi
done
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
elif [[ ${cur} == * ]] ; then
for i in "${COMP_WORDS[@]}"; do
if [[ "$i" == *.sps ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
fi
if [[ "$i" == *.scm ]] ; then
COMPREPLY=( $(compgen -W "${shortopts}" -- ${cur}) )
return 0
fi
done
COMPREPLY=( $(compgen -W "$(find . -maxdepth 1 -type f -name "*.sps" -o -name "*.scm" -printf '%f\n')" -- ${cur}) )
return 0
fi
}
# `foo` <tab> <tab> would show autocomplete above wordlist
complete -o bashdefault -o default -F _compile_scheme compile-scheme
# # If you want simplest wordlist, use below instead:
#complete -W "--help --verbose --version" compile-scheme
#

View File

@ -9,7 +9,20 @@
(libs library-util) (libs library-util)
(srfi 170)) (srfi 170))
(define-c-library c-stdlib
'("stdlib.h")
libc-name
'((additional-versions ("6"))))
(define-c-procedure c-system c-stdlib 'system 'int '(pointer))
(when (member "--help" (command-line)) (when (member "--help" (command-line))
(display "For help see: man compile-scheme")
(newline)
(exit 0))
(when (member "--version" (command-line))
(display "DEVELOPMENT_VERSION")
(newline) (newline)
(exit 0)) (exit 0))
@ -138,13 +151,6 @@
(newline) (newline)
(exit 0)) (exit 0))
(define-c-library c-stdlib
'("stdlib.h")
libc-name
'((additional-versions ("6"))))
(define-c-procedure c-system c-stdlib 'system 'int '(pointer))
#;(define search-library-files #;(define search-library-files
(lambda (directory) (lambda (directory)
(let ((result (list))) (let ((result (list)))

View File

@ -16,18 +16,18 @@ It supports most of SRFI-138 but also adds more features.
The program \fIinput-file\fR is compiled into an executable file. The program \fIinput-file\fR is compiled into an executable file.
The resulting executable file is written to file specified by the \fB-o\fR \fIpath\fR (if present) or to the file named same as \fIinput-file\fR but without the .scm or .sps suffix. The resulting executable file is written to file specified by the \fB-o\fR \fIpath\fR (if present) or to the file named same as \fIinput-file\fR but without the .scm or .sps suffix.
On Windows either .bat or .exe is appended to the output name. On Windows either .bat or .exe is appended to the output name.
.SS SUPPORT LIST .SH SUPPORTED IMPLEMENTATIONS
.P .P
Some implementations support both compiling and interpreting, in that Some implementations support both compiling and interpreting, in that
case only the compiler functionality is used and the implementation is marked case only the compiler functionality is used and the implementation is marked
as compiler. as compiler.
.IP "R6RS Compilers" .SS "R6RS Compilers"
loko loko
.IP "R6RS Interpreters" .SS "R6RS Interpreters"
chezscheme guile ikarus ironscheme mosh racket sagittarius ypsilon chezscheme guile ikarus ironscheme mosh racket sagittarius ypsilon
.IP "R7RS Compilers" .SS "R7RS Compilers"
chicken cyclone loko chicken cyclone loko
.IP "R7RS Interpreters" .SS "R7RS Interpreters"
chibi foment gauche guile kawa larceny meevax mit-scheme mosh racket sagittarius skint stklos tr7 ypsilon chibi foment gauche guile kawa larceny meevax mit-scheme mosh racket sagittarius skint stklos tr7 ypsilon
.SH OPTIONS .SH OPTIONS
.P .P
@ -47,9 +47,13 @@ Set the compilation target.
This is not needed if you are compiling for the target OS you are running. This is not needed if you are compiling for the target OS you are running.
Cross compilation is only supported in following cases: Cross compilation is only supported in following cases:
.IP .IP
From \fIunix\fR host to \fIwindows\fR target when chosen implementation is interpreter.
.IP
From \fIwindows\fR host to \fIunix\fR target when chosen implementation is interpreter.
.IP
From \fIunix\fR host to \fIphp\fR target when chosen implementation is interpreter. From \fIunix\fR host to \fIphp\fR target when chosen implementation is interpreter.
.IP .IP
From \fIunix\fR host to \fIwindows\fR target when chosen implementation is interpreter. From \fIwindows\fR host to \fIphp\fR target when chosen implementation is interpreter.
.P .P
.B \-\-list-r6rs .B \-\-list-r6rs
List supported R6RS implementations. List supported R6RS implementations.
@ -62,6 +66,12 @@ List all supported implementations.
.P .P
\fB\-\-list-targets\fR \fB\-\-list-targets\fR
List all supported compilation targets. List all supported compilation targets.
.P
\fB\-\-version\fR
Show the software version.
.P
\fB\-\-help\fR
Shows you command to read this manual page. :)
.SH ENVIRONMENT .SH ENVIRONMENT
.P .P
\fBCOMPILE_R7RS\fR \fBCOMPILE_R7RS\fR