Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created November 8, 2023 08:02
Show Gist options
  • Save naranyala/4f28148461392e9e8534549917ad7c89 to your computer and use it in GitHub Desktop.
Save naranyala/4f28148461392e9e8534549917ad7c89 to your computer and use it in GitHub Desktop.
#!/bin/bash
DEFAULT_TERMINAL="kitty"
# Function to display error messages
display_error() {
notify-send "Error" "$1" --icon=dialog-error
}
search_query=$(rofi -dmenu -p "MAN Search: ")
if [ -n "$search_query" ]; then
# Temporarily redirect stderr to /dev/null to prevent system error messages
# We'll handle errors manually instead
if ! man -w "$search_query" &>/dev/null; then
# If man returns a non-zero exit status, the page doesn't exist
display_error "No manual entry for $search_query"
else
# If man returns success (0 exit status), display the page
notify-send "Search for $search_query ..."
# It's a good idea to use 'sh -c' to ensure the entire command is executed in the shell
"$DEFAULT_TERMINAL" sh -c "man '$search_query' || read -p 'Press enter to continue...'"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment