From 77f9c3fdd0b9e75b7c073a1b43826d9c6e9d6996 Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Mon, 8 Aug 2022 19:17:59 -0400 Subject: [PATCH 1/5] fix(Sheets): cheatsheets in hidden directories (#690) Fix an issue whereby cheatsheets that were contained within hidden directories were prevented from being loaded. --- internal/sheets/load.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/sheets/load.go b/internal/sheets/load.go index 0d88c24..4442b3e 100644 --- a/internal/sheets/load.go +++ b/internal/sheets/load.go @@ -49,17 +49,18 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) { string(os.PathSeparator), ) - // ignore hidden files and directories. Otherwise, we'll likely load - // .git/* and .DS_Store. + // Don't walk the `.git` directory. Doing so creates + // hundreds/thousands of needless syscalls and could + // potentially harm performance on machines with slow disks. // - // NB: this is still somewhat brittle in that it will miss files - // contained within hidden directories in the middle of a path, though - // that should not realistically occur. - if strings.HasPrefix(title, ".") || strings.HasPrefix(info.Name(), ".") { - // Do not walk hidden directories. This is important, - // because it's common for cheatsheets to be stored in - // version-control, and a `.git` directory can easily - // contain thousands of files. + // NB: We _do_ want to walk hidden directories, however, so we + // should not constrain this further (perhaps to include all + // hidden directories). In the wild, many users appear to store + // cheatsheets in a `.config` directory (seemingly a default + // behavior of `brew`), and `cheat` explicitly supports a + // local `.cheat` directory. Constraining further here will + // break those use-cases - and has done so in the past! + if strings.Contains(path, ".git") { return fs.SkipDir } From 0c47f44ff9099244502a211b162b4029796051da Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Mon, 8 Aug 2022 19:45:32 -0400 Subject: [PATCH 2/5] fix: no colorization on default install (#687) Fix an issue whereby a default installation (as created by the installer) would (seemingly) fail to output colorized text, even when the `-c` flag was passed. The root cause of the problem was that the installer did not set a default `style` for `chroma`, which in turn defaulted to using the `bw` (black-and-white) style. Thus, colorization actually *was* being applied with `-c` - it was simply black and white! --- cmd/cheat/str_config.go | 5 ++--- configs/conf.yml | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cmd/cheat/str_config.go b/cmd/cheat/str_config.go index 02beccb..72a7649 100644 --- a/cmd/cheat/str_config.go +++ b/cmd/cheat/str_config.go @@ -17,11 +17,11 @@ colorize: false # Which 'chroma' colorscheme should be applied to the output? # Options are available here: # https://github.com/alecthomas/chroma/tree/master/styles -# style: monokai +style: monokai # Which 'chroma' "formatter" should be applied? # One of: "terminal", "terminal256", "terminal16m" -formatter: terminal +formatter: terminal256 # Through which pager should output be piped? # 'less -FRX' is recommended on Unix systems @@ -41,7 +41,6 @@ pager: PAGER_PATH # commands. So, if you want to view the 'tar' cheatsheet that is tagged as # 'community' rather than your own, you can use: cheat tar -t community cheatpaths: - # Paths that come earlier are considered to be the most "global", and will # thus be overridden by more local cheatsheets. That being the case, you # should probably list community cheatsheets first. diff --git a/configs/conf.yml b/configs/conf.yml index c18797d..4fb1d77 100644 --- a/configs/conf.yml +++ b/configs/conf.yml @@ -8,11 +8,11 @@ colorize: false # Which 'chroma' colorscheme should be applied to the output? # Options are available here: # https://github.com/alecthomas/chroma/tree/master/styles -# style: monokai +style: monokai # Which 'chroma' "formatter" should be applied? # One of: "terminal", "terminal256", "terminal16m" -formatter: terminal +formatter: terminal256 # Through which pager should output be piped? # 'less -FRX' is recommended on Unix systems @@ -32,7 +32,6 @@ pager: PAGER_PATH # commands. So, if you want to view the 'tar' cheatsheet that is tagged as # 'community' rather than your own, you can use: cheat tar -t community cheatpaths: - # Paths that come earlier are considered to be the most "global", and will # thus be overridden by more local cheatsheets. That being the case, you # should probably list community cheatsheets first. From 6421953183f067d347bd279c9e16ce7ddff8f658 Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Mon, 8 Aug 2022 20:14:27 -0400 Subject: [PATCH 3/5] feat(installer): set default `editor` Attempt to set and locate a default editor when running the installer. --- cmd/cheat/str_config.go | 2 +- configs/conf.yml | 2 +- internal/config/editor.go | 17 ++++++++++++++--- internal/installer/run.go | 9 ++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cmd/cheat/str_config.go b/cmd/cheat/str_config.go index 72a7649..0eec47f 100644 --- a/cmd/cheat/str_config.go +++ b/cmd/cheat/str_config.go @@ -9,7 +9,7 @@ import ( func configs() string { return strings.TrimSpace(`--- # The editor to use with 'cheat -e '. Defaults to $EDITOR or $VISUAL. -# editor: vim +editor: EDITOR_PATH # Should 'cheat' always colorize output? colorize: false diff --git a/configs/conf.yml b/configs/conf.yml index 4fb1d77..25bfbc6 100644 --- a/configs/conf.yml +++ b/configs/conf.yml @@ -1,6 +1,6 @@ --- # The editor to use with 'cheat -e '. Defaults to $EDITOR or $VISUAL. -# editor: vim +editor: EDITOR_PATH # Should 'cheat' always colorize output? colorize: false diff --git a/internal/config/editor.go b/internal/config/editor.go index 73087cc..88fdfc9 100644 --- a/internal/config/editor.go +++ b/internal/config/editor.go @@ -15,11 +15,22 @@ func Editor() (string, error) { return "notepad", nil } - // look for `nano` on the `PATH` + // look for `nano` and `vim` on the `PATH` + def, _ := exec.LookPath("editor") // default `editor` wrapper nano, _ := exec.LookPath("nano") + vim, _ := exec.LookPath("vim") - // search for `$VISUAL`, `$EDITOR`, and then `nano`, in that order - for _, editor := range []string{os.Getenv("VISUAL"), os.Getenv("EDITOR"), nano} { + // set editor priority + editors := []string{ + os.Getenv("VISUAL"), + os.Getenv("EDITOR"), + def, + nano, + vim, + } + + // return the first editor that was found per the priority above + for _, editor := range editors { if editor != "" { return editor, nil } diff --git a/internal/installer/run.go b/internal/installer/run.go index 7fc22ad..302c653 100644 --- a/internal/installer/run.go +++ b/internal/installer/run.go @@ -20,11 +20,18 @@ func Run(configs string, confpath string) error { community := filepath.Join(confdir, "cheatsheets", "community") personal := filepath.Join(confdir, "cheatsheets", "personal") - // template the above paths into the default configs + // set default cheatpaths configs = strings.Replace(configs, "COMMUNITY_PATH", community, -1) configs = strings.Replace(configs, "PERSONAL_PATH", personal, -1) + + // locate and set a default pager configs = strings.Replace(configs, "PAGER_PATH", config.Pager(), -1) + // locate and set a default editor + if editor, err := config.Editor(); err == nil { + configs = strings.Replace(configs, "EDITOR_PATH", editor, -1) + } + // prompt the user to download the community cheatsheets yes, err := Prompt( "Would you like to download the community cheatsheets? [Y/n]", From 2a6586b41b2f366f4864167ac0655f900540a732 Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Mon, 8 Aug 2022 20:37:27 -0400 Subject: [PATCH 4/5] fix(installer): always use `more` pager on Windows --- internal/config/pager.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/config/pager.go b/internal/config/pager.go index 1b26638..850116b 100644 --- a/internal/config/pager.go +++ b/internal/config/pager.go @@ -3,11 +3,17 @@ package config import ( "os" "os/exec" + "runtime" ) // Pager attempts to locate a pager that's appropriate for the environment. func Pager() string { + // default to `more` on Windows + if runtime.GOOS == "windows" { + return "more" + } + // if $PAGER is set, return the corresponding pager if os.Getenv("PAGER") != "" { return os.Getenv("PAGER") From 3c1e24a0e89f271fc9f617f99eec0e9d4178636e Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Mon, 8 Aug 2022 20:21:27 -0400 Subject: [PATCH 5/5] chore: bump version to `4.3.1` --- INSTALLING.md | 4 ++-- cmd/cheat/main.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALLING.md b/INSTALLING.md index b42c3d2..8300a21 100644 --- a/INSTALLING.md +++ b/INSTALLING.md @@ -9,13 +9,13 @@ On Unix-like systems, you may simply paste the following snippet into your termi ```sh cd /tmp \ - && wget https://github.com/cheat/cheat/releases/download/4.3.0/cheat-linux-amd64.gz \ + && wget https://github.com/cheat/cheat/releases/download/4.3.1/cheat-linux-amd64.gz \ && gunzip cheat-linux-amd64.gz \ && chmod +x cheat-linux-amd64 \ && sudo mv cheat-linux-amd64 /usr/local/bin/cheat ``` -You may need to need to change the version number (`4.3.0`) and the archive +You may need to need to change the version number (`4.3.1`) and the archive (`cheat-linux-amd64.gz`) depending on your platform. See the [releases page][releases] for a list of supported platforms. diff --git a/cmd/cheat/main.go b/cmd/cheat/main.go index 292c605..37c339f 100755 --- a/cmd/cheat/main.go +++ b/cmd/cheat/main.go @@ -16,7 +16,7 @@ import ( "github.com/cheat/cheat/internal/installer" ) -const version = "4.3.0" +const version = "4.3.1" func main() {