Skip to content

Commit 79bfcd8

Browse files
RealPath for cd, ls accessor
1 parent 55deb94 commit 79bfcd8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

core/src/main/scala/io/chrisdavenport/shellfish/Shell.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ trait Shell[F[_]]{
139139
/** Show all matching executables in PATH, not just the first */
140140
def whichAll(path: String): Stream[F, String]
141141

142+
def ls: Stream[F, String]
142143
def ls(path: String): Stream[F, String]
143144
}
144145

@@ -208,8 +209,9 @@ object Shell {
208209

209210
def cd(path: String): F[Unit] = for {
210211
newPath <- getResolved(path)
211-
out <- files.isDirectory(newPath).ifM(
212-
setWd(newPath.toAbsolutePath.toString),
212+
real = newPath.toRealPath()
213+
out <- files.isDirectory(real).ifM(
214+
setWd(real.toString),
213215
new RuntimeException(s"cd: no such file or directory $path").raiseError
214216
)
215217
} yield out
@@ -306,9 +308,10 @@ object Shell {
306308
.map(_.toString)
307309
)
308310

311+
def ls: Stream[F, String] = ls("")
309312
def ls(path: String): Stream[F, String] =
310313
Stream.eval(getResolved(path)).flatMap(p =>
311-
files.walk(p, 1).map(_.toString)
314+
files.walk(p, 1).map(_.toString).drop(1) // Exclude Myself
312315
)
313316

314317
}

examples/src/main/scala/Main.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ object Main extends IOApp {
2121
// got <- p.shellStrict("find", List("-wholename", "*.scala"))
2222
// got <- which("java")
2323
// got <- hostname
24-
got <- ls("").compile.toList
24+
_ <- cd("..")
25+
got <- ls.compile.toList
2526
_ <- echo(got.toString)
2627
// _ <- p.shellStrict("which", "java":: Nil).flatMap(a => echo(a.toString))
2728
} yield ExitCode.Success

0 commit comments

Comments
 (0)