Search Mabox Forum From CLI

Search the Mabox Forum.

With this very simple script it is possible to search the Mabox forum from terminal.

search-mabox-forum.sh

#!/bin/bash

# Array of forums
FORUMS=(
    "Endevouros|https://forum.endeavouros.com"
    "Manjaro|https://forum.manjaro.org"
    "Mabox|https://forum.maboxlinux.org"
    
)

# Set viewer to bat if available, otherwise fallback to cat
if command -v bat &>/dev/null; then
  cat="bat"
else
  cat="cat"
fi

HISTORY_FILE="$HOME/.cache/mabox_forum_search.log"

# Colors
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2)
CYAN=$(tput setaf 6)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
ORANGE=$(tput setaf 208)

show_header() {
  clear
  echo -e "${BOLD}${GREEN}
β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—  β–ˆβ–ˆβ•—
β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•
β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ•”β• 
β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— 
β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•—
β•šβ•β•     β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•β•β•β•β•  β•šβ•β•β•β•β•β• β•šβ•β•  β•šβ•β•
${NORMAL}"
  echo -e "${CYAN}${BOLD}       Mabox|Manjaro Forum Search Tool${NORMAL}\n"
  echo -e "${YELLOW}Usage:${NORMAL}"
  echo -e "  πŸ”  Type search terms and hit Enter"
  echo -e "  ⏹   Use multiple words for better accuracy"
  echo -e "  🧠  Terms are cumulative β€” add more as you go"
  echo -e "  πŸ•˜  Use ${BOLD}--history${NORMAL} to show past searches"
  echo -e "  ⌨️  Press ${BOLD}Ctrl+C${NORMAL} to quit\n"
}

# Show search history
if [[ "$1" == "--history" ]]; then
  echo -e "${YELLOW}πŸ” Search History:${NORMAL}"
  [[ -f "$HISTORY_FILE" ]] && "$cat" "$HISTORY_FILE" || echo "No history yet."
  exit 0
fi

search_terms=""
trap "echo -e '\n${RED}❌ Exiting...${NORMAL}'; exit" INT
show_header

while true; do
    echo -e ""
  echo -e "${CYAN}Current search terms:${NORMAL} ${BOLD}${ORANGE}$search_terms${NORMAL}"
  echo -e "πŸ’‘ Type ${YELLOW}!new${NORMAL} to start a clean search"
  read -rp "${ORANGE}πŸ” Add keyword(s) (or press Enter to repeat): ${NORMAL}" input

  if [[ "$input" == "!new" ]]; then
    search_terms=""
    show_header
    echo -e "${GREEN}πŸ”„ Starting a new search...${NORMAL}\n"
    continue
  fi

  [[ -n "$input" ]] && search_terms="$search_terms $input"
  search_terms="$(echo "$search_terms" | xargs)"  # trim

  if [[ -z "$search_terms" ]]; then
    show_header
    echo -e "${RED}❌ No search terms entered yet.${NORMAL}"
    continue
  fi

  echo "$(date '+%F %T') - $search_terms" >> "$HISTORY_FILE"
  encoded_keyword=$(echo "$search_terms" | sed 's/ /+/g')

  echo -e "\n${CYAN}⏳ Fetching results for: '${search_terms}'...${NORMAL}"

  # Prepare a hit counter summary
  echo -e "\n${BOLD}πŸ“Š Quick summary of hits:${NORMAL}"
  declare -A HITS
  declare -A RESPONSES

  for entry in "${FORUMS[@]}"; do
    NAME="${entry%%|*}"
    URL="${entry##*|}"
    SEARCH_URL="$URL/search.json"

    response=$(curl -s "${SEARCH_URL}?q=${encoded_keyword}")
    RESPONSES["$NAME"]="$response"

    if [[ -z "$response" || "$response" == "null" ]]; then
      echo -e "${RED}⚠️  $NAME: Error fetching data.${NORMAL}"
      continue
    fi

    hits=$(echo "$response" | jq '.topics | length')
    HITS["$NAME"]=$hits
    echo -e "${YELLOW}- $NAME:${NORMAL} ${GREEN}${hits} result(s)${NORMAL}"
  done

  # Show detailed results
  for entry in "${FORUMS[@]}"; do
    NAME="${entry%%|*}"
    URL="${entry##*|}"
    hits="${HITS[$NAME]}"
    response="${RESPONSES[$NAME]}"

    echo -e "\n${CYAN}πŸ” $NAME forum (${hits} result(s)):${NORMAL}"

    if [[ "$hits" -eq 0 || "$hits" == "null" ]]; then
      echo -e "${YELLOW}ℹ️ No results found.${NORMAL}"
      continue
    fi

    echo "$response" | jq -r --arg BASE "$URL" '
  .topics[] |
  {
    title: .title,
    link: ($BASE + "/t/" + .slug + "/" + (.id|tostring)),
    created: (.created_at | split("T") | join(" ") | sub("Z$"; ""))
  } |
  [.title, .link, .created] |
  @tsv
' | while IFS=$'\t' read -r title link created; do
  # Conditional coloring based on forum name
  if [[ "$NAME" == "Mabox" ]]; then
    LINK_COLOR="${GREEN}"
  elif [[ "$NAME" == "Manjaro" ]]; then
    LINK_COLOR="${BLUE}"
    elif [[ "$NAME" == "Endevouros" ]]; then
    LINK_COLOR="${ORANGE}"
  fi

  echo -e "\n${RED}β€’${YELLOW} ${BOLD}${title}${NORMAL}"
  echo -e "  ${LINK_COLOR}${link}${NORMAL}"
  echo -e "  Created at: $created"
        done
    done
done


How to see search history.

$ search-mabox-forum.sh --history

:bird:

2 Likes

UPDATE:

  • added history search
  • and better search handling
  • update preview
$ search-mabox-forum.sh --history

:bird:

1 Like

Update: See Usage…

:bird:

1 Like

It looks great.
When I see these scripts, I always wonder where to save them.
Is it a good idea to have a folder like β€œMy Scripts” for everything that isn’t part of the system itself?
If so, is it better to save it directly in /home or as a subfolder somewhere else?

New update: Non functional parts. Fine tune messages with MABOX ascii.

Just put it in ~/bin.

But it is a good start to run the script first from a myscripts dir to test the script.
When you think you can use it put in the home bin.

:bird:

1 Like

Update:

  • added creation date to the list.

:bird:

Thank you very much, but unfortunately, since I’m unable to resolve the issues I’m having with Mabox, I’ve decided to abandon the distro.
I can’t find answers to my questions, so I can’t resolve them.
Wish you success.

Update:

  • added manjaro forum for hits.
  • coloring URL mabox(green), manjaro(blue).

:bird:

Update:

  • Set viewer to bat if available, otherwise fallback to cat.
  • Coloring.
  • Order of output first Manjaro | Mabox topics.
    For quicker acces of Mabox topics.

Search Mabox From Cli…Script

:bird:

Update:

  • added Endevouros forum to the hits.
  • coloring
  • green mabox
  • blue manjaro
  • orange endevouros

:bird: