1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| nofile() { touch source/_data/shuoshuo.yml echo >> source/_data/shuoshuo.yml echo "- date: $(date +'%Y-%m-%d %H:%M:%S')" >> source/_data/shuoshuo.yml echo " key: 1" >> source/_data/shuoshuo.yml echo " content: $@" >> source/_data/shuoshuo.yml }
hadfile() { key=$(grep -oE 'key: [0-9]+' source/_data/shuoshuo.yml | \ tail -n 1 | \ sed 's/key: //') ((key++)) echo >> source/_data/shuoshuo.yml echo "- date: $(date +'%Y-%m-%d %H:%M:%S')" >> source/_data/shuoshuo.yml echo " key: $key" >> source/_data/shuoshuo.yml echo " content: $@" >> source/_data/shuoshuo.yml }
if [[ -f source/_data/shuoshuo.yml ]] then hadfile $@ else nofile $@ fi
|