Skip to content

Instantly share code, notes, and snippets.

@dwijnand
Forked from paulp/sbt-new
Created March 8, 2019 17:05
Show Gist options
  • Save dwijnand/26a1a61410c39388d8979783df218f42 to your computer and use it in GitHub Desktop.
Save dwijnand/26a1a61410c39388d8979783df218f42 to your computer and use it in GitHub Desktop.
a less messy sbt new
#!/usr/bin/env bash
#
# Intercepting the output of 'sbt new' directly fails
# because it asks interactive questions so we can't process
# line by line. An apparent OSX-specific bug in egrep
# fails on lookbehind clauses so we use ag. Capturing
# the interactive output with script succeeds, but script
# uses \r\n to terminate lines so we can't match the
# filename with '.*' or we get
#
# mv: rename ./proj\r to /tmp/proj\r: No such file or directory
#
# Remember this entire wrapper only exists because 'sbt new'
# insensibly wants to spew build files into your current directory.
set -euo pipefail
initial="$(pwd)"
scratch="$(mktemp -dt sbt-new)"
cd $scratch
script -q out.txt sbt -Dsbt.log.noformat=true new "$@"
proj="$( rg -o '(?:Template applied in )([^\r\n]*)' -r '$1' out.txt )"
mv -i "$proj" "$initial"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment