#!/usr/bin/env bash if test -t 1; then # see if it supports colors... ncolors=$(tput colors) if test -n "$ncolors" && test $ncolors -ge 8; then bold="$(tput bold)" underline="$(tput smul)" standout="$(tput smso)" normal="$(tput sgr0)" black="$(tput setaf 0)" red="$(tput setaf 1)" green="$(tput setaf 2)" yellow="$(tput setaf 3)" blue="$(tput setaf 4)" magenta="$(tput setaf 5)" cyan="$(tput setaf 6)" white="$(tput setaf 7)" fi fi REMOVE=false CLEAR_CACHE=false for arg in "$@"; do shift case "$arg" in "--remove") set -- "$@" "-r" ;; "--clear-cache") set -- "$@" "-c" ;; "--help") set -- "$@" "-h" ;; "--"*) echo "Invalid Option: ${arg}" ; exit 1 ;; *) set -- "$@" "$arg" esac done shift $((OPTIND -1)) while getopts ":rch" opt; do case $opt in r ) REMOVE=true ;; c ) CLEAR_CACHE=true ;; h ) echo "Usage: haur [--remove | -r] | [--clear-cache | -c] " exit 0 ;; \?) echo "${red}Invalid Option: -$OPTARG${normal}" 1>&2 exit 1 ;; esac done shift $((OPTIND -1)) if [ $REMOVE == true ]; then for PACKAGE_NAME in "$@"; do echo "${blue}Removing $PACKAGE_NAME...${normal}" sudo pacman -Rns $PACKAGE_NAME echo $PACKAGE_NAME > ~/.haur_cache done if [ $CLEAR_CACHE == true ]; then if test -f "$HOME/.haur_cache"; then echo "${blue}Clearing cache...${normal}" while IFS= read -r line || [[ -n "$line" ]]; do echo "${blue}Removing $line${normal}" rm -rf $HOME/.haur/$line done < "$HOME/.haur_cache" rm ~/.haur_cache else echo "${blue}Nothing to clear${normal}" fi fi else if [ $CLEAR_CACHE == true ]; then if test -f "$HOME/.haur_cache"; then echo "${blue}Clearing cache...${normal}" while IFS= read -r line || [[ -n "$line" ]]; do echo "${blue}Removing $line${normal}" rm -rf $HOME/.haur/$line done < "$HOME/.haur_cache" rm ~/.haur_cache else echo "${blue}Nothing to clear${normal}" fi fi for PACKAGE_NAME in "$@"; do echo "${blue}Installing $PACKAGE_NAME...${normal}" mkdir -p ~/.haur cd ~/.haur git clone https://aur.archlinux.org/$PACKAGE_NAME.git cd $PACKAGE_NAME makepkg -si done fi