Created
December 27, 2008 22:42
-
-
Save koduki/40327 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io._ | |
import java.net._ | |
import scala.io._ | |
import scala.xml._ | |
object Shell { | |
val sjis = "Shift_JIS" | |
val utf8 = "UTF8" | |
val jis = "jis" | |
val eucjp = "EUC_JP" | |
implicit def toRichSource(src:Source) = new { | |
def read = src.getLines.foldLeft(""){(r, line) => r + line + "\n"} | |
} | |
implicit def strAddtoURL(s:String) = new { def toURL = new URL(s) } | |
implicit def regexAddmatchRegex(r:scala.util.matching.Regex) = new { def =~(s:String) = s.matches(r.toString)} | |
implicit def strAddmatchRegex(s1:String) = new { | |
def =~(s2:String) = s2.matches(s1.toString) | |
def =~(r:scala.util.matching.Regex) = s1.matches(r.toString) | |
def encode(charset:String) = new String(s1.getBytes("iso-8859-1"), charset) | |
} | |
def open(url:URL):Source = { | |
Source.fromURL( url ) | |
} | |
implicit val path = "./" | |
def ls(implicit path:String) = { | |
val f = new File(path) | |
if (f.isFile) List(f) | |
else if(f.isDirectory) f.listFiles.toList | |
else List() | |
} | |
def exec(cmd:String)(implicit filter:(String) => String) = { | |
val process = Runtime.getRuntime().exec(cmd) | |
val in = process.getInputStream() | |
val br = new BufferedReader(new InputStreamReader(in)) | |
val sw = new StringWriter() | |
val pw = new PrintWriter(sw) | |
var s = br.readLine | |
while(s != null){ | |
pw.println( filter(s) ) | |
s = br.readLine | |
} | |
sw.toString | |
} | |
def main(args : Array[String]) : Unit = { | |
println( exec("ls -l /"){ x => "\\\\ " + x.split(" ")(0) + " //" } ) | |
println( exec("ls -l /") ) | |
// val xml = XML.loadString(html.encode(sjis).replaceAll("FIXED HREF","href").replaceAll("<!--.*","")) | |
//val url = xml \\ "ref" \ "@href" text | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment