File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,21 @@ A utility to create gists from command line
10
10
11
11
lsusb | create-gist.sh Github_user_name
12
12
13
+ or
14
+
15
+ lsusb | create-gist.sh your_token
16
+
17
+
18
+ # Creating OAuth token
19
+
20
+ 1 . Go to https://github.com/settings/tokens/new and generate a new token with ` create gist ` permission.
21
+ 2 . Use the token for authentication:
22
+
23
+ ```
24
+ lsusb | create-gist.sh your-token-here
25
+ ```
26
+
27
+
13
28
# Dependencies
14
29
15
30
* ` curl `
Original file line number Diff line number Diff line change @@ -17,17 +17,21 @@ print_usage(){
17
17
18
18
lsusb | $( basename $0 ) Github_user_name
19
19
20
+ or
21
+
22
+ lsusb | $( basename $0 ) your_token
23
+
20
24
USAGE
21
25
}
22
26
23
27
# 0. Your file name
24
28
FNAME=" ${1:- } "
25
29
if [[ -f " $FNAME " ]]; then
26
30
CONTENT=$( cat " $FNAME " )
27
- GITHUB_USERNAME =" ${2:- } "
31
+ CREDENTIAL =" ${2:- } "
28
32
else
29
33
CONTENT=$( timeout 2 cat -)
30
- GITHUB_USERNAME =" ${1-} "
34
+ CREDENTIAL =" ${1-} "
31
35
FNAME=" stdin"
32
36
if [[ " $CONTENT " == " " ]]; then
33
37
print_usage
36
40
fi
37
41
38
42
# Github does not permit anonymous uploads since April 2018
39
- if [[ -z $GITHUB_USERNAME ]]; then
43
+ if [[ -z $CREDENTIAL ]]; then
40
44
print_usage
41
45
exit 2
42
46
fi
@@ -68,7 +72,15 @@ cat > $tmp_file <<EOF
68
72
EOF
69
73
70
74
# 4. Use curl to make a POST request
71
- OUTPUT=$( curl -u ${GITHUB_USERNAME} -X POST -d @$tmp_file " https://api.github.com/gists" )
75
+ if [[ ${# CREDENTIAL} -eq 40 ]]; then
76
+ echo " Using token authentication."
77
+ OUTPUT=$( curl -H " Authorization: token ${CREDENTIAL} " \
78
+ -X POST -d @$tmp_file " https://api.github.com/gists" )
79
+ else
80
+ echo " Using username/password authentication."
81
+ OUTPUT=$( curl -u ${CREDENTIAL} \
82
+ -X POST -d @$tmp_file " https://api.github.com/gists" )
83
+ fi
72
84
uploaded_url=$( echo " $OUTPUT " | grep ' html_url' | grep ' gist' )
73
85
74
86
# 5. cleanup the tmp file
You can’t perform that action at this time.
0 commit comments