Useful CLI tools (bash) for Arch Linux administration
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.

43 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. #!/usr/bin/env bash
  2. #
  3. # findpkg - Search package in official Arch Linux repositories
  4. #
  5. # Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #####################################
  20. if [ -z "$1" ] ; then
  21. echo "Usage: findpkg <string>"
  22. return 1
  23. else
  24. #
  25. # pacman: find packages which include/refer to user input string $1 by using online repositories. Verbose order
  26. #
  27. # Sort the output:
  28. # 1) sed: remove first 9 lines
  29. # 2) sed: remove everything before the first slash in every other line (package names), including the slash itself
  30. # 3) sed: remove version number strings in every other line (all numbers after the first space after package names
  31. # 4) sed: remove bracket mark ) from every other line
  32. # 5) perl: colorize the output: every other line with bold blue ( \033[1:34m ) and the other after that with dim yellow ( \033[0;33m ). Starting from the first output line (sorted by sed in the first step)
  33. # 6) sed: colorize all '[installed]' strings with bold red ( [ \033[1;31m )
  34. # 7) echo: normalize bash text (reset colors with \e[0m)
  35. # NOTE: \e and \033 mean the same thing.
  36. # NOTE: More bash colors here: http://misc.flogisoft.com/bash/tip_colors_and_formatting
  37. #
  38. /usr/bin/pacman -Ssv $1 | sed -e '1,9d' | sed -e '1~2s/^.*\///' -e '1~2s/ .*[0-9]//g' -e '1~2s/)//g' | perl -pe '$_ = "\033[1;34m$_\033[0;33m" if($. % 2)' | sed ''/\\[installed\\]/s//$(printf "\033[1;31m\\[installed\\]")/''
  39. fi
  40. echo -e '\e[0m'