You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pkgrm 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env bash
  2. declare by_size
  3. has() {
  4. local verbose=0
  5. if [[ $1 = '-v' ]]; then
  6. verbose=1
  7. shift
  8. fi
  9. for c; do c="${c%% *}"
  10. if ! command -v "$c" &> /dev/null; then
  11. (( "$verbose" > 0 )) && err "$c not found"
  12. return 1
  13. fi
  14. done
  15. }
  16. err() {
  17. printf "\e[31m%s\e[0m\n" "$*" >&2
  18. }
  19. die() {
  20. (( $# > 0 )) && err "$*"
  21. exit 1
  22. }
  23. select_from() {
  24. local o c cmd OPTARG OPTIND
  25. cmd='command -v'
  26. while getopts 'c:' o; do
  27. case "$o" in
  28. c) cmd="$OPTARG" ;;
  29. esac
  30. done
  31. shift "$((OPTIND-1))"
  32. for c; do
  33. if $cmd "${c%% *}" &> /dev/null; then
  34. echo "$c"
  35. return 0
  36. fi
  37. done
  38. return 1
  39. }
  40. has -v fzf expac || die
  41. fzf() {
  42. command fzf -e --multi --no-hscroll --inline-info --cycle --bind='Ctrl-a:toggle-all' "$@"
  43. }
  44. case $1 in
  45. -s|--size) by_size=1; shift;
  46. esac
  47. if (( $# > 0 )); then
  48. sudo pacman -Rcusn "$@"
  49. exit
  50. fi
  51. preview=$(select_from pacaur pacman)
  52. if (( by_size )); then
  53. mapfile -t pkgs < <(expac -H M '%m\t%n' | sort -hr | fzf +s --preview="$preview --color=always -Si {3}" -q '!^lib ' | cut -f2)
  54. else
  55. mapfile -t pkgs < <(expac '%n' | fzf +s --preview="$preview --color=always -Si {1}" -q '!^lib ' | cut -d' ' -f1)
  56. fi
  57. (( ${#pkgs[@]} > 0 )) && sudo pacman -Rcusn "${pkgs[@]}"