Skip to content

Commit 21861ce

Browse files
authored
Merge pull request #258 from gcbw/patch-1
fix token file name
2 parents 431ee0e + addb2c0 commit 21861ce

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,38 @@ an OAuth2 token (with the "gist" permission).
9292

9393
This token is stored in `~/.gist` and used for all future gisting. If you need to
9494
you can revoke it from https://github.com/settings/tokens, or just delete the
95-
file. If you need to store tokens for both github.com and a Github Enterprise instance
96-
you can save your Github Enterprise token in `~/.gist.github.example.com` where
97-
"github.example.com" is the URL for your Github Enterprise instance.
95+
file.
9896

9997
‌After you've done this, you can still upload gists anonymously with `-a`.
10098

10199
gist -a a.rb
102100

101+
### GitHub Enterprise
102+
103+
If you'd like `gist` to use your locally installed [GitHub Enterprise](https://enterprise.github.com/),
104+
you need to export the `GITHUB_URL` environment variable (usually done in your `~/.bashrc`).
105+
106+
export GITHUB_URL=http://github.internal.example.com/
107+
108+
Once you've done this and restarted your terminal (or run `source ~/.bashrc`), gist will
109+
automatically use github enterprise instead of the public github.com
110+
111+
Your token for GitHub Enterprise will be stored in `.gist.<protocol>.<server.name>[.<port>]` (e.g.
112+
`~.gist.http.github.internal.example.com` for the GITHUB_URL example above) instead of `~/.gist`.
113+
114+
If you have multiple servers or use Enterprise and public GitHub often, you can work around this by creating scripts
115+
that set the env var and then run `gist`. Keep in mind that to use the public GitHub you must unset the env var. Just
116+
setting it to the public URL will not work. Use `unset GITHUB_URL`
117+
118+
### Token file format
119+
120+
If you cannot use passwords, as most Enterprise installations do, you can generate the token via the web interface
121+
and then simply save the string in the correct file. Avoid line breaks or you might see:
122+
```
123+
$ gist -l
124+
Error: Bad credentials
125+
```
126+
103127
# Library
104128

105129
‌You can also use Gist as a library from inside your ruby code:
@@ -131,16 +155,6 @@ NOTE: The access_token must have the "gist" scope.
131155
‌This will take them through the process of obtaining an OAuth2 token, and storing it
132156
in `~/.gist`, where it can later be read by `Gist.gist`
133157

134-
## GitHub enterprise
135-
136-
‌If you'd like `gist` to use your locally installed [GitHub Enterprise](https://enterprise.github.com/),
137-
you need to export the `GITHUB_URL` environment variable in your `~/.bashrc`.
138-
139-
export GITHUB_URL=http://github.internal.example.com/
140-
141-
‌Once you've done this and restarted your terminal (or run `source ~/.bashrc`), gist will
142-
automatically use github enterprise instead of the public github.com
143-
144158
## Configuration
145159

146160
‌If you'd like `-o` or `-c` to be the default when you use the gist executable, add an

lib/gist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ClipboardError < RuntimeError; include Error end
4444
module AuthTokenFile
4545
def self.filename
4646
if ENV.key?(URL_ENV_NAME)
47-
File.expand_path "~/.gist.#{ENV[URL_ENV_NAME].gsub(/[^a-z.]/, '')}"
47+
File.expand_path "~/.gist.#{ENV[URL_ENV_NAME].gsub(/:/, '.').gsub(/[^a-z0-9.]/, '')}"
4848
else
4949
File.expand_path "~/.gist"
5050
end

spec/auth_token_file_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
before do
2020
ENV[Gist::URL_ENV_NAME] = github_url
2121
end
22-
let(:github_url) { "gh.custom.org" }
22+
let(:github_url) { "http://gh.custom.org:442/" }
2323

2424
it "is ~/.gist.{custom_github_url}" do
25-
File.should_receive(:expand_path).with("~/.gist.#{github_url}").and_return(filename)
25+
File.should_receive(:expand_path).with("~/.gist.http.gh.custom.org.442").and_return(filename)
2626
subject.filename.should be filename
2727
end
2828
end

0 commit comments

Comments
 (0)