Last active
August 8, 2023 03:13
-
-
Save naranyala/79aa2a676a9292c970344d20274ae071 to your computer and use it in GitHub Desktop.
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
#!/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