Skip to content

Commit

Permalink
Merge pull request #154 from icy/issue-143-add-quiet-option
Browse files Browse the repository at this point in the history
Fix #96, #143: Qs/q for yum, apk, dpkg
  • Loading branch information
icy authored Jun 18, 2021
2 parents 16c31ca + a9156a1 commit c309417
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## next

* `lib/yum`, `lib/dpkg`, `lib/apk`: Fix #96, #143
by adding `-q` (quiet) option for `Qs`.
* `lib/apk`: `Q` prints version information.

## v2.4.4

* `lib/dnf`: Minor improvements (#148)
Expand Down
8 changes: 8 additions & 0 deletions lib/00_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,11 @@ _print_supported_operations() {
done
echo
}

_quiet_field1() {
if [[ "${_TOPT}" == "" ]]; then
cat
else
awk '{print $1}'
fi
}
2 changes: 1 addition & 1 deletion lib/00_external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _PACMAN_found_from_script_name() {
_tmp_name="${_tmp_name%.*}" # remove extension if any (remove everything from the last `.`)
_pacman="${_tmp_name##*-}" # remove every thing before the last `-`

if grep -Eq -e ":$_pacman[[:space:]]*" <<< "$_SUPPORTED_EXTERNALS"; then
if grep -Eq -e ":${_pacman}[[:space:]]*" <<< "$_SUPPORTED_EXTERNALS"; then
export _PACMAN="$_pacman"
return 0
else
Expand Down
20 changes: 14 additions & 6 deletions lib/apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,35 @@ _apk_init() {

# apk_Q may _not_implemented
apk_Q() {
if [[ -z "$_TOPT" ]]; then
case "$_TOPT" in
"")
apk info --all $(apk info -dws) \
| grep 'installed size' \
| awk '{ print $1}'
;;
"q")
apk info
else
;;
*)
_not_implemented
fi
;;
esac
}

apk_Qi() {
apk info -a -- "$@"
apk info --all -- "$@"
}

apk_Ql() {
apk info -L -- "$@"
apk info --contents -- "$@"
}

apk_Qo() {
apk info --who-owns -- "$@"
}

apk_Qs() {
apk info -- "*${*}*"
apk_Q | grep -Ee ".*${*}.*"
}

apk_Qu() {
Expand Down
3 changes: 2 additions & 1 deletion lib/dpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ dpkg_Qs() {
dpkg-query -W -f='${Status} ${Package}\t${Version}\t${Description}\n' \
| grep -E '^((hold)|(install)|(deinstall))' \
| sed -r -e 's#^(\w+ ){3}##g' \
| grep -Ei "${@:-.}"
| grep -Ei "${@:-.}" \
| _quiet_field1
}

# dpkg_Rs may _not_implemented
Expand Down
8 changes: 7 additions & 1 deletion lib/yum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ yum_Qi() {
}

yum_Qs() {
rpm -qa "*${*}*"
if [[ "$_TOPT" == "q" ]]; then
rpm -qa --qf "%{NAME}\\n" "*${*}*"
elif [[ "$_TOPT" == "" ]]; then
rpm -qa --qf "%{NAME} %{VERSION}\\n" "*${*}*"
else
_not_implemented
fi
}

yum_Ql() {
Expand Down

0 comments on commit c309417

Please sign in to comment.