Skip to content

Instantly share code, notes, and snippets.

@deanturpin
Last active August 6, 2019 19:11
Show Gist options
  • Save deanturpin/6d7e3b3fa5cdd6e144ddce02af4ca086 to your computer and use it in GitHub Desktop.
Save deanturpin/6d7e3b3fa5cdd6e144ddce02af4ca086 to your computer and use it in GitHub Desktop.
CPU load in your bash prompt - source this script
cpu-status-string(){
# Create some colours
idle="\u001b[32m"
low="\u001b[36m"
medium="\u001b[33m"
high="\u001b[31m"
reset="\u001b[0m"
# Extract CPU info from top
cpu_info=$(top -b -n 1 | grep %Cpu | cut -c9-11 | tr '\n' ' ')
# Create the summary by appending a single character for each CPU
for cpu in $cpu_info; do
if (( $cpu < 25 )); then status_string+="$idle\u28c0"
elif (( $cpu < 50 )); then status_string+="$low\u28e4"
elif (( $cpu < 75 )); then status_string+="$medium\u28f6"
else status_string+="$high\u28ff"
fi
done
# The prompt symbol
cursor="\u2605"
# Print the new prompt
echo -en "$status_string $medium$cursor$reset "
}
PS1='$(cpu-status-string)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment