Last active
August 22, 2019 15:00
-
-
Save elementbound/75520478848ff4007b8d4886a56c9b50 to your computer and use it in GitHub Desktop.
Bashrc loader
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
# Spinners | |
# https://stackoverflow.com/questions/2685435/cooler-ascii-spinners | |
# "← ↖ ↑ ↗ → ↘ ↓ ↙" | |
# "▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▁" | |
# "▉▊▋▌▍▎▏▎▍▌▋▊▉" | |
# "▖▘▝▗" | |
# "┤┘┴└ ├ ┌ ┬ ┐" | |
# "◢◣◤◥" | |
# "◰◳◲◱" | |
# "◴◷◶◵" | |
# "◐◓◑◒" | |
# "◡◡⊙⊙◠◠" | |
# "⣾⣽⣻⢿⡿⣟⣯⣷ ⠁⠂⠄⡀⢀⠠⠐⠈" | |
declare -a spinner=("◴" "◷" "◶" "◵") | |
spinner_length=${#spinner[@]} | |
filename_length=0 | |
index=0 | |
width=$(tput cols) | |
declare -a load_times; | |
declare -a load_scripts; | |
while read -r initsh; do | |
# Clear line | |
printf "\r" | |
printf " %.0s" $(seq 2 $width) | |
# Print spinner | |
spinner_index=$[index % spinner_length] | |
printf "\r\e[1m[\e[36m ${spinner[$spinner_index]} \e[0m\e[1m]\e[0m $initsh" | |
index=$[$index + 1] | |
start=$(date +%s%N) | |
. "$initsh" | |
end=$(date +%s%N) | |
load_times[$[index]]="$[end - start]" | |
load_scripts[$[index]]="$initsh" | |
# Keep track of longest filename | |
if (( ${#initsh} > filename_length )); then | |
filename_length=${#initsh} | |
fi; | |
done <<< $(find ~/.bash/init/ -name "*.sh"); | |
clear | |
# Print report | |
printf "\e[1mInit times:\e[0m\n" | |
for i in $(seq 1 $index); do | |
load_script="${load_scripts[$i]}" | |
load_time="${load_times[$i]}" | |
load_time=$[load_time / 1000000] | |
load_color="\e[32m" # Green | |
if (( load_time > 100 )); then | |
load_color="\e[33m" # Yellow | |
fi | |
if (( load_time > 200 )); then | |
load_color="\e[31m" # Red | |
fi | |
printf " [${load_color}%-${filename_length}s\e[0m] $load_color $load_time ms\e[0m\n" "$load_script" | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment