Created
February 9, 2019 04:07
-
-
Save mpan-pl/d567cbbc759a7ba1d6cc3a50d5d5926f to your computer and use it in GitHub Desktop.
lsd bash script, inspired by Aniket-Pradhan/lsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright © 2019 mpan; <https://mpan.pl/>; CC0 1.0 (THIS FILE!) | |
declare -ri rows="$(tput lines)" | |
declare -ri columns="$(tput cols)" | |
declare -ra codes=( | |
"$(tput setab 0) " | |
"$(tput setab 1) " | |
"$(tput setab 2) " | |
"$(tput setab 3) " | |
"$(tput setab 4) " | |
"$(tput setab 5) " | |
"$(tput setab 6) " | |
"$(tput setab 7) " | |
"$(tput setab 8) " | |
"$(tput setab 9) " | |
"$(tput setab 10) " | |
"$(tput setab 11) " | |
"$(tput setab 12) " | |
"$(tput setab 13) " | |
"$(tput setab 14) " | |
"$(tput setab 15) " | |
) | |
rowFormat='' | |
for ((iColumn = 0; iColumn < columns; ++iColumn)); do | |
rowFormat+='%s' | |
done | |
format='' | |
for ((iRow = 0; iRow < rows - 1; ++iRow)); do | |
format+="$rowFormat" | |
format+=$'\n' | |
done | |
format+="$rowFormat" | |
declare -r format | |
declare -a screen | |
for ((iRow = 0; iRow < rows; ++iRow)); do | |
for ((iColumn = 0; iColumn < columns; ++iColumn)); do | |
screen+=("${codes[0]}") | |
done | |
done | |
while true; do | |
tput cup 0,0 | |
for ((iRow = 0; iRow < rows; ++iRow )); do | |
for ((iColumn = 0; iColumn < columns; ++iColumn)); do | |
color=$(( RANDOM % "${#codes[@]}" )) | |
screen["$((iRow * columns + iColumn))"]="${codes[$color]}" | |
done | |
done | |
printf "$format" "${screen[@]}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment