Skip to content

Commit 436ab1b

Browse files
committed
added option to clear jar-cache and fixed tmp-directory creation on linux
1 parent 7620afc commit 436ab1b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

kscript

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ KSCRIPT_VERSION=1.0
66
## Show basic CLI description if no arguments are provided
77
if [ $# == 0 ] || [ $1 == "-v" ] || [ $1 == "--version" ] || [ $1 == "-h" ] || [ $1 == "--help" ]; then
88
echo "Usage : kscript <scriptfile or - for stdin> [<script_args>]*" >&2
9+
echo "Usage : kscript --clear-jar-cache" >&2
910
echo "" >&2
1011
echo "Easy-to-use scripting support for Kotlin on *nix-based systems." >&2
1112
echo "" >&2
@@ -16,6 +17,12 @@ if [ $# == 0 ] || [ $1 == "-v" ] || [ $1 == "--version" ] || [ $1 == "-h" ] ||
1617
exit 1;
1718
fi
1819

20+
## optionally clear up jar cache
21+
if [ $1 == "--clear-jar-cache" ]; then
22+
echo "Cleaning up jar cache..."
23+
rm ${TMPDIR}/.kscript*jar
24+
exit 0
25+
fi
1926

2027
## ... or use a cached version of it if possible
2128
#scriptFile="./test.kts"
@@ -37,8 +44,7 @@ if [ "$scriptFile" == "-" ]; then scriptFile="/dev/stdin"; fi
3744
# https://viewsby.wordpress.com/2013/09/06/bash-string-ends-with/
3845

3946
if [[ "$scriptFile" != *kts ]]; then
40-
tmpScript=${TMPDIR=/tmp}/kscript_stdin_$(mktemp -d XXXXXXXXX).kts # odd but works on macos as well
41-
# tmpScript=/tmp/kscript_stdin_$(mktemp -d XXXXXXXXX).kts # odd but works on macos as well
47+
tmpScript=${TMPDIR=/tmp}/kscript_stdin_${RANDOM}${RANDOM}.kts # odd but works on macos as well
4248
cat "${scriptFile}" > ${tmpScript}
4349

4450
## rename to use checksum as name to allow for jar-caching also when using stdin

0 commit comments

Comments
 (0)