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.

27 lines
1.3 KiB

6 years ago
  1. #!/bin/bash
  2. ##################################################
  3. # Search package in online repositories
  4. if [ -z "$1" ] ; then
  5. echo "Usage: findpkg <string>"
  6. return 1
  7. else
  8. #
  9. # pacman: find packages which include/refer to user input string $1 by using online repositories. Verbose order
  10. #
  11. # Sort the output:
  12. # 1) sed: remove first 9 lines
  13. # 2) sed: remove everything before the first slash in every other line (package names), including the slash itself
  14. # 3) sed: remove version number strings in every other line (all numbers after the first space after package names
  15. # 4) sed: remove bracket mark ) from every other line
  16. # 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)
  17. # 6) sed: colorize all '[installed]' strings with bold red ( [ \033[1;31m )
  18. # 7) echo: normalize bash text (reset colors with \e[0m)
  19. # NOTE: \e and \033 mean the same thing.
  20. # NOTE: More bash colors here: http://misc.flogisoft.com/bash/tip_colors_and_formatting
  21. #
  22. 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\\]")/''
  23. fi
  24. echo -e '\e[0m'