Skip to content

Instantly share code, notes, and snippets.

@naranyala
Last active August 8, 2023 03:13
Show Gist options
  • Save naranyala/79aa2a676a9292c970344d20274ae071 to your computer and use it in GitHub Desktop.
Save naranyala/79aa2a676a9292c970344d20274ae071 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ENHANCED CHEATSHEETS (github.com/naranyala)
####################################
# combining: curl, cht.sh, and bat #
####################################
# Check if the query is provided as the first command-line argument
if [[ -n "$1" ]]; then
query="$1"
else
# Prompt the user for the query
read -p "Enter the query: " query
fi
# Validate if the query is provided
if [[ -z "$query" ]]; then
echo "Please provide a query."
exit 1
fi
# Make the cht.sh API request using curl and capture the output
result=$(curl -s "https://cht.sh/$query")
# Colorize and display the result using bat
echo "$result" | bat --theme="TwoDark"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment