diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | describe/describe.go | 33 | ||||
| -rw-r--r-- | runner/base.go | 2 | ||||
| -rw-r--r-- | runner/python/projtarget.go | 3 | ||||
| -rw-r--r-- | runner/shell/hydrated.go | 9 |
5 files changed, 44 insertions, 5 deletions
@@ -32,6 +32,7 @@ running `pik` in a supported repository will index its own file-based task syste * target tags in filenames which trigger flag behaviours * aliases to sources through the `.alias` file * tui for viewing and running targets + * descriptions for targets based on the first- or second line comment * y/n confirmation with yes as default * will be used if we have an uncertain target guess * `--yes` to automatically confirm y/n prompts @@ -52,7 +53,6 @@ attach to these features. * this will also enable arbitrary shells like node by way of the shebang * indexers for other target types such as `make` and `npm` * expand tui: - * adding descriptions to targets based on the first comment in a target * support for categories and ordering of targets through the `.order` file * search * more hotkeys (filter jumping, toggle all, etc.) diff --git a/describe/describe.go b/describe/describe.go new file mode 100644 index 0000000..fe168ec --- /dev/null +++ b/describe/describe.go @@ -0,0 +1,33 @@ +package describe + +import ( + "bufio" + "os" + "strings" +) + +var DescriptionPrefixes = []string{ + "#", + "//", +} + +func Describe(file string) (string, error) { + fd, err := os.Open(file) + if err != nil { + return "", err + } + defer fd.Close() + scanner := bufio.NewScanner(fd) + scanner.Split(bufio.ScanLines) + scanner.Scan() + text := scanner.Text() + if strings.HasPrefix(text, "#!") { + scanner.Scan() + text = scanner.Text() + } + text = strings.TrimSpace(text) + if !strings.HasPrefix(text, "#") { + return "", nil + } + return text, nil +} diff --git a/runner/base.go b/runner/base.go index 7a6ce81..28ea4d5 100644 --- a/runner/base.go +++ b/runner/base.go @@ -70,7 +70,7 @@ func (b BaseHydration[T]) Icon() string { } func (b BaseHydration[T]) Description() string { - return "//TODO" + return "" } func (b BaseHydration[T]) Target() model.Target { diff --git a/runner/python/projtarget.go b/runner/python/projtarget.go index 1604948..c7422b4 100644 --- a/runner/python/projtarget.go +++ b/runner/python/projtarget.go @@ -21,8 +21,7 @@ func (h *HydratedProjTarget) Icon() string { } func (h *HydratedProjTarget) Description() string { - //TODO implement me - return "//TODO" + return h.BaseTarget.Cmd } func (p *ProjTarget) Create(s *model.Source) *exec.Cmd { diff --git a/runner/shell/hydrated.go b/runner/shell/hydrated.go index 5a86d5a..77fc45c 100644 --- a/runner/shell/hydrated.go +++ b/runner/shell/hydrated.go @@ -1,7 +1,9 @@ package shell import ( + "pik/describe" "pik/runner" + "pik/spool" ) type HydratedShellTarget struct { @@ -13,5 +15,10 @@ func (h *HydratedShellTarget) Icon() string { } func (h *HydratedShellTarget) Description() string { - return "//TODO" + desc, err := describe.Describe(h.BaseTarget.Script) + if err != nil { + spool.Warn("%v\n", err) + return "" + } + return desc } |
