shell脚本实现交互式的删除git远程仓库已发布的tag的脚本

shell脚本实现交互式的删除git远程仓库已发布的tag的脚本

先上图片

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

再上脚本

#!/bin/bash

function promptbox() {
    # promptbox <title> [<content> [<height> [<width> [<yes_button> [<no_button>]]]]]
    title=$1
    yesno=$2
    height=10
    width=60
    yes_button="Yes"
    no_button="No"
    if [ -n "$3" ]; then
        height=$3
    fi
    if [ -n "$4" ]; then
        width=$4
    fi
    if [ -n "$5" ]; then
        yes_button=$5
    fi
    if [ -n "$6" ]; then
        no_button=$6
    fi

    # 提示框
    # whiptail --title "<dialog box title>" --yesno "<text to show>" <height> <width>
    #!/bin/bash if (whiptail --title "Test Yes/No Box" --yes-button "Skittles" --no-button "M&M's" --yesno "Which do you like better?" 10 60) then echo "You chose Skittles Exit status was $?." else echo "You chose M&M's. Exit status was $?." fi
    whiptail --title "$title" --yes-button "$yes_button" --no-button "$no_button" --yesno "$yesno" $height $width
    ret=$?
    return $ret
}

scriptPath=$(cd $(dirname $0) && pwd)
cd ${scriptPath}

TagSize=$(git tag -l | wc -l)
TagList=`git tag -l | awk '{for(i=1;i<=NF;i++) printf "%s < ",$1 }'`
echo ${TagList}
changeTagCmd="whiptail --title \"删除Tag脚本\" --ok-button \"确定\" --cancel-button \"取消\" --menu \"请选择要删除的tag值:\" 15 120 ${TagSize} ${TagList}"
TAGNAME=$(${changeTagCmd} 3>&1 1>&2 2>&3) 
exitstatus=$? 
if [ $exitstatus = 0 ]; then 
    echo "Your chosen Tag:" $TAGNAME 
else 
    echo "You chose Cancel." 
    exit 0
fi

promptbox "命令执行" "是否执行命令\"git tag -d ${TAGNAME}\"" 10 120 "是" "否"
ret=$?
if [ $ret = 0 ]; then
    echo "开始执行命令:\"git tag -d ${TAGNAME}\""
    git tag -d ${TAGNAME}
else 
    echo "取消执行" 
    exit 0
fi

promptbox "命令执行" "是否执行命令\"git push origin :refs/tags/${TAGNAME}\"" 10 120 "是" "否"
ret=$?
if [ $ret = 0 ]; then
    echo "开始执行命令:\"git push origin :refs/tags/${TAGNAME}\""
    git push origin :refs/tags/${TAGNAME}
else 
    echo "取消执行" 
    exit 0
fi

exit 0

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值