程序员

shell花活-摸鱼神器-2023-01-18

2023-01-17  本文已影响0人  貓叔

写了一个shell脚本,让终端假装在写代码

准备工作

脚本运行

$ ./imitationGame.sh  hello.go
$ ./imitationGame.sh  world/

脚本

#!/bin/bash

## 获得500内随机数
function rand()
{
        num=$RANDOM$RANDOM
        ((ret=num%500))
        echo $ret
}

## 打印文件内容
## 空行换行时不sleep,非空行换行sleep 1.x秒
## 空字符不sleep,非空字符sleep 0.x秒
function echoFile() {
        inputFile=$(realpath $1)
        for lineCount in `seq 1 $(wc -l $inputFile | awk '{print $1}')`;do
                line=`head -n $lineCount $inputFile | tail -n 1`

                ## NOT empty line
                if echo $line | grep -v ^$ &>/dev/null; then
                        sleep 1.$(rand)
                fi
                for num in `seq 1 $(echo -n "$line" | wc -c )`;do
                        character=`echo "$line" | cut -c $num`
                        if ! [ -z "$character" ];then
                                sleep 0.$(echo $RANDOM)
                        fi
                        #printf "%s" "$character"
                        echo -n -e "\e[32m`printf "%s" "$character"`"
                done
                echo
        done
}

## 启动时清屏
clear

input=$(realpath $1)

if [ -d $input ];then
        for file in `find $input -type f`;do
                echoFile $file
        done
else
        echoFile $input
fi
上一篇 下一篇

猜你喜欢

热点阅读