mirror of
https://github.com/charmbracelet/glow
synced 2024-09-30 05:05:24 +00:00
Hide files and dirs starting with a dot by default
This commit is contained in:
parent
05a77ff655
commit
5b20e3edae
12
main.go
12
main.go
|
@ -26,10 +26,11 @@ var (
|
|||
Version = ""
|
||||
CommitSHA = ""
|
||||
|
||||
readmeNames = []string{"README.md", "README"}
|
||||
pager bool
|
||||
style string
|
||||
width uint
|
||||
readmeNames = []string{"README.md", "README"}
|
||||
pager bool
|
||||
style string
|
||||
width uint
|
||||
showAllFiles bool
|
||||
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "glow SOURCE",
|
||||
|
@ -186,6 +187,8 @@ func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
|
|||
defer f.Close()
|
||||
}
|
||||
|
||||
cfg.ShowAllFiles = showAllFiles
|
||||
|
||||
// Run Bubble Tea program
|
||||
p := ui.NewProgram(style, cfg)
|
||||
p.EnterAltScreen()
|
||||
|
@ -291,6 +294,7 @@ func init() {
|
|||
rootCmd.Flags().BoolVarP(&pager, "pager", "p", false, "display with pager")
|
||||
rootCmd.Flags().StringVarP(&style, "style", "s", "auto", "style name or JSON path")
|
||||
rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width")
|
||||
rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show files and directories starting with a dot (TUI-mode only)")
|
||||
|
||||
// Stash
|
||||
stashCmd.PersistentFlags().StringVarP(&memo, "memo", "m", "", "memo/note for stashing")
|
||||
|
|
35
ui/ui.go
35
ui/ui.go
|
@ -32,6 +32,8 @@ var (
|
|||
|
||||
// Config contains configuration specified to the TUI.
|
||||
type Config struct {
|
||||
ShowAllFiles bool
|
||||
|
||||
// For debugging the UI
|
||||
Logfile string `env:"GLOW_UI_LOGFILE"`
|
||||
HighPerformancePager bool `env:"GLOW_UI_HIGH_PERFORMANCE_PAGER" default:"true"`
|
||||
|
@ -63,6 +65,7 @@ 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 }
|
||||
|
@ -274,6 +277,10 @@ 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 {
|
||||
|
@ -419,14 +426,22 @@ func findLocalFiles() tea.Msg {
|
|||
|
||||
func findNextLocalFile(m model) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
pathStr, ok := <-m.localFileFinder
|
||||
res, ok := <-m.localFileFinder
|
||||
|
||||
if !m.cfg.ShowAllFiles && isDotFileOrDir(m.cwd, res.Path) {
|
||||
if debug {
|
||||
log.Println("ignoring file:", res.Path)
|
||||
}
|
||||
return skipLocalFileMsg(res)
|
||||
}
|
||||
|
||||
if ok {
|
||||
// Okay now find the next one
|
||||
return foundLocalFileMsg(pathStr)
|
||||
return foundLocalFileMsg(res)
|
||||
}
|
||||
// We're done
|
||||
if debug {
|
||||
log.Println("Local file search finished")
|
||||
log.Println("local file search finished")
|
||||
}
|
||||
return localFileSearchFinished{}
|
||||
}
|
||||
|
@ -601,6 +616,20 @@ func localFileToMarkdown(cwd string, res gitcha.SearchResult) *markdown {
|
|||
return md
|
||||
}
|
||||
|
||||
// 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.Replace(path, cwd, "", 1)
|
||||
for _, v := range strings.Split(p, string(os.PathSeparator)) {
|
||||
if len(v) > 0 && v[0] == '.' {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Lightweight version of reflow's indent function.
|
||||
func indent(s string, n int) string {
|
||||
if n <= 0 || s == "" {
|
||||
|
|
Loading…
Reference in a new issue