1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-01-14 22:47:45 +08:00

Podman Compsoe plugins added. To-Do: README

This commit is contained in:
Sahil Rathee 2024-10-22 20:15:47 +05:30
parent a9e29fc12c
commit 4744aa8bd1
3 changed files with 244 additions and 0 deletions

View File

@ -0,0 +1,47 @@
# Podman plugin
This plugin adds auto-completion and aliases for [podman](https://podman.io/).
To use it add `podman` to the plugins array in your zshrc file.
```zsh
plugins=(... podman)
```
## Aliases
| Alias | Command | Description |
| :------ | :-------------------------------------------- | :--------------------------------------------------------------------------------------- |
| pbl | `podman build` | Build an image from a Dockerfile |
| pcin | `podman container inspect` | Display detailed information on one or more containers |
| pcls | `podman container ls` | List all the running podman containers |
| pclsa | `podman container ls --all` | List all running and stopped containers |
| pib | `podman image build` | Build an image from a Dockerfile (same as podman build) |
| pii | `podman image inspect` | Display detailed information on one or more images |
| pils | `podman image ls` | List podman images |
| pipu | `podman image push` | Push an image or repository to a remote registry |
| pirm | `podman image rm` | Remove one or more images |
| pit | `podman image tag` | Add a name and tag to a particular image |
| plo | `podman container logs` | Fetch the logs of a podman container |
| pnc | `podman network create` | Create a new network |
| pncn | `podman network connect` | Connect a container to a network |
| pndcn | `podman network disconnect` | Disconnect a container from a network |
| pni | `podman network inspect` | Return information about one or more networks |
| pnls | `podman network ls` | List all networks the engine daemon knows about, including those spanning multiple hosts |
| pnrm | `podman network rm` | Remove one or more networks |
| ppo | `podman container port` | List port mappings or a specific mapping for the container |
| ppu | `podman pull` | Pull an image or a repository from a registry |
| pr | `podman container run` | Create a new container and start it using the specified command |
| prit | `podman container run --interactive --tty` | Create a new container and start it in an interactive shell |
| prm | `podman container rm` | Remove the specified container(s) |
| prm! | `podman container rm --force` | Force the removal of a running container (uses SIGKILL) |
| pst | `podman container start` | Start one or more stopped containers |
| prs | `podman container restart` | Restart one or more containers |
| psta | `podman stop $(podman ps -q)` | Stop all running containers |
| pstp | `podman container stop` | Stop one or more running containers |
| ptop | `podman top` | Display the running processes of a container |
| pvi | `podman volume inspect` | Display detailed information about one or more volumes |
| pvls | `podman volume ls` | List all the volumes known to podman |
| pvprune | `podman volume prune` | Cleanup dangling volumes |
| pxc | `podman container exec` | Run a new command in a running container |
| pxcit | `podman container exec --interactive --tty` | Run a new command in a running container in an interactive shell |

View File

@ -0,0 +1,174 @@
#compdef podman-compose
# Description
# -----------
# zsh completion for podman-compose
# -------------------------------------------------------------------------
# Author(s)
# -------
# Sahil Rt sahil.rathee@infortts.com
# -------------------------------------------------------------------------
__podman_compose_q() {
podman-compose 2>/dev/null "$@"
}
# All services defined in podman-compose.yml
__podman_compose_all_services_in_compose_file() {
local already_selected
local -a services
already_selected=$(echo $words | tr " " "|")
__podman_compose_q ps --services "$@" \
| grep -Ev "^(${already_selected})$"
}
# All services, even those without an existing container
__podman_compose_services_all() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
services=$(__podman_compose_all_services_in_compose_file "$@")
_alternative "args:services:($services)" && ret=0
return ret
}
# All services that are defined by a Dockerfile reference
__podman_compose_services_from_build() {
[[ $PREFIX = -* ]] && return 1
__podman_compose_services_all --filter source=build
}
# All services that are defined by an image
__podman_compose_services_from_image() {
[[ $PREFIX = -* ]] && return 1
__podman_compose_services_all --filter source=image
}
__podman_compose_pausedservices() {
[[ $PREFIX = -* ]] && return 1
__podman_compose_services_all --filter status=paused
}
__podman_compose_stoppedservices() {
[[ $PREFIX = -* ]] && return 1
__podman_compose_services_all --filter status=stopped
}
__podman_compose_runningservices() {
[[ $PREFIX = -* ]] && return 1
__podman_compose_services_all --filter status=running
}
__podman_compose_services() {
[[ $PREFIX = -* ]] && return 1
__podman_compose_services_all
}
__podman_compose_caching_policy() {
oldp=( "$1"(Nmh+1) ) # 1 hour
(( $#oldp ))
}
__podman_compose_commands() {
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
if [[ -z "$cache_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy __podman_compose_caching_policy
fi
if ( [[ ${+_podman_compose_subcommands} -eq 0 ]] || _cache_invalid podman_compose_subcommands) \
&& ! _retrieve_cache podman_compose_subcommands;
then
local -a lines
lines=(${(f)"$(_call_program commands podman-compose 2>&1)"})
_podman_compose_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:})
(( $#_podman_compose_subcommands > 0 )) && _store_cache podman_compose_subcommands _podman_compose_subcommands
fi
_describe -t podman-compose-commands "podman-compose command" _podman_compose_subcommands
}
__podman_compose_subcommand() {
local opts_help opts_no_color opts_no_deps
opts_help='(: -)--help[Print usage]'
opts_no_color='--no-color[Produce monochrome output.]'
opts_no_deps="--no-deps[Don't start linked services.]"
integer ret=1
case "$words[1]" in
(build)
_arguments \
$opts_help \
'--no-cache[Do not use cache when building the image.]' \
'--pull[Always attempt to pull a newer version of the image.]' \
'*:services:__podman_compose_services_from_build' && ret=0
;;
(down)
_arguments \
$opts_help \
'--remove-orphans[Remove containers for services not defined in the Compose file]' \
'--volumes[Remove named volumes and anonymous volumes attached to containers]' && ret=0
;;
(logs)
_arguments \
$opts_help \
'(-f --follow)'{-f,--follow}'[Follow log output]' \
'--tail=[Number of lines to show from the end of the logs for each container.]:number of lines: ' \
$opts_no_color \
'*:services:__podman_compose_services' && ret=0
;;
(start|stop)
_arguments \
$opts_help \
'*:services:__podman_compose_services' && ret=0
;;
(ps)
_arguments \
$opts_help \
'--filter KEY=VAL[Filter services by a property]:<filtername>=<value>:' \
'*:services:__podman_compose_services' && ret=0
;;
(*)
_message 'Unknown sub command' && ret=1
;;
esac
return ret
}
_podman_compose() {
local curcontext="$curcontext" state line
integer ret=1
typeset -A opt_args
_arguments -C \
'(- :)'{-h,--help}'[Get help]' \
'*'{-f,--file}"[Specify an alternate podman-compose file (default: podman-compose.yml)]:file:_files -g '*.yml'" \
'(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \
"--compatibility[Attempt to convert keys to non-Swarm equivalent]" \
'(-v --version)'{-v,--version}'[Print version and exit]' \
"--log-level=[Set log level]:level:(DEBUG INFO WARNING ERROR CRITICAL)" \
"--tls[Use TLS]" \
"--tlscert=[Path to TLS certificate file]:client cert path:" \
"--tlskey=[Path to TLS key file]:tls key path:" \
"--tlsverify[Use TLS and verify the remote]" \
"--skip-hostname-check[Skip daemon hostname check]" \
'(-): :->command' \
'(-)*:: :->option-or-argument' && ret=0
case $state in
(command)
__podman_compose_commands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:podman-compose-$words[1]:
__podman_compose_subcommand && ret=0
;;
esac
return ret
}
_podman_compose "$@"

View File

@ -0,0 +1,23 @@
[[ -x "${commands[podman-compose]:A}" ]] && pccmd='podman-compose' || pccmd='podman compose'
alias pco="$pccmd"
alias pcb="$pccmd build"
alias pce="$pccmd exec"
alias pcps="$pccmd ps"
alias pcrestart="$pccmd restart"
alias pcrm="$pccmd rm"
alias pcr="$pccmd run"
alias pcstop="$pccmd stop"
alias pcup="$pccmd up"
alias pcupb="$pccmd up --build"
alias pcupd="$pccmd up -d"
alias pcupdb="$pccmd up -d --build"
alias pcdn="$pccmd down"
alias pcl="$pccmd logs"
alias pclf="$pccmd logs -f"
alias pclF="$pccmd logs -f --tail 0"
alias pcpull="$pccmd pull"
alias pcstart="$pccmd start"
alias pck="$pccmd kill"
unset pccmd