mirror of
https://github.com/cheat/cheat.git
synced 2024-11-24 06:51:36 +01:00
feat(installer): set default editor
Attempt to set and locate a default editor when running the installer.
This commit is contained in:
parent
0c47f44ff9
commit
6421953183
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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]",
|
||||||
|
Loading…
Reference in New Issue
Block a user