From f5c5c51f2f70907d6cdaecbfe550c6e3abeb1630 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 20 Sep 2022 16:12:54 +0200 Subject: [PATCH] feat: Use .smug.yml as a default configuration file --- .smug.yml | 8 ++++++++ README.md | 3 ++- main.go | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .smug.yml diff --git a/.smug.yml b/.smug.yml new file mode 100644 index 0000000..ab197d9 --- /dev/null +++ b/.smug.yml @@ -0,0 +1,8 @@ +session: smug + +root: . + +windows: + - name: code + commands: + - go test ./... diff --git a/README.md b/README.md index 3294097..9578eab 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,8 @@ xyz@localhost:~$ smug start -f ./project.yml -w window1 -w window2 ## Configuration -Configuration files stored in the `~/.config/smug` directory in the `YAML` format, e.g `~/.config/smug/your_project.yml`. +Configuration files can stored in the `~/.config/smug` directory in the `YAML` format, e.g `~/.config/smug/your_project.yml`. +You may also create a file named `.smug.yml` in the current working directory, which will be used by default. ### Examples diff --git a/main.go b/main.go index d5c9a4f..d139750 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,8 @@ Examples: $ smug print > ~/.config/smug/blog.yml `, version, FileUsage, WindowsUsage, AttachUsage, InsideCurrentSessionUsage, DebugUsage, DetachUsage) +const defaultConfigFile = ".smug.yml" + func newLogger(path string) *log.Logger { logFile, err := os.Create(filepath.Join(path, "smug.log")) if err != nil { @@ -87,8 +89,15 @@ func main() { var configPath string if options.Config != "" { configPath = options.Config - } else { + } else if options.Project != "" { configPath = filepath.Join(userConfigDir, options.Project+".yml") + } else { + path, err := os.Getwd() + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + configPath = filepath.Join(path, defaultConfigFile) } switch options.Command {