Created
January 6, 2012 17:07
-
-
Save sroebuck/1571464 to your computer and use it in GitHub Desktop.
Running Scala shell scripts with library dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec /Users/sroebuck/local/bin/scalas $0 $@ | |
!# | |
/*** | |
libraryDependencies ++= Seq( | |
"com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0", | |
"joda-time" % "joda-time" % "2.0", | |
"org.joda" % "joda-convert" % "1.1" | |
) | |
*/ | |
import org.joda.time.LocalDate | |
import scalax.file.Path | |
val desktop = Path("/Users/sroebuck/Desktop") | |
val archive = Path("/Users/sroebuck/Archive/Desktop") | |
/** | |
* Copy all the files on the Desktop that were not modified today into the file archive. | |
*/ | |
val files = desktop.children() | |
val filtered = files.filter(f => new LocalDate(f.lastModified).isBefore(new LocalDate)) | |
val grouped = filtered.groupBy(f => new LocalDate(f.lastModified).withDayOfMonth(1)) | |
grouped.foreach { | |
case (date, files) => | |
val year = date.getYear | |
val month = date.getMonthOfYear | |
val dir = archive \ year.toString \ "%04d-%02d".format(year,month) | |
dir.createDirectory(failIfExists=false) | |
files.foreach { | |
file => | |
println("Moving '%s' to '%s'".format(file.name, dir.path)) | |
file.moveTo(dir \ file.name) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
java -Dsbt.main.class=sbt.ScriptMain \ | |
-Dsbt.boot.directory=/home/myhome/.sbt/boot \ | |
-Dsbt.log.noformat=true \ | |
-jar /the/path/to/my/sbt/0.11.2/libexec/sbt-launch.jar "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
archiveDesktopFiles.scala
is a Scala script which has dependencies on three external libraries.scalas
is just a shell script which runsscalas
which is part of a normal install ofsbt
but isn't provided with a command line executable.Further explanation of
scalas
can be found here: https://github.com/harrah/xsbt/wiki/Scripts.