mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-23 16:44:17 +02:00
Move ignore stuff to gitcha (and temporarily use the meowgorithm fork)
This commit is contained in:
parent
f8fa5a04dc
commit
a3a05fde9c
6 changed files with 37 additions and 83 deletions
2
go.mod
2
go.mod
|
|
@ -21,3 +21,5 @@ require (
|
|||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc // indirect
|
||||
golang.org/x/sys v0.0.0-20200821140526-fda516888d29
|
||||
)
|
||||
|
||||
replace github.com/muesli/gitcha => github.com/meowgorithm/gitcha v0.1.2-0.20200907220241-87b69df49486
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -98,6 +98,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
|
|||
github.com/meowgorithm/babyenv v1.2.1/go.mod h1:lwNX+J6AGBFqNrMZ2PTLkM6SO+W4X8DOg9zBDO4j3Ig=
|
||||
github.com/meowgorithm/babyenv v1.3.0 h1:klb7ugoZt0/Xlqkd5kLxM7eLZX8waiwxHZWW5nfEZ0Q=
|
||||
github.com/meowgorithm/babyenv v1.3.0/go.mod h1:lwNX+J6AGBFqNrMZ2PTLkM6SO+W4X8DOg9zBDO4j3Ig=
|
||||
github.com/meowgorithm/gitcha v0.1.2-0.20200907220241-87b69df49486 h1:Q59vhaeBGofDFPzw9dc05t/xF5w7qlgpXLsUi3Bt5kw=
|
||||
github.com/meowgorithm/gitcha v0.1.2-0.20200907220241-87b69df49486/go.mod h1:Ri8m9TZS4+ORG4JVmVKUQcWZuxDvUW3UKxMdQfzG2zI=
|
||||
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
||||
github.com/microcosm-cc/bluemonday v1.0.4 h1:p0L+CTpo/PLFdkoPcJemLXG+fpMD7pYOoDEq1axMbGg=
|
||||
github.com/microcosm-cc/bluemonday v1.0.4/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
|
||||
|
|
@ -106,8 +108,6 @@ github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a/go.mod h1:v8eSC2S
|
|||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/muesli/gitcha v0.1.1 h1:TzTFwvwTg0oq7DXFyVXFa6usbG9v6MyBT7W/+ic/9xg=
|
||||
github.com/muesli/gitcha v0.1.1/go.mod h1:Ri8m9TZS4+ORG4JVmVKUQcWZuxDvUW3UKxMdQfzG2zI=
|
||||
github.com/muesli/go-app-paths v0.2.1 h1:Qi+2igkDX2aPqyRddp7P0sMQIBwBqhkfQfNcjdGjL6Y=
|
||||
github.com/muesli/go-app-paths v0.2.1/go.mod h1:SxS3Umca63pcFcLtbjVb+J0oD7cl4ixQWoBKhGEtEho=
|
||||
github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=
|
||||
|
|
|
|||
39
ui/ignore.go
39
ui/ignore.go
|
|
@ -1,39 +0,0 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Returns whether or not the given path contains a file or directory starting
|
||||
// with a dot. This is relative to the current working directory, so if you're
|
||||
// in a dot directory and browsing files beneath this function won't return
|
||||
// true every time.
|
||||
func isDotFileOrDir(cwd, path string) bool {
|
||||
p := strings.TrimPrefix(path, cwd)
|
||||
for _, v := range strings.Split(p, string(os.PathSeparator)) {
|
||||
if len(v) > 0 && v[0] == '.' {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Returns whether or not a path is a child of a given path. For example:
|
||||
//
|
||||
// parent := "/usr/local/bin"
|
||||
// child := "/usr/local/bin/glow"
|
||||
// pathIsChild(parent, child) // true
|
||||
//
|
||||
func pathIsChild(parent, child string) bool {
|
||||
if len(parent) == 0 || len(child) == 0 {
|
||||
return false
|
||||
}
|
||||
if len(parent) > len(child) {
|
||||
return false
|
||||
}
|
||||
if strings.Compare(parent, child[:len(parent)]) == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
@ -4,15 +4,11 @@ package ui
|
|||
|
||||
import "os"
|
||||
|
||||
func ignorePath(m model, p string) bool {
|
||||
if isDotFileOrDir(m.cwd, p) {
|
||||
return true
|
||||
func ignorePatterns(m model) []string {
|
||||
return []string{
|
||||
m.cfg.HomeDir + string(os.PathSeparator) + "Library",
|
||||
m.cfg.Gopath,
|
||||
"node_modules",
|
||||
".*",
|
||||
}
|
||||
if pathIsChild(m.cfg.Gopath, p) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Look for ~/Library on macOS
|
||||
macOSLibraryPath := m.cfg.HomeDir + string(os.PathSeparator) + "Library"
|
||||
return pathIsChild(macOSLibraryPath, p)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
package ui
|
||||
|
||||
// Whether or not we should ignore the given path
|
||||
func ignorePath(m model, p string) bool {
|
||||
if isDotFileOrDir(m.cwd, p) {
|
||||
return true
|
||||
func ignorePatterns(m model) []string {
|
||||
return []string{
|
||||
m.cfg.Gopath,
|
||||
"node_modules"
|
||||
".*",
|
||||
}
|
||||
return pathIsChild(m.cfg.Gopath, p)
|
||||
}
|
||||
|
|
|
|||
49
ui/ui.go
49
ui/ui.go
|
|
@ -67,7 +67,6 @@ type initLocalFileSearchMsg struct {
|
|||
ch chan gitcha.SearchResult
|
||||
}
|
||||
type foundLocalFileMsg gitcha.SearchResult
|
||||
type skipLocalFileMsg gitcha.SearchResult
|
||||
type localFileSearchFinished struct{}
|
||||
type gotStashMsg []*charm.Markdown
|
||||
type stashLoadErrMsg struct{ err error }
|
||||
|
|
@ -172,7 +171,7 @@ func initialize(cfg Config, style string) func() (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
return m, tea.Batch(
|
||||
findLocalFiles,
|
||||
findLocalFiles(m),
|
||||
newCharmClient,
|
||||
spinner.Tick(m.stash.spinner),
|
||||
)
|
||||
|
|
@ -279,10 +278,6 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
m.stash.addMarkdowns(newMd)
|
||||
cmds = append(cmds, findNextLocalFile(m))
|
||||
|
||||
// We found a file that we want to ignore
|
||||
case skipLocalFileMsg:
|
||||
cmds = append(cmds, findNextLocalFile(m))
|
||||
|
||||
case sshAuthErrMsg:
|
||||
// If we haven't run the keygen yet, do that
|
||||
if m.keygenState != keygenFinished {
|
||||
|
|
@ -406,37 +401,37 @@ func errorView(err error, fatal bool) string {
|
|||
|
||||
// COMMANDS
|
||||
|
||||
func findLocalFiles() tea.Msg {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
if debug {
|
||||
log.Println("error finding local files:", err)
|
||||
func findLocalFiles(m model) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
if debug {
|
||||
log.Println("error finding local files:", err)
|
||||
}
|
||||
return errMsg{err}
|
||||
}
|
||||
return errMsg{err}
|
||||
}
|
||||
|
||||
ch, err := gitcha.FindFiles(cwd, []string{"*.md"})
|
||||
if err != nil {
|
||||
if debug {
|
||||
log.Println("error finding local files:", err)
|
||||
var ignore []string
|
||||
if !m.cfg.ShowAllFiles {
|
||||
ignore = ignorePatterns(m)
|
||||
}
|
||||
return errMsg{err}
|
||||
}
|
||||
|
||||
return initLocalFileSearchMsg{ch: ch, cwd: cwd}
|
||||
ch, err := gitcha.FindFilesExcept(cwd, []string{"*.md"}, ignore)
|
||||
if err != nil {
|
||||
if debug {
|
||||
log.Println("error finding local files:", err)
|
||||
}
|
||||
return errMsg{err}
|
||||
}
|
||||
|
||||
return initLocalFileSearchMsg{ch: ch, cwd: cwd}
|
||||
}
|
||||
}
|
||||
|
||||
func findNextLocalFile(m model) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
res, ok := <-m.localFileFinder
|
||||
|
||||
if !m.cfg.ShowAllFiles && ignorePath(m, res.Path) {
|
||||
if debug {
|
||||
log.Println("ignoring file:", res.Path)
|
||||
}
|
||||
return skipLocalFileMsg(res)
|
||||
}
|
||||
|
||||
if ok {
|
||||
// Okay now find the next one
|
||||
return foundLocalFileMsg(res)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue