Skip to content

Commit

Permalink
Respect the XDG Base Directory specification for configs
Browse files Browse the repository at this point in the history
Rather than assuming a configuration file at `~/.slack-term`, respect
the user's choice per the XDG Base Directory specification
(https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
to find the configuration.

Uses a cross-platform XDG library to abstract the details of the
specification and encompass any future changes
(https://github.com/OpenPeeDeeP/xdg, https://godoc.org/github.com/OpenPeeDeeP/xdg).

After merging, the [wiki home page](https://github.com/erroneousboat/slack-term/wiki)
should be updated to reflect the new configuration location.

This closes #170 and closes #203.
  • Loading branch information
lhanson authored and jpbruinsslot committed Jan 8, 2020
1 parent 78d1eb5 commit ce1d8ce
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ ENV USER root
COPY --from=builder /usr/bin/slack-term /usr/bin/slack-term
COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs

ENTRYPOINT stty cols 25 && slack-term -config .slack-term
ENTRYPOINT stty cols 25 && slack-term -config ~/.config/slack-term/config
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ $ go install .
Setup
-----

1. Get a slack token, click [here](https://api.slack.com/docs/oauth-test-tokens)
1. Get a slack token, click [here](https://api.slack.com/docs/oauth-test-tokens)

2. Create a `.slack-term` file, and place it in your home directory. Below is
an example of such a file. You are only required to specify a
`slack_token`. For more configuration options of the `.slack-term` file,
see the [wiki](https://github.com/erroneousboat/slack-term/wiki).
2. Create a file named `config` in the `$XDG_CONFIG_HOME/slack-term` directory
(the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
specifies `$HOME/.config/` if you do not have `$XDG_CONFIG_HOME` explicitly
set). Below is an example of such a file. You are only required to specify a
`slack_token`. For more configuration options of the `config` file, see
the [wiki](https://github.com/erroneousboat/slack-term/wiki).

```javascript
{
Expand All @@ -49,7 +51,7 @@ Usage
-----

When everything is setup correctly you can run `slack-term` with the following
command:
command:

```bash
$ slack-term
Expand All @@ -59,7 +61,7 @@ Default Key Mapping
-------------------

Below are the default key-mappings for `slack-term`, you can change them
in your `.slack-term` file.
in your `config` file.

| mode | key | action |
|---------|-----------|----------------------------|
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/0xAX/notificator v0.0.0-20171022182052-88d57ee9043b
github.com/OpenPeeDeeP/xdg v0.2.0
github.com/erroneousboat/termui v0.0.0-20170923115141-80f245cdfa04
github.com/gorilla/websocket v1.4.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/0xAX/notificator v0.0.0-20171022182052-88d57ee9043b h1:Sn+u6zpXFyfm2X7ruh+z6SJiUVyFg8YElh6HIOhrRCA=
github.com/0xAX/notificator v0.0.0-20171022182052-88d57ee9043b/go.mod h1:NtXa9WwQsukMHZpjNakTTz0LArxvGYdPA9CjIcUSZ6s=
github.com/OpenPeeDeeP/xdg v0.2.0 h1:xr89rnllbkRkM7SV9Y++FJ8TGkbdkhhBQm5kOkGT7AE=
github.com/OpenPeeDeeP/xdg v0.2.0/go.mod h1:tMoSueLQlMf0TCldjrJLNIjAc5qAOIcHt5REi88/Ygo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -31,6 +33,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/user"
"path"

"github.com/OpenPeeDeeP/xdg"
"github.com/erroneousboat/termui"
termbox "github.com/nsf/termbox-go"

Expand Down Expand Up @@ -51,11 +52,19 @@ func init() {
log.Fatal(err)
}

// Find the default config file
xdg := xdg.New("slack-term", "")
configFile := xdg.QueryConfig("config")
if configFile == "" {
// Fall back to $HOME/.slack_term for legacy compatibility
configFile = path.Join(usr.HomeDir, ".slack-term")
}

// Parse flags
flag.StringVar(
&flgConfig,
"config",
path.Join(usr.HomeDir, ".slack-term"),
configFile,
"location of config file",
)

Expand Down

0 comments on commit ce1d8ce

Please sign in to comment.