summaryrefslogtreecommitdiff
path: root/shell.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2019-06-14 19:05:17 -0700
committerJeff Carr <[email protected]>2019-06-14 19:05:17 -0700
commit8d1122b534a7d518b2df8baecd580ff337fa8f21 (patch)
treec5245c8ccbc52b1f34fbac775e386b471cffc345 /shell.go
parent2dc091f5bc0cb901a19b751e2c0641e5b2a26e75 (diff)
add shell.Cat()
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'shell.go')
-rw-r--r--shell.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/shell.go b/shell.go
index fbbbcc1..51f6378 100644
--- a/shell.go
+++ b/shell.go
@@ -8,7 +8,7 @@ import "os/exec"
import "bufio"
import "bytes"
import "io"
-// import "io/ioutil"
+import "io/ioutil"
import "github.com/davecgh/go-spew/spew"
import "github.com/svent/go-nbreader"
@@ -268,20 +268,30 @@ func Exec(cmdline string) {
os.Exit(0)
}
-// return true if the filename exists
+// return true if the filename exists (cross-platform)
func Exists(filename string) bool {
- _, err := os.Stat(filename)
+ _, err := os.Stat(Path(filename))
if os.IsNotExist(err) {
return false
}
return true
}
-// return true if the filename exists
+// return true if the filename exists (cross-platform)
func Dir(dirname string) bool {
- info, err := os.Stat(dirname)
+ info, err := os.Stat(Path(dirname))
if os.IsNotExist(err) {
return false
}
return info.IsDir()
}
+
+// Cat a file into a string
+func Cat(filename string) string {
+ buffer, err := ioutil.ReadFile(Path(filename))
+ // log.Println("buffer =", string(buffer))
+ if err != nil {
+ return ""
+ }
+ return Chomp(buffer)
+}