8000 make the script can detect the author name automatically · JavaScriptor/leetcode@32ce962 · GitHub
[go: up one dir, main page]

Skip to content

Commit 32ce962

Browse files
committed
make the script can detect the author name automatically
1 parent cf12236 commit 32ce962

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/comments.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
AUTHOR="Hao Chen"
4+
AUTHOR="NOBODY"
55
LEETCODE_URL=https://leetcode.com/problems/
66
LEETCODE_NEW_URL=https://leetcode.com/problems/
77
LEETCODE_OLD_URL=https://oj.leetcode.com/problems/
@@ -23,6 +23,18 @@ function usage()
2323
echo -e ""
2424
}
2525

26+
function get_author_name()
27+
{
28+
TRUE_CMD=`which true`
29+
git=`type -P git || ${TRUE_CMD}`
30+
if [ ! -z "${git}" ]; then
31+
AUTHOR=`git config --get user.name`
32+
else
33+
AUTHOR=`whoami`
34+
fi
35+
}
36+
37+
2638
function detect_os()
2739
{
2840
platform='unknown'
@@ -138,6 +150,9 @@ if [ ! -s $source_file ]; then
138150
echo "" > $source_file
139151
fi
140152

153+
#detect the author name
154+
get_author_name;
155+
141156
#adding the Copyright Comments
142157
if ! grep -Fq "${COMMENT_TAG} Author :" $source_file ; then
143158
sed -i.bak '1i\'$'\n'"${COMMENT_TAG} Source : ${leetcode_url}"$'\n' $source_file

0 commit comments

Comments
 (0)
0