终端下来自FBI的问候

先上效果图

在猥琐同学的启发下,打算把爱情动作大片的片头放到终端的字符界面下,233,便简单写了一个bash脚本,放到~/.zshrc里面便可,每次打开终端都会显示出来一个FBI WARNING,哈哈。

附上代码

    function bash_center_print {
        strlen=${#1}
        blanklen=$(((COLUMNS - strlen) / 2))
        echo "$(tput cuf $blanklen) $1"
    }

    function bash_center_print_red {
        strlen=${#1}
        blanklen=$(((COLUMNS - strlen) / 2))
        echo "$(tput cuf $blanklen) $(tput setab 1)$1$(tput sgr 0)"
    }

    bash_center_print_red "FBI WARNING"
    echo ""
    bash_center_print "Federal Law provides severe civil and criminal penalties for "
    bash_center_print "the unauthorized reproduction, distribution, or exhibition of"
    bash_center_print "copyrighted motion pictures (Title 17, United States Code,   "
    bash_center_print "Sections 501 and 508). The Federal Bureau of Investigation   "
    bash_center_print "investigates allegations of criminal copyright infringement  "
    bash_center_print "(Title 17, United States Code, Section 506)."

END

其中用COLUMNS来获取到字符终端的宽度,计算一下居中的留白部分长度,用tput cuf来实现居中,关于FBI WARNING那一行用红色背景打印用到了tput setab来设置了背景色。

Github https://github.com/zhaohui8969/FBI_WARNING