If you find yourself in a hole, stop digging, Will Rogers
This is the second article, you may want to read the first one, Proxmox VM Arch Linux Hyprland. Get information from Ollama, tldr, myripgrep
ddgr is a command-line interface specifically for DuckDuckGo. It allows you to search DuckDuckGo directly from the terminal and view results in a clean, readable format.
TLDR (Too Long; Didn't Read) is a community-driven project that provides simplified and practical examples for command-line tools. It’s a great resource for quickly understanding how to use various commands without diving into the full man pages, which can be tiredsome, boring, and even overwhelming
ShellGPT is a command-line productivity tool powered by AI large language models (LLM). This command-line tool offers streamlined generation of shell commands, code snippets, documentation, eliminating the need for external resources (like Google search). However, like many evolving projects, they do have plenty of updates and new features, but also a few bugs to iron out. Development can be a wild ride!
man pages—abbreviation (man-db package) for “manual pages”—are the form of documentation that is available on almost all UNIX-like operating systems, including Arch Linux.
❯ pacman -S ddgr tldr man-db bat surfraw
# If you find the error: Error fetching from tldr:
# 1. ping www.google.com, 2. Temporary disable your firewall, sudo ufw disable. 3. Cache issues: rm -rf ~/.cache/tldr.
# getinfo.sh, script to search information in a VM
# Use: sh ./getinfo.sh "What is the capital of France?"
#!/bin/bash
REMOTE_USER="nmaximo7"
REMOTE_HOST="192.168.1.106" # Replace by your IP
if [ -z "$1" ]; then
echo "Usage: $0 "
exit 1
fi
question="$1"
# Check for "tldr" in the question
if echo "$question" | grep -qi 'tldr'; then
echo "Query tldr"
# Remove the word "tldr" and extra spaces from the question
cleaned_question=$(echo "$question" | sed -e 's/tldr//gi' -e 's/ */ /g' -e 's/^ *//' -e 's/ *$//')
echo "Cleaned question: $cleaned_question"
ssh -t "$REMOTE_USER@$REMOTE_HOST" "tldr '$cleaned_question'"
fi
# Query Ollama remotely
echo "Querying Ollama..."
ssh -t "$REMOTE_USER@$REMOTE_HOST" "echo '$question' | ollama run qwen2.5"
# Query ddgr remotely
echo "Searching with ddgr..."
ssh -t "$REMOTE_USER@$REMOTE_HOST" "ddgr -n 3 --np '$question'"
The script greets the user and processes a question passed as an argument.
It checks if the question pertains to:
It also queries Ollama, utilizes ddgr for search results, less (a pager for viewing long outputs) and bat (a cat clone with syntax highlighting).
#!/bin/bash
# __ _ _ ___ __
#( )( \( )( _) / \
# )( ) ( ) _)( () )
#(__)(_)\_)(_) \__/
#
# Help message function
show_help() {
echo "Usage: $0 [QUESTION]"
echo
echo "This script assists in querying various resources based on the provided question."
echo
echo "You can ask questions related to:"
echo "1. Manual pages (man): Use the word 'man' followed by the command."
echo " Example: $0 'man ls'"
echo
echo "2. Cheat sheets (cheat.sh): Use 'cheat.sh' followed by the command."
echo " Example: $0 'cheat.sh tar'"
echo
echo "3. TLDR pages: Use 'tldr' followed by the command."
echo " Example: $0 'tldr git'"
echo
echo "4. General queries: Any other question will be processed with Ollama and ddgr."
echo " Example: $0 'How to install Python?'"
echo
echo "Ensure you have the necessary permissions and the remote server is accessible."
echo "You must have the following tools installed: cowsay, ssh, rg, curl, tldr, and ddgr."
echo
echo "For more information, refer to the specific command's documentation."
exit 1
}
# Display help if no arguments are provided
if [ $# -eq 0 ]; then
show_help
fi
REMOTE_USER="nmaximo7"
REMOTE_HOST="192.168.1.106"
cowsay "Welcome, $(whoami)!"
question="$1"
# Function to clean the question by removing specified keywords
clean_question() {
local input_question="$1"
echo "$input_question" | sed -e 's/man//gi' -e 's/tldr//gi' -e 's/cheat.sh//gi' -e 's/ */ /g' -e 's/^ *//' -e 's/ *$//'
}
# Function to colorize output
colorize() {
local color="$1"
local text="$2"
case $color in
red) echo -e "\033[31m$text\033[0m" ;;
green) echo -e "\033[32m$text\033[0m" ;;
yellow) echo -e "\033[33m$text\033[0m" ;;
blue) echo -e "\033[34m$text\033[0m" ;;
*) echo "$text" ;;
esac
}
# Check for "man" in the question
if echo "$question" | grep -qi 'man'; then
echo "$(colorize blue "Querying manual pages...")"
# Clean the question
cleaned_question=$(clean_question "$question")
echo "Cleaned question: $cleaned_question"
ssh -t "$REMOTE_USER@$REMOTE_HOST" "man '$cleaned_question'"
rg "$cleaned_question" ~/justtothepoint/content/
rg "$cleaned_question" ~/dotfiles/
rg "$cleaned_question" ~/myNewPython/
fi
# Check for "cheat.sh" in the question
if echo "$question" | grep -qi 'cheat.sh'; then
echo "$(colorize green "Querying cheat.sh...")"
# Clean the question
cleaned_question=$(clean_question "$question")
echo "Cleaned question: $cleaned_question"
encoded_question=$(echo "$cleaned_question" | sed 's/ /%20/g')
ssh -t "$REMOTE_USER@$REMOTE_HOST" "curl -s 'cheat.sh/$encoded_question' | less -R"
rg "$encoded_question" ~/justtothepoint/content/ | bat --paging=always
rg "$encoded_question" ~/dotfiles/ | bat --paging=always
rg "$encoded_question" ~/myNewPython/ | bat --paging=always
fi
# Check for "tldr" in the question
if echo "$question" | grep -qi 'tldr'; then
echo "$(colorize yellow "Querying tldr...")"
# Clean the question
cleaned_question=$(clean_question "$question")
echo "Cleaned question: $cleaned_question"
ssh -t "$REMOTE_USER@$REMOTE_HOST" "tldr '$cleaned_question' | less -R"
rg "$cleaned_question" ~/justtothepoint/content/ | bat --paging=always
rg "$cleaned_question" ~/dotfiles/ | bat --paging=always
rg "$cleaned_question" ~/myNewPython/ | bat --paging=always
fi
# Clean the question for Ollama query
ollama_question=$(clean_question "$question")
# Query Ollama remotely with the cleaned question
echo "$(colorize blue "Querying Ollama...")"
ssh -t "$REMOTE_USER@$REMOTE_HOST" "echo '$ollama_question' | ollama run qwen2.5"
# Search for the cleaned question in local directories using ripgrep
rg "$ollama_question" ~/justtothepoint/content/
rg "$ollama_question" ~/dotfiles/
rg "$ollama_question" ~/myNewPython/
# Query ddgr remotely
echo "$(colorize green "Searching with ddgr...")"
ssh -t "$REMOTE_USER@$REMOTE_HOST" "ddgr -n 3 --np '$ollama_question' | less -R"
# The following lines are commented out; they can be used to open search results in Firefox
# echo "Opening search results in Firefox..."
# firefox -new-tab "https://www.google.com/search?q=$question"
# firefox -new-tab "https://www.bing.com/search?q=$question"
# firefox -new-tab "https://copilot.microsoft.com/?q=$question"
# Alternative method using surfraw to search with Google and Bing in new Firefox tabs
# nix-shell --run "surfraw -browser='firefox -new-tab' google $1 && surfraw -browser='firefox -new-tab' bing $1"
# Check if the Ollama Docker container is running; if not, run it
# Otherwise, run the command in the Ollama container
# docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
# docker exec -t ollama ollama run llama3.3 "$question"