diff --git a/.scripts/pacman-diff b/.scripts/pacman-diff index 91e06800..d1cb837e 100755 --- a/.scripts/pacman-diff +++ b/.scripts/pacman-diff @@ -1,5 +1,4 @@ #!/bin/sh -[ -z "$(command -v pacman)" ] && echo "You need pacman to run this script." && exit 1 _printhelp() { @@ -22,27 +21,21 @@ OPTION_LOCAL="-1" while getopts ":hmqe" opt; do case $opt in e) - OPTION_EXPLICIT="e" - ;; + OPTION_EXPLICIT="e" ;; h) _printhelp "$0" - exit 1 - ;; + exit 1 ;; m) - OPTION_FOREIGN="m" - ;; + OPTION_FOREIGN="m" ;; q) - OPTION_LOCAL="-2" - ;; + OPTION_LOCAL="-2" ;; ?) _printhelp "$0" - exit 1 - ;; + exit 1 ;; :) echo "Missing argument." _printhelp "$0" - exit 1 - ;; + exit 1 ;; esac done @@ -54,6 +47,8 @@ if [ $# -eq 0 ]; then exit 1 fi +[ -z "$(command -v pacman)" ] && echo "You need pacman to run this script." && exit 1 + PKGLIST="$(mktemp)" FILE="$(mktemp)" pacman -Qq${OPTION_FOREIGN}${OPTION_EXPLICIT} | sort > "$PKGLIST" diff --git a/.scripts/pacman-files b/.scripts/pacman-files index 96c0f1c4..f60a4390 100755 --- a/.scripts/pacman-files +++ b/.scripts/pacman-files @@ -1,5 +1,4 @@ #!/bin/sh -[ -z "$(command -v pacman)" ] && echo "You need pacman to run this script." && exit 1 _printhelp() { @@ -10,6 +9,7 @@ Display size of files in PACKAGES. -h: Display this help. -n: Sort by size. + EOF } @@ -19,20 +19,16 @@ while getopts ":hn" opt; do case $opt in h) _printhelp "$0" - exit 1 - ;; + exit 1 ;; n) - OPTION_SORT="sort -h" - ;; + OPTION_SORT="sort -h" ;; ?) _printhelp "$0" - exit 1 - ;; + exit 1 ;; :) echo "Missing argument." _printhelp "$0" - exit 1 - ;; + exit 1 ;; esac done @@ -44,4 +40,6 @@ if [ $# -eq 0 ]; then exit 1 fi +[ -z "$(command -v pacman)" ] && echo "You need pacman to run this script." && exit 1 + du -bch $(pacman -Qlq "$@" | grep -v ".*/$" | sort -u) 2>/dev/null | eval ${OPTION_SORT} diff --git a/.scripts/pacman-size b/.scripts/pacman-size index 30d12c7e..defefab9 100755 --- a/.scripts/pacman-size +++ b/.scripts/pacman-size @@ -1,9 +1,4 @@ #!/bin/sh -if [ -f "${0%/*}/.pacman-init" ];then - . "${0%/*}/.pacman-init" -else - echo "Missing init file" && exit 1 -fi _printhelp() { @@ -16,7 +11,6 @@ default. -h: Show this help. -n: Output is sorted by size. - -q: Uses installed packages database instead of repos database. It speeds up queries and allows displaying size of local packages not available in repos. @@ -34,23 +28,18 @@ while getopts ":hnq" opt; do case $opt in h) _printhelp "$0" - exit 1 - ;; + exit 1 ;; n) - SORT_SIZE="sort -n" - ;; + SORT_SIZE="sort -n" ;; q) - CMD="pacman -Qi" - ;; + CMD="pacman -Qi" ;; ?) _printhelp "$0" - exit 1 - ;; + exit 1 ;; :) echo "Missing argument." _printhelp "$0" - exit 1 - ;; + exit 1 ;; esac done @@ -62,6 +51,12 @@ if [ $# -eq 0 ]; then exit 1 fi +if [ -f "${0%/*}/.pacman-init" ];then + . "${0%/*}/.pacman-init" +else + echo "Missing init file" && exit 1 +fi + ## We use external variable for awk to fit current locales. RESULT="$(eval "${CMD} $@" 2>/dev/null | awk -F "$SEP" -v filter="$pacman_size" -v pkg="$pacman_name" \ '$0 ~ pkg {pkgname=$2} $0 ~ filter {gsub(/\..*/,"") ; printf("%6s KiB %s\n", $2, pkgname)}' | eval "$SORT" | eval "$SORT_SIZE")" @@ -71,6 +66,7 @@ echo "$RESULT" ## Print total size. echo "$RESULT" | awk '{TOTAL=$1+TOTAL} END {printf("Total: %d KiB\n",TOTAL)}' + ## One line version. Approximately same performance. Note the combination of ## 'tee' and >(awk ...) to write the detailed list to standard output and to ## pass it to awk.