| |
| Posted by bearophile | PermalinkReply |
|
bearophile
| An interesting library for Scala language (found through Reddit):
https://github.com/lihaoyi/Ammonite#ammonite-010
I think this library is interesting for D not for its command line usage nor for the details of its syntax (that I think is too much succinct), but as an example of things you want to do in a handy way with Phobos, as:
// Get the current working directory
val d = cwd
// Copy a file or folder
cp(d/'file, d/'file2)
// Make a folder named "folder"
mkdir! d/'folder
// Rename all .scala files inside the folder d into .java files
ls! d | mv{case r"$x.scala" => s"$x.java"}
// Line-count of all .scala files recursively in d
ls.rec! cwd |? (_.ext == "scala") | read.lines | (_.size) sum
// Find and concatenate all .js files directly in the working directory
ls! cwd |? (_.ext == "js") | read |> write! wd/'target/"bundle.js"
// Make a directory
mkdir! cwd/'folder
// Move it
mv(cwd/'folder, cwd/'folder2)
// Copy it; recursive by default
cp(cwd/'folder2, cwd/'folder3)
// List the files in cwd
ls! cwd
// List the files in cwd recursively
ls.rec! cwd
// Remove one of them; recursive by default
rm! cwd/'folder2
// Write a file, if it doesn't exist
write(cwd/'folder2/"data.txt", "I am a cow")
// Write to a file, stomping over anything that exists
write.over(cwd/'folder2/"data.txt", "I am a cow")
// Append to a file
write.append(cwd/'folder2/"data.txt", "I am a cow")
// Read a file as a String
read! cwd/'folder2/"data.txt"
// Read a file as an Iterator[String]
read.lines! cwd/'folder2/"data.txt"
// Read a file as an Array[Byte]
read.bytes! cwd/'folder2/"data.bin"
// Check if a file or folder exists
exists! cwd/'folder2/"data.txt"
Bye,
bearophile
|