Revert back to using XDG on macOS

This commit is contained in:
Caleb Bassi 2019-02-16 02:11:05 -08:00
parent 357ff01fe3
commit 334f08bc5a
15 changed files with 26 additions and 242 deletions

View File

@ -14,7 +14,4 @@ Required information:
- Any relevenat hardware info: - Any relevenat hardware info:
- tmux version if using tmux: - tmux version if using tmux:
Also please copy or attach the following file if it exists and contains logs: Also please copy or attach `~/.local/state/gotop/errors.log` if it exists and contains logs:
- Linux: `~/.local/state/gotop/errors.log`
- OSX: `~/Library/Logs/gotop/errors.log`

View File

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Change `-v` cli option to `-V` for version - Change `-v` cli option to `-V` for version
- Revert back to using the XDG spec on macOS
### Fixed ### Fixed

View File

@ -85,7 +85,7 @@ brew install gotop
gotop ships with a few colorschemes which can be set with the `-c` flag followed by the name of one. You can find all the colorschemes in the [colorschemes folder](./colorschemes). gotop ships with a few colorschemes which can be set with the `-c` flag followed by the name of one. You can find all the colorschemes in the [colorschemes folder](./colorschemes).
To make a custom colorscheme, check out the [template](./colorschemes/template.go) for instructions and then use [default.json](./colorschemes/default.json) as a starter. Then put the file at `~/.config/gotop/<name>.json` on Linux or `~/Library/Application Support/gotop/<name>.json` on OSX and load it with `gotop -c <name>`. Colorschemes PR's are welcome! To make a custom colorscheme, check out the [template](./colorschemes/template.go) for instructions and then use [default.json](./colorschemes/default.json) as a starter. Then put the file at `~/.config/gotop/<name>.json` and load it with `gotop -c <name>`. Colorschemes PR's are welcome!
### CLI Options ### CLI Options

1
go.mod
View File

