blob: 38d0c334d99f286e12e5ace482d6226f01cbe8fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package TeXLive
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import sys.process._
object OsTools {
val OS = System.getProperty("os.name").map(_.toLower)
def isWindows: Boolean = {
OS.startsWith("windows")
}
def isApple: Boolean = {
OS.startsWith("mac os")
}
def isUnix: Boolean = {
!(isWindows || isApple)
}
def openFileCmd(f: String): Seq[String] = {
val absf = new java.io.File(f).getCanonicalPath
if (isWindows) {
Seq("cmd", "start", absf)
} else if (isApple) {
Seq("open", absf)
} else {
Seq("xdg-open", absf)
}
}
def openFile(f: String): Unit = {
val cmd = openFileCmd(f)
val bar = Future {
try {
cmd.!
} catch {
case e: Exception => println("Cannot run command: " + cmd + " -- " + e + "\n")
}
}
}
}
|