forked from com-lihaoyi/os-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.scala
More file actions
67 lines (56 loc) · 1.87 KB
/
package.scala
File metadata and controls
67 lines (56 loc) · 1.87 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import scala.language.implicitConversions
import java.nio.file.FileSystem
import java.nio.file.FileSystems
import java.nio.file.Paths
package object os {
type Generator[+T] = geny.Generator[T]
val Generator = geny.Generator
implicit def GlobSyntax(s: StringContext): GlobInterpolator = new GlobInterpolator(s)
/**
* The root of the filesystem
*/
val root: Path = Path(java.nio.file.Paths.get(".").toAbsolutePath.getRoot)
def root(root: String, fileSystem: FileSystem = FileSystems.getDefault()): Path = {
val path = Path(fileSystem.getPath(root))
assert(path.root == root || path.root == root.replace('/', '\\'), s"$root is not a root path")
path
}
def resource(implicit resRoot: ResourceRoot = Thread.currentThread().getContextClassLoader) = {
os.ResourcePath.resource(resRoot)
}
// See https://github.com/com-lihaoyi/os-lib/pull/239
// and https://github.com/lightbend/mima/issues/794
// why the need the inner object to preserve binary compatibility
private object _home {
lazy val value = Path(System.getProperty("user.home"))
}
/**
* The user's home directory
*/
def home: Path = _home.value
/**
* The current working directory for this process.
*/
val pwd: Path = os.Path(java.nio.file.Paths.get(".").toAbsolutePath)
val up: RelPath = RelPath.up
val rel: RelPath = RelPath.rel
val sub: SubPath = SubPath.sub
/**
* Extractor to let you easily pattern match on [[os.Path]]s. Lets you do
*
* {{{
* @ val base/segment/filename = pwd
* base: Path = Path(Vector("Users", "haoyi", "Dropbox (Personal)"))
* segment: String = "Workspace"
* filename: String = "Ammonite"
* }}}
*
* To break apart a path and extract various pieces of it.
*/
object / {
def unapply(p: Path): Option[(Path, String)] = {
if (p.segmentCount != 0) Some((p / up, p.last))
else None
}
}
}