mirror of
https://github.com/cheat/cheat.git
synced 2024-11-22 05:51:35 +01:00
commit
0b80a608c3
@ -9,13 +9,13 @@ On Unix-like systems, you may simply paste the following snippet into your termi
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd /tmp \
|
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 \
|
&& gunzip cheat-linux-amd64.gz \
|
||||||
&& chmod +x cheat-linux-amd64 \
|
&& chmod +x cheat-linux-amd64 \
|
||||||
&& sudo mv cheat-linux-amd64 /usr/local/bin/cheat
|
&& 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.
|
(`cheat-linux-amd64.gz`) depending on your platform.
|
||||||
|
|
||||||
See the [releases page][releases] for a list of supported platforms.
|
See the [releases page][releases] for a list of supported platforms.
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/cheat/cheat/internal/installer"
|
"github.com/cheat/cheat/internal/installer"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "4.3.0"
|
const version = "4.3.1"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
func configs() string {
|
func configs() string {
|
||||||
return strings.TrimSpace(`---
|
return strings.TrimSpace(`---
|
||||||
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
||||||
# editor: vim
|
editor: EDITOR_PATH
|
||||||
|
|
||||||
# Should 'cheat' always colorize output?
|
# Should 'cheat' always colorize output?
|
||||||
colorize: false
|
colorize: false
|
||||||
@ -17,11 +17,11 @@ colorize: false
|
|||||||
# Which 'chroma' colorscheme should be applied to the output?
|
# Which 'chroma' colorscheme should be applied to the output?
|
||||||
# Options are available here:
|
# Options are available here:
|
||||||
# https://github.com/alecthomas/chroma/tree/master/styles
|
# https://github.com/alecthomas/chroma/tree/master/styles
|
||||||
# style: monokai
|
style: monokai
|
||||||
|
|
||||||
# Which 'chroma' "formatter" should be applied?
|
# Which 'chroma' "formatter" should be applied?
|
||||||
# One of: "terminal", "terminal256", "terminal16m"
|
# One of: "terminal", "terminal256", "terminal16m"
|
||||||
formatter: terminal
|
formatter: terminal256
|
||||||
|
|
||||||
# Through which pager should output be piped?
|
# Through which pager should output be piped?
|
||||||
# 'less -FRX' is recommended on Unix systems
|
# '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
|
# 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
|
# 'community' rather than your own, you can use: cheat tar -t community
|
||||||
cheatpaths:
|
cheatpaths:
|
||||||
|
|
||||||
# Paths that come earlier are considered to be the most "global", and will
|
# 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
|
# thus be overridden by more local cheatsheets. That being the case, you
|
||||||
# should probably list community cheatsheets first.
|
# should probably list community cheatsheets first.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
||||||
# editor: vim
|
editor: EDITOR_PATH
|
||||||
|
|
||||||
# Should 'cheat' always colorize output?
|
# Should 'cheat' always colorize output?
|
||||||
colorize: false
|
colorize: false
|
||||||
@ -8,11 +8,11 @@ colorize: false
|
|||||||
# Which 'chroma' colorscheme should be applied to the output?
|
# Which 'chroma' colorscheme should be applied to the output?
|
||||||
# Options are available here:
|
# Options are available here:
|
||||||
# https://github.com/alecthomas/chroma/tree/master/styles
|
# https://github.com/alecthomas/chroma/tree/master/styles
|
||||||
# style: monokai
|
style: monokai
|
||||||
|
|
||||||
# Which 'chroma' "formatter" should be applied?
|
# Which 'chroma' "formatter" should be applied?
|
||||||
# One of: "terminal", "terminal256", "terminal16m"
|
# One of: "terminal", "terminal256", "terminal16m"
|
||||||
formatter: terminal
|
formatter: terminal256
|
||||||
|
|
||||||
# Through which pager should output be piped?
|
# Through which pager should output be piped?
|
||||||
# 'less -FRX' is recommended on Unix systems
|
# '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
|
# 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
|
# 'community' rather than your own, you can use: cheat tar -t community
|
||||||
cheatpaths:
|
cheatpaths:
|
||||||
|
|
||||||
# Paths that come earlier are considered to be the most "global", and will
|
# 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
|
# thus be overridden by more local cheatsheets. That being the case, you
|
||||||
# should probably list community cheatsheets first.
|
# should probably list community cheatsheets first.
|
||||||
|
@ -15,11 +15,22 @@ func Editor() (string, error) {
|
|||||||
return "notepad", nil
|
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")
|
nano, _ := exec.LookPath("nano")
|
||||||
|
vim, _ := exec.LookPath("vim")
|
||||||
|
|
||||||
// search for `$VISUAL`, `$EDITOR`, and then `nano`, in that order
|
// set editor priority
|
||||||
for _, editor := range []string{os.Getenv("VISUAL"), os.Getenv("EDITOR"), nano} {
|
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 != "" {
|
if editor != "" {
|
||||||
return editor, nil
|
return editor, nil
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,17 @@ package config
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pager attempts to locate a pager that's appropriate for the environment.
|
// Pager attempts to locate a pager that's appropriate for the environment.
|
||||||
func Pager() string {
|
func Pager() string {
|
||||||
|
|
||||||
|
// default to `more` on Windows
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return "more"
|
||||||
|
}
|
||||||
|
|
||||||
// if $PAGER is set, return the corresponding pager
|
// if $PAGER is set, return the corresponding pager
|
||||||
if os.Getenv("PAGER") != "" {
|
if os.Getenv("PAGER") != "" {
|
||||||
return os.Getenv("PAGER")
|
return os.Getenv("PAGER")
|
||||||
|
@ -20,11 +20,18 @@ func Run(configs string, confpath string) error {
|
|||||||
community := filepath.Join(confdir, "cheatsheets", "community")
|
community := filepath.Join(confdir, "cheatsheets", "community")
|
||||||
personal := filepath.Join(confdir, "cheatsheets", "personal")
|
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, "COMMUNITY_PATH", community, -1)
|
||||||
configs = strings.Replace(configs, "PERSONAL_PATH", personal, -1)
|
configs = strings.Replace(configs, "PERSONAL_PATH", personal, -1)
|
||||||
|
|
||||||
|
// locate and set a default pager
|
||||||
configs = strings.Replace(configs, "PAGER_PATH", config.Pager(), -1)
|
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
|
// prompt the user to download the community cheatsheets
|
||||||
yes, err := Prompt(
|
yes, err := Prompt(
|
||||||
"Would you like to download the community cheatsheets? [Y/n]",
|
"Would you like to download the community cheatsheets? [Y/n]",
|
||||||
|
@ -49,17 +49,18 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) {
|
|||||||
string(os.PathSeparator),
|
string(os.PathSeparator),
|
||||||
)
|
)
|
||||||
|
|
||||||
// ignore hidden files and directories. Otherwise, we'll likely load
|
// Don't walk the `.git` directory. Doing so creates
|
||||||
// .git/* and .DS_Store.
|
// 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
|
// NB: We _do_ want to walk hidden directories, however, so we
|
||||||
// contained within hidden directories in the middle of a path, though
|
// should not constrain this further (perhaps to include all
|
||||||
// that should not realistically occur.
|
// hidden directories). In the wild, many users appear to store
|
||||||
if strings.HasPrefix(title, ".") || strings.HasPrefix(info.Name(), ".") {
|
// cheatsheets in a `.config` directory (seemingly a default
|
||||||
// Do not walk hidden directories. This is important,
|
// behavior of `brew`), and `cheat` explicitly supports a
|
||||||
// because it's common for cheatsheets to be stored in
|
// local `.cheat` directory. Constraining further here will
|
||||||
// version-control, and a `.git` directory can easily
|
// break those use-cases - and has done so in the past!
|
||||||
// contain thousands of files.
|
if strings.Contains(path, ".git") {
|
||||||
return fs.SkipDir
|
return fs.SkipDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user