No Description
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.

pkgup 996B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. has() {
  3. local verbose=0
  4. if [[ $1 = '-v' ]]; then
  5. verbose=1
  6. shift
  7. fi
  8. for c; do c="${c%% *}"
  9. if ! command -v "$c" &> /dev/null; then
  10. (( "$verbose" > 0 )) && err "$c not found"
  11. return 1
  12. fi
  13. done
  14. }
  15. err() {
  16. printf "\e[31m%s\e[0m\n" "$*" >&2
  17. }
  18. die() {
  19. (( $# > 0 )) && err "$*"
  20. exit 1
  21. }
  22. select_from() {
  23. local cmd='command -v'
  24. for a; do
  25. case "$a" in
  26. -c)
  27. cmd="$2"
  28. shift 2
  29. ;;
  30. esac
  31. done
  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 || die
  41. helper=$(select_from pacaur trizen packer apacman pacman)
  42. mapfile -t pkgs < <(
  43. $helper -Qu --color=always |
  44. fzf --ansi -e -m --inline-info --cycle --reverse --bind='Ctrl-A:toggle-all' |
  45. awk '{print $3}'
  46. )
  47. count="${#pkgs[@]} package"
  48. (( ${#pkgs[@]} > 1 )) && count+='s'
  49. printf "upgrading %s: %s\n" "$count" "${pkgs[*]}"
  50. (( ${#pkgs[@]} > 0 )) && $helper -S "${pkgs[@]}"