Skip to content

Commit fc87a5a

Browse files
author
Philip Hallstrom
committed
when gisting stdin default to filename 'gistfile1.txt' instead of '-'
fixes #235 test plan: ``` - ensure you're signed in (ie. have a token) % gist Gemfile # check gist, filename should be 'Gemfile' % jot 5 | gist # check gist, filename should be 'gistfile1.txt' % jot 5 | gist Gemfile - # check gist, filenames should be 'Gemfile' and 'gistfile1.txt' ```
1 parent c817380 commit fc87a5a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/gist.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ def auth_token
7676
#
7777
# @see http://developer.github.com/v3/gists/
7878
def gist(content, options = {})
79-
filename = options[:filename] || "a.rb"
79+
filename = options[:filename] || default_filename
8080
multi_gist({filename => content}, options)
8181
end
8282

83+
def default_filename
84+
"gistfile1.txt"
85+
end
86+
8387
# Upload a gist to https://gist.github.com
8488
#
8589
# @param [Hash] files the code you'd like to gist: filename => content
@@ -114,7 +118,8 @@ def multi_gist(files, options={})
114118
if content.to_s.strip == ""
115119
raise "Cannot gist empty files" unless options[:skip_empty]
116120
else
117-
json[:files][File.basename(name)] = {:content => content}
121+
name = name == "-" ? default_filename : File.basename(name)
122+
json[:files][name] = {:content => content}
118123
end
119124
end
120125

0 commit comments

Comments
 (0)