ref: ec4b6c03a8139988d6456195fe098b3dcfaca91d
parent: 2c8e9a79313f91a55e5c99fd20f88acc4035bd2d
author: Austin Ziegler <[email protected]>
date: Tue Oct 14 18:48:55 EDT 2014
Trigger an editor after `hugo new`. - Trigger permanently with NewContentEditor in config.{toml,yaml,json}. - Trigger on an individual basis with --editor.
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -56,7 +56,7 @@
//Flags that are to be added to commands.
var BuildWatch, Draft, Future, UglyUrls, Verbose, Logging, VerboseLog, DisableRSS, DisableSitemap, PluralizeListTitles, NoTimes bool
-var Source, Destination, Theme, BaseUrl, CfgFile, LogFile string
+var Source, Destination, Theme, BaseUrl, CfgFile, LogFile, Editor string
//Execute adds all child commands to the root command HugoCmd and sets flags appropriately.
func Execute() {
@@ -88,6 +88,7 @@
HugoCmd.PersistentFlags().BoolVar(&UglyUrls, "uglyUrls", false, "if true, use /filename.html instead of /filename/")
HugoCmd.PersistentFlags().StringVarP(&BaseUrl, "baseUrl", "b", "", "hostname (and path) to the root eg. http://spf13.com/")
HugoCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
+ HugoCmd.PersistentFlags().StringVar(&Editor, "editor", "", "edit new content with this editor, if provided")
HugoCmd.PersistentFlags().BoolVar(&Logging, "log", false, "Enable Logging")
HugoCmd.PersistentFlags().StringVar(&LogFile, "logFile", "", "Log File path (if set, logging enabled automatically)")
HugoCmd.PersistentFlags().BoolVar(&VerboseLog, "verboseLog", false, "verbose logging")
@@ -134,6 +135,7 @@
viper.SetDefault("PluralizeListTitles", true)
viper.SetDefault("FootnoteAnchorPrefix", "")
viper.SetDefault("FootnoteReturnLinkContents", "")
+ viper.SetDefault("NewContentEditor", "")
if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
viper.Set("BuildDrafts", Draft)
@@ -161,6 +163,10 @@
if hugoCmdV.PersistentFlags().Lookup("pluralizeListTitles").Changed {
viper.Set("PluralizeListTitles", PluralizeListTitles)
+ }
+
+ if hugoCmdV.PersistentFlags().Lookup("editor").Changed {
+ viper.Set("NewContentEditor", Editor)
}
if hugoCmdV.PersistentFlags().Lookup("logFile").Changed {
--- a/create/content.go
+++ b/create/content.go
@@ -17,6 +17,8 @@
"bytes"
"io/ioutil"
"os"
+ "os/exec"
+ "path"
"path/filepath"
"strings"
"time"
@@ -103,6 +105,21 @@
return
}
jww.FEEDBACK.Println(helpers.AbsPathify(filepath.Join(viper.GetString("contentDir"), name)), "created")
+
+ editor := viper.GetString("NewContentEditor")
+
+ if editor != "" {
+ jww.FEEDBACK.Printf("Editing %s in %s.\n", name, editor)
+
+ cmd := exec.Command(editor, path.Join(viper.GetString("contentDir"), name))
+ cmd.Stdin = os.Stdin
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+
+ if err = cmd.Run(); err != nil {
+ return
+ }
+ }
return nil
}