SourceTree文件導(dǎo)出

寫了個(gè)Mac下SourceTree文件導(dǎo)出功能的shell腳本,用于自定義操作,可實(shí)現(xiàn)類似于TortoiseGit的導(dǎo)出文件功能

  1. 腳本內(nèi)容
#!/bin/bash
# yifan 2017-12-01

DATE=`date +%m%d`
INIT_PATH=${1%/}
FILE_PATH=${2%/}
#自定義保存的位置
BASE_PATH="/Users/yifan/FileZilla/copy/$DATE"
SAVE_PATH=""

function checksavepath() {
    #序號(hào),保證每次都是新創(chuàng)建的“日期-[index]”的文件夾
    index=1
    path=${BASE_PATH}"-"$index
    while [ -d $path ]
    do
        let "index+=1"
        path=${BASE_PATH}"-"$index
    done
    SAVE_PATH=$path
#    echo "save path: ${SAVE_PATH}"

    mkdir ${SAVE_PATH}
#    touch $SAVE_PATH".log"
}

function getfilefromdir(){
    for file in ` ls $1`
    do
        if [ -d $1"/"$file ]
        then
            mkdir ${SAVE_PATH}"/"$file
            getfilefromdir $1"/"$file ${SAVE_PATH}"/"$file
        else
            local path="$1"
            local name=$file
            if [ ! -f $SAVE_PATH"/"$name ]
            then
                #確認(rèn)目錄存在,路徑不存在則創(chuàng)建
                parent=$(dirname $name)
                #應(yīng)該補(bǔ)全的文件夾路徑
                dirs="${parent#${INIT_PATH}}"
                #文件名
                filename="${var##*/}";
                #補(bǔ)全文件夾
                mkdir -p $2$dirs
                #輸出語(yǔ)句
                echo "cp ${path} to $2${dirs}/${filename}"
                #復(fù)制文件
                cp ${path} "$2${dirs}/${filename}"
            else
                echo "${path} file already exists"
#                echo "${path}" >> $SAVE_PATH".log" 2>&1
            fi
        fi
    done
}
checksavepath
#遍歷所有參數(shù)
for arg in $*
do
#判斷并排除為項(xiàng)目路徑的參數(shù)
if [ $arg != $INIT_PATH ]
then
    #復(fù)制文件
    getfilefromdir ${INIT_PATH}"/"$arg $SAVE_PATH
fi
done

2.修改導(dǎo)出文件的默認(rèn)路徑
BASE_PATH="/Users/yifan/FileZilla/copy/$DATE"
“/Users/yifan/FileZilla/copy/”是我mac上的路徑,“/$DATE”是指copy文件下的自動(dòng)以日期命名的文件,腳本中會(huì)自動(dòng)判斷日期命名的文件夾存在不,如果存在,則新建一個(gè)日期命名的文件夾并在后面加“-n”,n為自增序號(hào),1-n;

3.添加為自定義操作export


image.png

4.選中要導(dǎo)出的文件,右鍵->自定義操作->export


image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容