File: ppc.sh 1 #!/bin/sh 2 3 # The MIT License (MIT) 4 # 5 # Copyright (c) 2026 pacman64 6 # 7 # Permission is hereby granted, free of charge, to any person obtaining a copy 8 # of this software and associated documentation files (the "Software"), to deal 9 # in the Software without restriction, including without limitation the rights 10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 # copies of the Software, and to permit persons to whom the Software is 12 # furnished to do so, subject to the following conditions: 13 # 14 # The above copyright notice and this permission notice shall be included in 15 # all copies or substantial portions of the Software. 16 # 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 # SOFTWARE. 24 25 26 # ppc [options...] 27 # 28 # Pick Podman Containers, using the output of `podman container list`, and the 29 # interactive `fzf` line-picker. 30 # 31 # The options are, available both in single and double-dash versions 32 # 33 # -h, -help show this help message 34 # -id, -ids only emit container IDs, one per line 35 36 37 ids_only=0 38 39 case "$1" in 40 -h|--h|-help|--help) 41 awk '/^# +ppc /, /^$/ { gsub(/^# ?/, ""); print }' "$0" 42 exit 0 43 ;; 44 45 -id|--id|-ids|--ids) ids_only=1; shift ;; 46 47 --) shift ;; 48 49 -*) 50 printf "unsupported option '%s'\n" "$1" >&2 51 exit 1 52 ;; 53 esac 54 55 if ! command -v fzf > /dev/null; then 56 printf "fzf (interactive picker) not found\n" >&2 57 exit 2 58 fi 59 60 when="$(date +'%Y-%m-%d %H:%M:%S')" 61 data="$(podman container list)" 62 [ -z "${data}" ] && exit 1 63 64 keys='ctrl-a:select-all,ctrl-space:toggle,F10:abort,F12:abort' 65 pick="fzf -m --reverse --header-first --header-lines=1 --bind ${keys}" 66 msg="$(printf "%-20s (run on %s)\n" "podman container list" "${when}")" 67 68 picks="$(echo "${data}" | ${pick} --header="${msg}")" 69 [ -z "${picks}" ] && exit 1 70 71 printf "%s\n" "${picks}" \ 72 | awk -v ids_only="${ids_only}" '{ print((ids_only) ? $1 : $0) }'