Skip to content

Commit

Permalink
Allow loading ~/.yalrc in the REPL
Browse files Browse the repository at this point in the history
This allows a cute startup file:

```
;; Get our hostname
(set! hostname (fn* () (trim (slurp "/etc/hostname"))))

(set! trim (fn* (str)
   "Trim all leading/trailing whitespace from the given string."
   (let* (res (match "^[ \t\r\n]*([^ \t\r\n]+)[ \t\r\n]*" str))
     (if (list? res)
       (car (cdr res))
       str))))

;; Show ourselves
(print "This is ~/.yalrc on %s - %s %s" (hostname) (os) (arch) )
```
  • Loading branch information
skx committed Oct 29, 2022
1 parent 137dcfe commit 5347f1c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"math/rand"
"os"
"path"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -257,10 +258,34 @@ func main() {
fmt.Printf("YAL version %s\n", version)
reader := bufio.NewReader(os.Stdin)

//
// Get the home directory, and load ~/.yalrc if present
//
home := os.Getenv("HOME")
if home != "" {

// Build the path
file := path.Join(home, ".yalrc")

// Read the content
content, err := os.ReadFile(file)
if err == nil {

// Execute the contents
out := LISP.Execute(ENV, string(content))
if _, ok := out.(primitive.Error); ok {
fmt.Printf("Error executing ~/.yalrc %v\n", out)
}
}
}

src := ""
for {
if src == "" {
fmt.Printf("\n> ")
} else {
fmt.Printf(" ")

}

line, _ := reader.ReadString('\n')
Expand Down

0 comments on commit 5347f1c

Please sign in to comment.