Home

终端命令行篇-起始

终端命令脚本

为了,不一次次重复。集合工作流程为命令,是必要的。 我所有的*-zh 项目:中文翻译 和 *-explain:解释都是从这里开始的。

开始中文翻译(zh)

$ init https://github.com/worrydream/Tangle.git es

开始解释项目(explain)

$ init https://github.com/worrydream/Tangle.git ex

总览脚本

此终端脚本思路

# init.sh

one=${1#*github.com\/}
#echo $one
two=${one//.git/}
#echo $two
repo=${two#*/}
#echo $repo

# https://github.com/worrydream/Tangle.git ==> Tangle

if [ "$2" = "ex" ];then
echo "explain <-><0>"
repodir=$repo'-explain'
else
echo "translate <><>"
repodir=$repo'-zh'
fi

echo "1. $repodir"
mkdir $repodir
cd $repodir

echo "\n2. source dir"
git init
if [ "$3" = "no" ];then
# es repo.git no local-path
echo `ln -s $4 ./source`
else
git clone $1 'source'
fi
cd 'source' && COMMIT=`git rev-parse HEAD` && DATE=`git log -1 --date=short --format="%ad"`
cd -
echo "\n3. git info"

echo $1
echo $COMMIT
echo $DATE

echo "\n4. mrm ***"
mrm readme --config:repos $2 --config:name $1 --config:commit $COMMIT --config:date $DATE
mrm gitignore
source ~/.zshrc  &>/dev/null

sleep .5


echo "5. find *.md with source into .mds-list"
list="$(find ./source -type f -name \*.md)"
echo "here >>>>>> $list\n"
echo "$list\n" > './.mds-list';

echo "6. add sync-en.sh to sync en:*.md with .mds-list "
cat "$HOME/sync-en.sh" > ./sync-en.sh
chmod +x ./sync-en.sh

echo "\n7. use translate-mds, translate readme.md and move"
translateMds source/readme.md -T 'inlineCode,link' -C
cp source/readme.md ./en.md

echo "\n8. doc-templite"
if [ "$2" = "ex" ];then
echo "explain"
doc-templite-explain
cat source/readme.zh.md >> ./zh.md
else
echo "translate"
doc-templite-translate
cat source/readme.zh.md >> ./readme.md
fi


echo "\n9. >> hub cmd to hub-create.sh"
if [ "$2" = "ex" ];then

huC='hub create -d "explain:<'$two'> something :heart: explaining" '

else

huC='hub create -d "中文翻译:<'$two'> something :heart: working on" '
fi

echo $huC >> hub-create.sh

sync-en.sh

主要是,对.mds-list的复制

cat './.mds-list' | while read line || [[ -n ${line} ]]
do
    testseq="zh.md"
    if [[ $line =~ $testseq || "$line" == "" ]]; then
        echo "skip $line"
    else
        lowline=`echo "$line" | awk '{print tolower($0)}'`
        # lowwer string
        zh=${line//source\//}
        dir=$(dirname $zh)

        source_readme="./source/readme.md"
        if [[ $lowline == $source_readme ]];then
        # source/[readme|REAMDE].md => en.md
        filename="en.md"
        else
        # source/other.md => ./other.md
        filename=$(basename $zh)
        fi
        echo "$line >> $dir/$filename"
        mkdir -p $dir && cp $line "$_/$filename"
    fi
done