From bec22fcd4121ce7b60d1a7a6573d15c7658c6594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Sk=C3=B6ld?= Date: Tue, 28 Sep 2021 23:09:02 +0200 Subject: [PATCH] Print the target arch when using the %a format specifier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the %a format specifier to allow printing of a target's arch when using --print-format. Signed-off-by: Jonathan Sköld --- doc/pacman.8.asciidoc | 5 +++-- src/pacman/util.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc index bb205627..785844ce 100644 --- a/doc/pacman.8.asciidoc +++ b/doc/pacman.8.asciidoc @@ -235,8 +235,9 @@ Transaction Options (apply to '-S', '-R' and '-U') *\--print-format* :: Specify a printf-like format to control the output of the '\--print' - operation. The possible attributes are: "%n" for pkgname, "%v" for pkgver, - "%l" for location, "%r" for repository, and "%s" for size. Implies '\--print'. + operation. The possible attributes are: "%a" for arch, "%n" for pkgname, + "%v" for pkgver, "%l" for location, "%r" for repository, and "%s" for size. + Implies '\--print'. Upgrade Options (apply to '-S' and '-U')[[UO]] diff --git a/src/pacman/util.c b/src/pacman/util.c index 0f50ae0b..e356937b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1146,6 +1146,16 @@ void print_packages(const alpm_list_t *packages) alpm_pkg_t *pkg = i->data; char *string = strdup(config->print_format); char *temp = string; + /* %a : arch */ + if(strstr(temp, "%a")) { + const char *arch = alpm_pkg_get_arch(pkg); + if(arch == NULL) { + arch = ""; + } + string = strreplace(temp, "%a", arch); + free(temp); + temp = string; + } /* %n : pkgname */ if(strstr(temp, "%n")) { string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));