Skip to content

Commit 93a3303

Browse files
author
Cerem Cem ASLAN
committed
added reading from pipe
1 parent e3787f3 commit 93a3303

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
A utility to create gists from command line
44

5+
usage:
56

6-
usage:
7+
create-gist.sh /path/to/file [Github user name]
78

8-
create-gist.sh /path/to/file [Github user name]
9+
or
910

11+
lsusb | create-gist.sh [Github user name]
1012

create-gist.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,39 @@
66
print_usage(){
77
cat << USAGE
88
9-
usage:
10-
11-
$(basename $0) /path/to/file [Github user name]
9+
usage:
10+
11+
$(basename $0) /path/to/file [Github user name]
12+
13+
or
14+
15+
lsusb | $(basename $0) [Github user name]
1216
1317
USAGE
1418
}
1519

1620
# 0. Your file name
1721
FNAME=$1
18-
19-
if [[ ! -f $FNAME ]]; then
20-
print_usage
21-
exit 2
22+
if [[ -f $FNAME ]]; then
23+
CONTENT=$(cat $FNAME)
24+
GITHUB_USERNAME=$2
25+
else
26+
CONTENT=$(timeout 2 cat -)
27+
GITHUB_USERNAME=$1
28+
FNAME="stdin"
29+
if [[ "$CONTENT" == "" ]]; then
30+
print_usage
31+
exit 2
32+
fi
2233
fi
2334

24-
# 0.1 Your username (optional)
25-
GITHUB_USERNAME=$2
26-
2735

2836
# 1. Somehow sanitize the file content
2937
# Remove \r (from Windows end-of-lines),
3038
# Replace tabs by \t
3139
# Replace " by \"
3240
# Replace EOL by \n
33-
CONTENT=$(sed -e 's/\r//' -e's/\t/\\t/g' -e 's/"/\\"/g' "${FNAME}" | awk '{ printf($0 "\\n") }')
41+
CONTENT=$(echo "${CONTENT}" | sed -e 's/\r//' -e's/\t/\\t/g' -e 's/"/\\"/g' | awk '{ printf($0 "\\n") }')
3442

3543
read -p "Give a description: " DESCRIPTION
3644

0 commit comments

Comments
 (0)