Pieds-Nus_custom-scripts/wrapter

38 lines
1.1 KiB
Bash

#!/bin/bash
# A wrapper for apt[itutde]
# searches the repos for your query before trying to do the action.
# Install : # apt install aptitude dmenu ; cp wrapter /usr/local/bin/wrapter ; cd /usr/local/bin/ ; chmod +x wrapter ; for link in Install Isntall Show Remove Why ; do ln -s wrapter $link ; done
action="$(basename "${0}")"
test "${action}" = wrapter && action="$(dmenu <<< "\
install
show
remove
why\
")"
case "${action}" in
*[iI][ns][ns]tall* )
action=install
sudo="sudo ";;
*[sS]how* )
action=show;;
*[Rr]emove* | *purge* )
action=purge
sudo="sudo ";;
*[wW]hy* )
action=why;;
* )
exit 1;;
esac
pkgs="$(aptitude search $@ | grep -v ":i386" )"
test -z "${pkgs}" && echo "No pkgs found matching $@." && exit 2
nb="$(wc -l <<< "${pkgs}")"
test "${nb}" -gt 1 && echo "$nb packages found." && pkgs="$(echo -e "${pkgs}" | dmenu)"
test "$(wc -l <<< "${pkgs}")" -eq 1 && pkgs="$(tr -s " " <<< "${pkgs}" | cut -d " " -f 2)" && echo -e "Package was found: ${action}ing ${pkgs}\n\$ ${sudo}aptitude ${action} ${pkgs}" && ${sudo}aptitude ${action} "${pkgs}"