Home

终端命令行篇-起始

终端命令脚本

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

开始中文翻译(zh)

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

开始解释项目(explain)

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

总览脚本

此终端脚本思路

repo="${1##*/}"
repo=${repo/.git/}
two=$repo
echo "$repo"

source $HOME/.bashrc

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
    cd -
    abspath=$(cd ${4%/*} && echo $PWD/${4##*/})
    echo `ln -s $abspath $PWD/$repodir/source`
    cd -
else
    git clone $1 'source'
fi
cd './source' || mkdir "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

if [[ $PWD =~ "-zh" || $PWD =~ "-explain" ]]; then
    echo "\n5. mrm ***"
    mrm readme --config:repos $2 --config:name $1 --config:commit $COMMIT --config:date $DATE
    mrm gitignore

    sleep .5

    echo "6. find *.md with source into .mds-list"
    list="$(find ./source -type f -name \*.md)"
    echo "here >>>>>> $list\n"
    echo "$list\n" >'./.mds-list'
    # for file in $list; do if [ ! -f "$file" ]; then
    # echo "MISSING: $file"
    # else
    # echo "$file\n" >> "./mds-list";
    # fi;
    # done

    echo "7. 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 "\n8. start translate readme.md and move"
    local-translateMds source/readme.md -T 'inlineCode,link' -C
    cp source/readme.md ./en.md

    echo "\n9. 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 "\n10. >> hub cmd to hub-create.sh"
    if [ "$2" = "ex" ]; then

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

    else

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

    echo $huC >>hub-create.sh

else

    echo "错误 :not in *-zh Dir"
fi

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