Skip to content

Instantly share code, notes, and snippets.

@mpan-pl
Created February 9, 2019 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpan-pl/d567cbbc759a7ba1d6cc3a50d5d5926f to your computer and use it in GitHub Desktop.
Save mpan-pl/d567cbbc759a7ba1d6cc3a50d5d5926f to your computer and use it in GitHub Desktop.
lsd bash script, inspired by Aniket-Pradhan/lsd
#!/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