Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
http://www.lihaoyi.com/Ammonite/
Rock-solid shell scripting
with Ammonite
Maxim Novak
@maximnovakmaximn@wix.com https://gi...
01
List files
List files (recursively)
List all *.scala files
List the 3 largest *.scala files
Challenge… let’s ask Google
List the 3 largest *.scala files
Can’t really understand it
Seems to work…
http://toonclips.com/design/5803
http://www.clipartpanda.com/categories/man-thinking-drawing
(Lack of) Error handling
http://www.clipartpanda.com/categories/man-thinking-drawing
(Lack of) Error handling
Success
http://www.clipartpanda.com/categories/man-thinking-drawing
(Lack of) Error handling
Failed
Bash scripts are hard to understand,
hard to maintain, and very fragile
Bash scripts are hard to understand,
hard to maintain, and very fragile
We need something better
Why not ?
02
List files
import java.io.File
val file = new File(".")
if (file.exists && file.isDirectory) {
file.listFiles.toSeq
} else...
Write text to file
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
val file = Paths.get("hi.t...
What you really want is
What you really want is
the power of Scala
with the semantics of a shell
Welcome Ammonite!
03
List files
http://toonclips.com/design/9164
Structured data,
yes!
ls! wd is an alias for ls(wd)
List files (recursively)
List all *.scala files
List 3 largest *.scala files
Change directory
Write text to file
Running an executable
It’s easy breezy.
It’s easy breezy. And it’s safe.
Type safety
Main.scala:296: type mismatch;
found : ammonite.ops.Path
required: ammonite.ops.RelPath
relative/absolute
^
Compilation Fa...
Error handling
java.nio.file.NoSuchFileException: /Users/max/noSuchPath
sun.nio.fs.UnixException.translateToIOException(Un...
It’s easy breezy. And it’s safe.
Also, you can load any JVM library
to the shell.
Loading an external library
JVM ecosystem
at your fingertips
Power and safety
of Scala
Shell semantics
https://pixabay.com/en/shells-massage-therapy-s...
Thank You
Maxim Novak
@maximnovakmaximn@wix.com https://github.com/maximn
Upcoming SlideShare
Loading in …5
×

Rock-solid shell scripting with Ammonite

6,600 views

Published on

Are you tired of Bash scripts? Do you always forget the syntax, Googling the same commands over and over again? Don’t like Bash's dynamic nature?

We deserve better than that! Ammonite enables shell-like scripting in the Scala programming language. With all of Scala's power at your fingertips, why compromise on Bash's quirks?

Published in: Software

Rock-solid shell scripting with Ammonite

  1. 1. http://www.lihaoyi.com/Ammonite/ Rock-solid shell scripting with Ammonite Maxim Novak @maximnovakmaximn@wix.com https://github.com/maximn
  2. 2. 01
  3. 3. List files
  4. 4. List files (recursively)
  5. 5. List all *.scala files
  6. 6. List the 3 largest *.scala files Challenge… let’s ask Google
  7. 7. List the 3 largest *.scala files Can’t really understand it Seems to work… http://toonclips.com/design/5803
  8. 8. http://www.clipartpanda.com/categories/man-thinking-drawing (Lack of) Error handling
  9. 9. http://www.clipartpanda.com/categories/man-thinking-drawing (Lack of) Error handling Success
  10. 10. http://www.clipartpanda.com/categories/man-thinking-drawing (Lack of) Error handling Failed
  11. 11. Bash scripts are hard to understand, hard to maintain, and very fragile
  12. 12. Bash scripts are hard to understand, hard to maintain, and very fragile We need something better
  13. 13. Why not ? 02
  14. 14. List files import java.io.File val file = new File(".") if (file.exists && file.isDirectory) { file.listFiles.toSeq } else { Nil }
  15. 15. Write text to file import java.nio.file.{Paths, Files} import java.nio.charset.StandardCharsets val file = Paths.get("hi.txt") val content = "hello".getBytes(StandardCharsets.UTF_8) Files.write(file, content) http://humandefect.deviantart.com/art/U h-Oh-542255224 Verbose…
  16. 16. What you really want is
  17. 17. What you really want is the power of Scala with the semantics of a shell
  18. 18. Welcome Ammonite! 03
  19. 19. List files http://toonclips.com/design/9164 Structured data, yes! ls! wd is an alias for ls(wd)
  20. 20. List files (recursively)
  21. 21. List all *.scala files
  22. 22. List 3 largest *.scala files
  23. 23. Change directory
  24. 24. Write text to file
  25. 25. Running an executable
  26. 26. It’s easy breezy.
  27. 27. It’s easy breezy. And it’s safe.
  28. 28. Type safety
  29. 29. Main.scala:296: type mismatch; found : ammonite.ops.Path required: ammonite.ops.RelPath relative/absolute ^ Compilation Failed Type safety
  30. 30. Error handling java.nio.file.NoSuchFileException: /Users/max/noSuchPath sun.nio.fs.UnixException.translateToIOException(UnitExce sun.nio.fs.UnixException.rethrowAsIOException(UnitExcept sun.nio.fs.UnixException.rethrowAsIOException(UnitExcept sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(U
  31. 31. It’s easy breezy. And it’s safe. Also, you can load any JVM library to the shell.
  32. 32. Loading an external library
  33. 33. JVM ecosystem at your fingertips Power and safety of Scala Shell semantics https://pixabay.com/en/shells-massage-therapy-sand-beach-792912/ http://youandworld.am/news/5790.html Ammonite blurs the line between “system shell” and a “programming language” http://www.lihaoyi.com/Ammonite/
  34. 34. Thank You Maxim Novak @maximnovakmaximn@wix.com https://github.com/maximn

×