vim docker

just read for myself

start_vim.sh

#!/bin/bash

filename=$1

script_path=$(cd $(dirname ${BASH_SOURCE[0]});pwd)

bash  ${script_path}/v.sh ${LINES} ${COLUMNS} `pwd` ${filename}

 

v.sh

▽

▽
#!/bin/bash

LINES=$1
COLUMNS=$2
script_path=$3
filename=$4


function write_header () {
    suffix=$(echo ${filename} | awk -F "." '{print $2}')
    if [[ ${suffix} == "cpp" ]];then
        echo -e "/*************************************************" >> ${script_path}/${filename}
        echo -e "*" >> ${script_path}/${filename}
        echo -e "* Copyright (c) Baidu.com, Inc. All Rights Reserved" >> ${script_path}/${filename}
        echo -e "*" >> ${script_path}/${filename}
        echo -e "* @Author : liuyu" >> ${script_path}/${filename}
        echo -e "* @email : [email protected]" >> ${script_path}/${filename}
        echo -e "* @Created Time :  $(date)" >>  ${script_path}/${filename}
        echo -e "* @Description : " >>  ${script_path}/${filename}
        echo -e "*************************************************/" >> ${script_path}/${filename}
    elif [[ ${suffix} == "sh" ]];then
        echo -e "#################################################" >> ${script_path}/${filename}
        echo -e "#" >> ${script_path}/${filename}
        echo -e "# Copyright (c) Baidu.com, Inc. All Rights Reserved" >> ${script_path}/${filename}
        echo -e "#" >> ${script_path}/${filename}
        echo -e "# @Author : liuyu" >> ${script_path}/${filename}
        echo -e "# @email : [email protected]" >> ${script_path}/${filename}
        echo -e "# @Created Time :  $(date)" >> ${script_path}/${filename}
        echo -e "# @Description : " >> ${script_path}/${filename}
        echo -e "#################################################" >> ${script_path}/${filename}
        echo -e "    " >> ${script_path}/${filename}
        echo -e "#!/bin/sh" >> ${script_path}/${filename}
    elif [[ ${suffix} == "py" ]];then
        echo -e "# -*- coding: UTF-8 -*-" >> ${script_path}/${filename}
        echo -e "#################################################" >> ${script_path}/${filename}
        echo -e "#" >> ${script_path}/${filename}
        echo -e "# Copyright (c) Baidu.com, Inc. All Rights Reserved" >> ${script_path}/${filename}
        echo -e "#" >> ${script_path}/${filename}
        echo -e "# @Author : liuyu" >> ${script_path}/${filename}
        echo -e "# @email : [email protected]" >> ${script_path}/${filename}
        echo -e "# @Created Time :  $(date)" >> ${script_path}/${filename}
        echo -e "# @Description : " >> ${script_path}/${filename}
        echo -e "#################################################" >> ${script_path}/${filename}
    fi
}

docker_name="vim_docker_spf"

docker ps | grep ${docker_name} > /dev/null

if [ $? -ne 0 ];then
    docker run -dit \
        --name ${docker_name} \
        -v  /home/baidu:/home/baidu \
        yonidavidson/vim-box-spf13 \
        bash
fi

if [ -d ${script_path}/.$$tmp.sh ];then
    rm ${script_path}/.$$tmp.sh
fi

if [ ! -f ${script_path}/${filename} ];then
    write_header
fi
echo "export LINES=${LINES}" >> ${script_path}/.$$tmp.sh
echo "export COLUMNS=${COLUMNS}" >> ${script_path}/.$$tmp.sh
echo "cd ${script_path} && vim ${filename}" >> ${script_path}/.$$tmp.sh

docker exec -it \
    ${docker_name} \
    bash ${script_path}/.$$tmp.sh
rm  ${script_path}/.$$tmp.sh

 

demo.sh

#################################################
#
# Copyright (c) Baidu.com, Inc. All Rights Reserved
#
# @Author : liuyu
# @email : [email protected]
# @Created Time :  Sun Aug 19 18:35:26 CST 2018
# @Description : 
#
#################################################
    
#!/bin/sh

set -u # use var after define
set -e # exit when cmd fail
set -o pipefail # cmd return fail when one cmd fail in pipe
 
# functions
function err() {
    echo "[ $(date +%Y-%m-%d,%H:%m:%s)  ]: $@" >&2
}

function out() {
    echo "[ $(date +%Y-%m-%d,%H:%m:%s)  ]: $@" >&2
}

function help() {
    echo -e "
    bash start_rosplatform  --AAA
                            --BBB
                            --CCC
                            --DDD
                            --EEE
                            "
}

# input params
    user_cmd="$@"
    AAA="_none"
    BBB="_none"
    CCC="_none"
    DDD="_none"
    EEE="_none"

    while [ $# != 0 ]; do
        case $1 in
            -h) help && exit 0; shift 2;; 
            --help) help && exit 0; shift 2;; 
            --AAA) AAA=$2; shift 2;; 
            --BBB) BBB=$2; shift 2;; 
            --CCC) CCC=$2; shift 2;; 
            --DDD) DDD=$2; shift 2;; 
            --EEE) EEE=$2; shift 2;; 
            *) err "error input_params : $user_cmd " && exit -1;;
        esac
    done
    necessary_params=("" "") 

    for param in ${necessary_params[@]};do
        if [[  ${param} == "_none" ]];then
            help
            err "user cmd : $user_cmd"
            exit -1
        fi
    done
    out "input_params : $user_cmd"

 

docker :yonidavidson/vim-box-spf13

你可能感兴趣的:(杂)