寫了一個shell腳本,讓終端假裝在寫代碼
準(zhǔn)備工作
- 自己上github找項目,clone下來
- 有個shell,運行腳本,支持文件、文件夾
腳本運行
$ ./imitationGame.sh hello.go
$ ./imitationGame.sh world/
腳本
#!/bin/bash
## 獲得500內(nèi)隨機數(shù)
function rand()
{
num=$RANDOM$RANDOM
((ret=num%500))
echo $ret
}
## 打印文件內(nèi)容
## 空行換行時不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