From 11eeac017377fcadf559a8d10ebf1e594c6dcd55 Mon Sep 17 00:00:00 2001 From: "Stanislav (Stas) Katkov" Date: Mon, 30 Sep 2024 01:56:06 +0200 Subject: [PATCH 1/3] Make --all configurable globally --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 8a5ca903..6ba15aa7 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ var ( pager bool style string width uint + all bool showAllFiles bool showLineNumbers bool preserveNewLines bool @@ -146,6 +147,7 @@ func validateOptions(cmd *cobra.Command) error { width = viper.GetUint("width") mouse = viper.GetBool("mouse") pager = viper.GetBool("pager") + all = viper.GetBool("all") preserveNewLines = viper.GetBool("preserveNewLines") // validate the glamour style @@ -315,7 +317,11 @@ func runTUI(workingDirectory string) error { cfg.WorkingDirectory = workingDirectory - cfg.ShowAllFiles = showAllFiles + if showAllFiles { + cfg.ShowAllFiles = showAllFiles + } else { + cfg.ShowAllFiles = all + } cfg.ShowLineNumbers = showLineNumbers cfg.GlamourMaxWidth = width cfg.GlamourStyle = style From f79fe6eef544388f6c79e7724e70159c2acabb65 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Mon, 30 Sep 2024 08:13:49 -0700 Subject: [PATCH 2/3] docs: add all option to docs and default config --- README.md | 2 ++ config_cmd.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 225ed8c7..1e811677 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,8 @@ mouse: true pager: true # at which column should we word wrap? width: 80 +# show all files, including hidden and ignored. +all: true ``` ## Feedback diff --git a/config_cmd.go b/config_cmd.go index d3defcc7..e7376965 100644 --- a/config_cmd.go +++ b/config_cmd.go @@ -21,6 +21,8 @@ mouse: false pager: false # word-wrap at width width: 80 +# show all files, including hidden and ignored. +all: true ` var configCmd = &cobra.Command{ From ed155785e92b461fa5b1180ba5496b159673fdae Mon Sep 17 00:00:00 2001 From: bashbunni Date: Mon, 30 Sep 2024 09:53:30 -0700 Subject: [PATCH 3/3] refactor: tidy fields, set showAllFiles to true if unset --- main.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 6ba15aa7..fb3ce57e 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,6 @@ var ( pager bool style string width uint - all bool showAllFiles bool showLineNumbers bool preserveNewLines bool @@ -147,7 +146,7 @@ func validateOptions(cmd *cobra.Command) error { width = viper.GetUint("width") mouse = viper.GetBool("mouse") pager = viper.GetBool("pager") - all = viper.GetBool("all") + showAllFiles = viper.GetBool("all") preserveNewLines = viper.GetBool("preserveNewLines") // validate the glamour style @@ -317,11 +316,7 @@ func runTUI(workingDirectory string) error { cfg.WorkingDirectory = workingDirectory - if showAllFiles { - cfg.ShowAllFiles = showAllFiles - } else { - cfg.ShowAllFiles = all - } + cfg.ShowAllFiles = showAllFiles cfg.ShowLineNumbers = showLineNumbers cfg.GlamourMaxWidth = width cfg.GlamourStyle = style @@ -379,10 +374,11 @@ func init() { _ = viper.BindPFlag("mouse", rootCmd.Flags().Lookup("mouse")) _ = viper.BindPFlag("preserveNewLines", rootCmd.Flags().Lookup("preserve-new-lines")) _ = viper.BindPFlag("showLineNumbers", rootCmd.Flags().Lookup("line-numbers")) - _ = viper.BindPFlag("showAllFiles", rootCmd.Flags().Lookup("all")) + _ = viper.BindPFlag("all", rootCmd.Flags().Lookup("all")) viper.SetDefault("style", styles.AutoStyle) viper.SetDefault("width", 0) + viper.SetDefault("all", true) rootCmd.AddCommand(configCmd, manCmd) }