diff options
| -rw-r--r-- | describe/describe.go | 11 | ||||
| -rw-r--r-- | runner/shell/hydrated.go | 2 | ||||
| -rw-r--r-- | runner/shell/shell.go | 2 |
3 files changed, 12 insertions, 3 deletions
diff --git a/describe/describe.go b/describe/describe.go index 7f2c888..443c0e6 100644 --- a/describe/describe.go +++ b/describe/describe.go @@ -3,6 +3,7 @@ package describe import ( "bufio" "os" + "pik/model" "strings" ) @@ -11,9 +12,16 @@ var DescriptionPrefixes = []string{ "//", } -func Describe(file string) (string, error) { +var descriptions = make(map[model.Target]*string) + +func Describe(key model.Target, file string) (string, error) { + if d := descriptions[key]; d != nil { + return *d, nil + } fd, err := os.Open(file) if err != nil { + msg := err.Error() + descriptions[key] = &msg return "", err } defer fd.Close() @@ -33,5 +41,6 @@ func Describe(file string) (string, error) { text = strings.TrimPrefix(text, c) text = strings.TrimSpace(text) } + descriptions[key] = &text return text, nil } diff --git a/runner/shell/hydrated.go b/runner/shell/hydrated.go index 7ead74c..1ecce51 100644 --- a/runner/shell/hydrated.go +++ b/runner/shell/hydrated.go @@ -17,7 +17,7 @@ func (h *Hydrated) Icon() string { } func (h *Hydrated) Description() string { - desc, err := describe.Describe(h.BaseTarget.Script) + desc, err := describe.Describe(h.BaseTarget, h.BaseTarget.Script) if err != nil { spool.Warn("%v\n", err) return "" diff --git a/runner/shell/shell.go b/runner/shell/shell.go index c9d7134..a184182 100644 --- a/runner/shell/shell.go +++ b/runner/shell/shell.go @@ -97,7 +97,7 @@ func (s *shell) CreateTarget(fs fs.FS, src string, file string, _ fs.DirEntry) ( MyTags: model.TagsFromFilename(filename), }, Shell: shell, - Script: filepath.Join(src, file), + Script: file, SubValue: sub, }, nil } |
