GeezerVison is showing github.com — add readme.sh script to help to generate the content in README.md for… · weimo/leetcode@7f16adf
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: scripts/README.md +13Lines changed: 13 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -44,3 +44,16 @@ The comments would be generated by above examples as below: |
44 | 44 |
|
45 | 45 |
|
46 | 46 | ``` |
| 47 | + |
| 48 | +### readme.sh |
| 49 | + |
| 50 | +`readme.sh` - it's used to generate the table item in README.md |
| 51 | + |
| 52 | +For example: |
| 53 | + |
| 54 | +``` |
| 55 | +$ ./readme.sh ../algorithms/cpp/nextPermutation/nextPermutation.cpp |
| 56 | +|31|[Next Permutation](https://oj.leetcode.com/problems/next-permutation/) | [C++](./algorithms/cpp/nextPermutation/nextPermutation.cpp)|Medium| |
| 57 | +``` |
| 58 | + |
| 59 | + |
Collapse file
Copy file name to clipboard +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | + |
| 4 | +function usage() |
| 5 | +{ |
| 6 | + |
| 7 | + echo -e "Usage: ${0} [file]" |
| 8 | + echo -e "" |
| 9 | + echo -e "Example:" |
| 10 | + echo -e "" |
| 11 | + echo -e " ${0} ./LargestNumber.cpp" |
| 12 | + echo -e "" |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +if [ $# -lt 1 ] || [[ ! -f ${1} ]]; then |
| 18 | + usage |
| 19 | + exit 255 |
| 20 | +fi |
| 21 | + |
| 22 | +DIR=`cd $(dirname ${1}) && pwd -P` |
| 23 | +FILE=${DIR}/$(basename ${1}) |
| 24 | + |
| 25 | +URL=`grep Source ${FILE} | awk '{print $4}'` |
| 26 | +title_str=`xidel ${URL} -q -e "css('div.question-title h3')"` |
| 27 | +NUM=`echo ${title_str} | awk -F '.' '{print $1}'` |
| 28 | +TITLE=`echo ${title_str} | awk -F '.' '{print $2}' | sed -e 's/^[[:space:]]*//'` |
| 29 | +DIFFCULT=`xidel ${URL} -q -e "css('.question-info')" | grep Difficulty | awk '{print $2}'` |
| 30 | + |
| 31 | +FILE=`echo ${FILE} | sed "s/.*\/algorithms/\.\/algorithms/"` |
| 32 | + |
| 33 | +echo "|${NUM}|[${TITLE}](${URL}) | [C++](${FILE})|${DIFFCULT}|" |