From 559b238897192ffe74a4348301ff57fef00ac21e Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 14 Nov 2018 10:57:03 -0800 Subject: [PATCH] Update post2blog.sh add choosen for multiply repository locations --- post2blog.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/post2blog.sh b/post2blog.sh index 8d441b0..438250c 100755 --- a/post2blog.sh +++ b/post2blog.sh @@ -81,10 +81,11 @@ function dispOptionShort(){ } #change initial parameters depending on your own file system -_repository_address="/Users/zhangyi/Code/GitHub/YiZhangCUG.github.io" +_my_repository_addresses=("/Users/zhangyi/Code/GitHub/YiZhangCUG.github.io" "/Users/zhangyi/Documents/GitHub/YiZhangCUG.github.io") +_repository_address=${_my_repository_addresses[0]} _posts_address="_posts/" #directory of your posts _assets_address="assets/" #directory of your assets -_posts_sub_address="2018/" #sub-directory of your posts +_posts_sub_address=`date +"%Y-%m/"` #sub-directory of your posts _mfile='README.md' #default input filename _layout='post' #default post layout _categories='Null' #default category @@ -99,8 +100,9 @@ _outfile_end='Null' _savefile=0 _link_string="" _no_questions=0 +_repository_id=0 #get arguments from terminal -while getopts "hSVi:l:T:c:t:s:" arg +while getopts "hSVi:l:T:c:t:s:r:" arg do case $arg in h) @@ -115,6 +117,7 @@ do dispOptionShort "-s" "Sub-directory of the posts. The main directory of the posts is placed under '${_posts_address}' folder of your github.io directory. The default is '${_posts_sub_address}'." dispOptionShort "-S" "Save output markdown file. The default will remove the output file after committing the blog to Github." dispOptionShort "-V" "Don't ask me questions." + dispOptionShort "-r" "choose repository your want to use, The default will use the first one." dispOptionShort "-h" "Show help information." exit 0;; i) @@ -133,6 +136,8 @@ do _savefile=1;; V) _no_questions=1;; + r) + _repository_id=$OPTARG;; ?) printf "\e[1m\e[31mError ==>\e[0m Unknow argument.\n" printf "Use -h option to see help information.\n" @@ -140,6 +145,10 @@ do esac done +if [[ ${_repository_id} != 0 ]]; then + _repository_address=${_my_repository_addresses[${_repository_id}]} +fi + #check if _title is set or not. If so, skip getting _title and _outfile_end from the input file if [[ ${_title} != 'Null' ]]; then #read input file and put it into a temporary file