mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-09-19 21:17:31 -07:00
parent
90f3789057
commit
b492903f08
|
@ -2,7 +2,10 @@ package template
|
|||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/log"
|
||||
)
|
||||
|
||||
func glob(pattern string) (bool, error) {
|
||||
|
@ -17,3 +20,13 @@ func readFile(path string) string {
|
|||
content, _ := os.ReadFile(path)
|
||||
return string(content)
|
||||
}
|
||||
|
||||
func stat(path string) string {
|
||||
fullPath, err := exec.LookPath(path)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return fullPath
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package template
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
|
@ -10,7 +11,7 @@ func funcMap() template.FuncMap {
|
|||
funcMap := map[string]any{
|
||||
"secondsRound": secondsRound,
|
||||
"url": url,
|
||||
"path": path,
|
||||
"path": filePath,
|
||||
"glob": glob,
|
||||
"matchP": matchP,
|
||||
"replaceP": replaceP,
|
||||
|
@ -20,11 +21,16 @@ func funcMap() template.FuncMap {
|
|||
"hresult": hresult,
|
||||
"trunc": trunc,
|
||||
"readFile": readFile,
|
||||
"stat": stat,
|
||||
"dir": filepath.Dir,
|
||||
"base": filepath.Base,
|
||||
}
|
||||
|
||||
for key, fun := range sprig.TxtFuncMap() {
|
||||
if _, ok := funcMap[key]; !ok {
|
||||
funcMap[key] = fun
|
||||
}
|
||||
}
|
||||
|
||||
return template.FuncMap(funcMap)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func url(text, url string) (string, error) {
|
|||
return fmt.Sprintf("<LINK>%s<TEXT>%s</TEXT></LINK>", url, text), nil
|
||||
}
|
||||
|
||||
func path(text, path string) (string, error) {
|
||||
func filePath(text, path string) (string, error) {
|
||||
unsupported := []string{elvish, xonsh}
|
||||
if slices.Contains(unsupported, shell) {
|
||||
return text, nil
|
||||
|
|
Loading…
Reference in a new issue