#!/bin/sh
search () {
  shift 
  if command -v pacman &> /dev/null; then
    pacman -Ss $1 || yay -Ss $1
  elif command -v dnf &> /dev/null; then
    dnf search $1
  elif command -v port &> /dev/null; then
    port search $1
  elif command -v portmaster &> /dev/null; then
    cd /usr/ports
    make search name=$1 | grep "^\(Port\|Path\|Info\|Moved\|$\)"
  elif command -v aptitude &> /dev/null; then
    aptitude search $1
  elif command -v apt-cache &> /dev/null; then
    apt-cache search $1
  fi
}

update () {
  shift
  if command -v pacman &> /dev/null; then
    sudo pacman -Sy
  elif command -v dnf &> /dev/null; then
    sudo dnf update
  elif command -v port &> /dev/null; then
    sudo port selfupdate
  elif command -v portsnap &> /dev/null; then
    sudo portsnap fetch && sudo portsnap upgrade
  elif command -v apt-get &> /dev/null; then
    sudo apt-get update
  fi
}

install () {
  shift 
  if command -v pacman &> /dev/null; then
    sudo pacman -S $* || yay -S $*
  elif command -v dnf &> /dev/null; then
    sudo dnf install $*
  elif command -v port &> /dev/null; then
    sudo port install $*
  elif command -v portmaster &> /dev/null; then
    sudo portmaster $*
  elif command -v apt-get &> /dev/null; then
    sudo apt-get install $*
  fi
}

case $1
in
  "i" | "install") 
    install $*;;

  "s" | "search") 
    search $*;;

  "u" | "update") 
    update $*;;
esac