@ -1,7 +1,6 @@
module github.com/cjbassi/gotop module github.com/cjbassi/gotop
require ( require (
github.com/ProtonMail/go-appdir v0.0.0-20180220133335-7c788d1b45c6
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/cjbassi/battery v0.0.0-20190206091651-451cd0de3f6f github.com/cjbassi/battery v0.0.0-20190206091651-451cd0de3f6f
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect

2
go.sum
View File

@ -1,5 +1,3 @@
github.com/ProtonMail/go-appdir v0.0.0-20180220133335-7c788d1b45c6 h1:de/SvQsi6Oou9TJYp6Kp17S+JjXGn1w8XVYWFlE0z/U=
github.com/ProtonMail/go-appdir v0.0.0-20180220133335-7c788d1b45c6/go.mod h1:3d8Y9F5mbEUjrYbcJ3rcDxcWbqbttF+011nVZmdRdzc=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/cjbassi/battery v0.0.0-20190206091651-451cd0de3f6f h1:XtDkrKpWZomFY5YY7vjj/n024Ei/cpLrnrKvXrHI+2s= github.com/cjbassi/battery v0.0.0-20190206091651-451cd0de3f6f h1:XtDkrKpWZomFY5YY7vjj/n024Ei/cpLrnrKvXrHI+2s=

26
main.go
View File

@ -14,7 +14,6 @@ import (
"syscall" "syscall"
"time" "time"
appdir "github.com/ProtonMail/go-appdir"
docopt "github.com/docopt/docopt.go" docopt "github.com/docopt/docopt.go"
ui "github.com/gizak/termui" ui "github.com/gizak/termui"
@ -24,14 +23,15 @@ import (
) )
const ( const (
appName = "gotop"
version = "2.0.2" version = "2.0.2"
graphHorizontalScaleDelta = 3 graphHorizontalScaleDelta = 3
) )
var ( var (
configDir = appdir.New("gotop").UserConfig() configDir = getConfigDir(appName)
logDir = appdir.New("gotop").UserLogs() logDir = getLogDir(appName)
logPath = filepath.Join(logDir, "errors.log") logPath = filepath.Join(logDir, "errors.log")
stderrLogger = log.New(os.Stderr, "", 0) stderrLogger = log.New(os.Stderr, "", 0)
@ -62,6 +62,26 @@ var (
bar *w.StatusBar bar *w.StatusBar
) )
func getConfigDir(name string) string {
var basedir string
if env := os.Getenv("XDG_CONFIG_HOME"); env != "" {
basedir = env
} else {
basedir = filepath.Join(os.Getenv("HOME"), ".config")
}
return filepath.Join(basedir, name)
}
func getLogDir(name string) string {
var basedir string
if env := os.Getenv("XDG_STATE_HOME"); env != "" {
basedir = env
} else {
basedir = filepath.Join(os.Getenv("HOME"), ".local", "state")
}
return filepath.Join(basedir, name)
}
func parseArgs() error { func parseArgs() error {
usage := ` usage := `
Usage: gotop [options] Usage: gotop [options]

View File

@ -1,24 +0,0 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2016
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,52 +0,0 @@
# go-appdir
[![GoDoc](https://godoc.org/github.com/ProtonMail/go-appdir?status.svg)](https://godoc.org/github.com/ProtonMail/go-appdir)
Minimalistic Go package to get application directories such as config and cache.
Platform | Windows | [Linux/BSDs](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) | macOS
-------- | ------- | ------------------------------------------------------------------------------------------ | -----
User-specific config | `%APPDATA%` (`C:\Users\%USERNAME%\AppData\Roaming`) | `$XDG_CONFIG_HOME` (`$HOME/.config`) | `$HOME/Library/Application Support`
User-specific cache | `%LOCALAPPDATA%` (`C:\Users\%USERNAME%\AppData\Local`) | `$XDG_CACHE_HOME` (`$HOME/.cache`) | `$HOME/Library/Caches`
User-specific logs | `%LOCALAPPDATA%` (`C:\Users\%USERNAME%\AppData\Local`) | `$XDG_STATE_HOME` (`$HOME/.local/state`) | `$HOME/Library/Logs`
Inspired by [`configdir`](https://github.com/shibukawa/configdir).
## Usage
```go
package main
import (
"os"
"path/filepath"
"github.com/ProtonMail/go-appdir"
)
func main() {
// Get directories for our app
dirs := appdir.New("my-awesome-app")
// Get user-specific config dir
p := dirs.UserConfig()
// Create our app config dir
if err := os.MkdirAll(p, 0755); err != nil {
panic(err)
}
// Now we can use it
f, err := os.Create(filepath.Join(p, "config-file"))
if err != nil {
panic(err)
}
defer f.Close()
f.Write([]byte("<3"))
}
```
## License
MIT

View File

@ -1,17 +0,0 @@
// Get application directories such as config and cache.
package appdir
// Dirs requests application directories paths.
type Dirs interface {
// Get the user-specific config directory.
UserConfig() string
// Get the user-specific cache directory.
UserCache() string
// Get the user-specific logs directory.
UserLogs() string
}
// New creates a new App with the provided name.
func New(name string) Dirs {
return &dirs{name: name}
}

View File

@ -1,22 +0,0 @@
package appdir
import (
"os"
"path/filepath"
)
type dirs struct {
name string
}
func (d *dirs) UserConfig() string {
return filepath.Join(os.Getenv("HOME"), "Library", "Application Support", d.name)
}
func (d *dirs) UserCache() string {
return filepath.Join(os.Getenv("HOME"), "Library", "Caches", d.name)
}
func (d *dirs) UserLogs() string {
return filepath.Join(os.Getenv("HOME"), "Library", "Logs", d.name)
}

View File

@ -1,22 +0,0 @@
package appdir
import (
"os"
"path/filepath"
)
type dirs struct {
name string
}
func (d *dirs) UserConfig() string {
return filepath.Join(os.Getenv("APPDATA"), d.name)
}
func (d *dirs) UserCache() string {
return filepath.Join(os.Getenv("LOCALAPPDATA"), d.name)
}
func (d *dirs) UserLogs() string {
return filepath.Join(os.Getenv("LOCALAPPDATA"), d.name)
}

View File

@ -1,39 +0,0 @@
// +build !darwin,!windows
package appdir
import (
"os"
"path/filepath"
)
type dirs struct {
name string
}
func (d *dirs) UserConfig() string {
baseDir := filepath.Join(os.Getenv("HOME"), ".config")
if os.Getenv("XDG_CONFIG_HOME") != "" {
baseDir = os.Getenv("XDG_CONFIG_HOME")
}
return filepath.Join(baseDir, d.name)
}
func (d *dirs) UserCache() string {
baseDir := filepath.Join(os.Getenv("HOME"), ".cache")
if os.Getenv("XDG_CACHE_HOME") != "" {
baseDir = os.Getenv("XDG_CACHE_HOME")
}
return filepath.Join(baseDir, d.name)
}
func (d *dirs) UserLogs() string {
baseDir := filepath.Join(os.Getenv("HOME"), ".local", "state")
if os.Getenv("XDG_STATE_HOME") != "" {
baseDir = os.Getenv("XDG_STATE_HOME")
}
return filepath.Join(baseDir, d.name)
}

View File

@ -1,32 +0,0 @@
// +build ignore
package main
import (
"os"
"path/filepath"
"github.com/ProtonMail/go-appdir"
)
func main() {
// Get directories for our app
dirs := appdir.New("my-awesome-app")
// Get user-specific config dir
p := dirs.UserConfig()
// Create our app config dir
if err := os.MkdirAll(p, 0755); err != nil {
panic(err)
}
// Now we can use it
f, err := os.Create(filepath.Join(p, "config-file"))
if err != nil {
panic(err)
}
defer f.Close()
f.Write([]byte("<3"))
}

2
vendor/modules.txt vendored
View File

@ -1,5 +1,3 @@
# github.com/ProtonMail/go-appdir v0.0.0-20180220133335-7c788d1b45c6
github.com/ProtonMail/go-appdir
# github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 # github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6
github.com/StackExchange/wmi github.com/StackExchange/wmi
# github.com/cjbassi/battery v0.0.0-20190206091651-451cd0de3f6f # github.com/cjbassi/battery v0.0.0-20190206091651-451cd0de3f6f