Skip to content

Instantly share code, notes, and snippets.

@mateoppalacios
Last active July 29, 2021 10:37
Show Gist options
  • Save mateoppalacios/e6fc5aa889a36b9777973d9ef8f9d1a5 to your computer and use it in GitHub Desktop.
Save mateoppalacios/e6fc5aa889a36b9777973d9ef8f9d1a5 to your computer and use it in GitHub Desktop.
Simple fetching tool for UNIX like systems, that pipes to cowsay.
#!/bin/sh
# Cowfetch - Simple fetching tool for UNIX like systems, that pipes to cowsay.
# Check if cowsay is installed.
if [ "$(command -v cowsay | wc -l)" = 0 ]; then
printf "cowsay isn't installed.\n"
exit 1
fi
# Get the current username.
get_username () {
printf "%s" "$USER"
}
# Get the release's name.
get_release_name () {
cat /etc/*-release | awk \
'BEGIN { FS = "=" } NR == 1 { gsub("\"", ""); print $2 }'
}
# Get the running kernel version.
get_kernel_version () {
uname -r
}
# Get the system's uptime.
get_memory_usage () {
free -h | awk 'NR == 2 { printf("%s/%s\n", $3, $2) }'
}
# Get the running shell's name.
get_running_shell () {
printf "%s" "$SHELL" | awk 'BEGIN { FS = "/" } { printf $3 }'
}
main () {
# Fetch all the information.
username=$(get_username)
release_name=$(get_release_name)
kernel_version=$(get_kernel_version)
memory=$(get_memory_usage)
running_shell=$(get_running_shell)
# Pretty print the fetched information.
printf "User:\t%s\nOS:\t%s\nKernel:\t%s\nMemory:\t%s\nShell:\t%s" \
"$username" "$release_name" "$kernel_version" "$memory" \
"$running_shell"
}
main | cowsay -n
@monke0192
Copy link

ok

ok

@monke0192
Copy link

ok

ok

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment