c95509ebfdbcc3c497f12697cfd2717bcb0a528b

Author
Igor Aleksandrov <igor.alexandrov@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(kamal): add autocomplete support and aliases for Kamal (https://kamal-deploy.org/) (#13080)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/kamal/README.md b/plugins/kamal/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..af57168265e7df99c751f0b159982fd77d60935f
  4--- /dev/null
  5+++ b/plugins/kamal/README.md
  6@@ -0,0 +1,16 @@
  7+# Kamal
  8+
  9+This plugin provides completion for [Kamal](https://kamal-deploy.org/) as well as some
 10+aliases for frequent Kamal commands.
 11+
 12+To use it, add kamal to the plugins array of your zshrc file:
 13+
 14+```zsh
 15+plugins=(... kamal)
 16+```
 17+
 18+## Aliase
 19+
 20+| Alias     | Command                          | Description                                                                      |
 21+|-----------|----------------------------------|----------------------------------------------------------------------------------|
 22+| kad       | `kamal deploy`                   | Deploy app to servers                                                            |
 23diff --git a/plugins/kamal/_kamal b/plugins/kamal/_kamal
 24new file mode 100644
 25index 0000000000000000000000000000000000000000..52b29e81462ef771c0974bb7ce065b7cc4f46224
 26--- /dev/null
 27+++ b/plugins/kamal/_kamal
 28@@ -0,0 +1,691 @@
 29+#compdef kamal
 30+
 31+# Description
 32+# -----------
 33+#  zsh completion for Kamal (https://kamal-deploy.org/)
 34+# -------------------------------------------------------------------------
 35+# Authors
 36+# -------
 37+#  * Igor Aleksandrov <igor.alexandrov@gmail.com>
 38+# -------------------------------------------------------------------------
 39+# Inspiration
 40+# -----------
 41+#  * docker-compose ohmyzsh completion script by @sdurrheimer Steve Durrheimer
 42+# -------------------------------------------------------------------------
 43+
 44+# _kamal_commands() {
 45+#   # Only initialize if empty
 46+#   if (( ${#kamal_commands} == 0 )); then
 47+#     kamal_commands=(
 48+#       accessory
 49+#       app
 50+#       audit
 51+#       build
 52+#       config
 53+#       deploy
 54+#       details
 55+#       docs
 56+#       help
 57+#       init
 58+#       lock
 59+#       proxy
 60+#       prune
 61+#       redeploy
 62+#       registry
 63+#       remove
 64+#       rollback
 65+#       secrets
 66+#       server
 67+#       setup
 68+#       upgrade
 69+#       version
 70+#     )
 71+#   fi
 72+
 73+#   _values 'Kamal commands' $kamal_commands
 74+# }
 75+
 76+typeset -gr _kamal_commands=(
 77+  'accessory:Control accessory services'
 78+  'app:Control application deployment'
 79+  'audit:Audit security of deployment'
 80+  'build:Build and manage app images'
 81+  'config:Show effective configuration'
 82+  'deploy:Deploy app to servers'
 83+  'details:Show details about deployment'
 84+  'docs:Open documentation in browser'
 85+  'help:Show command help'
 86+  'init:Initialize new Kamal project'
 87+  'lock:Manage deployment locks'
 88+  'proxy:Control reverse proxy'
 89+  'prune:Clean up containers and images'
 90+  'redeploy:Redeploy current version'
 91+  'registry:Manage Docker registry access'
 92+  'remove:Remove app from servers'
 93+  'rollback:Rollback to a previous version'
 94+  'secrets:Manage deployment secrets'
 95+  'server:Control server configuration'
 96+  'setup:Setup initial deployment'
 97+  'upgrade:Upgrade deployment'
 98+  'version:Show Kamal version'
 99+)
100+
101+# Helper function to display messages
102+_kamal_message() {
103+  local msg="$1"
104+  _kamal_message "==> $msg"
105+}
106+
107+# Helper function to extract destination names from ./config/deploy.*.yml
108+_kamal_destinations() {
109+  local -a dests
110+  local file
111+
112+  # Check if config directory exists
113+  if [[ ! -d "config" ]]; then
114+    _kamal_message "Cannot find Kamal configuration directory at ./config" && return 1
115+  fi
116+
117+  for file in config/deploy.*.yml(N); do
118+    [[ $file =~ config/deploy\.(.+)\.yml ]] && dests+=("${match[1]}")
119+  done
120+
121+  _values 'Destination' $dests
122+}
123+
124+# Define global _kamal_flags array
125+typeset -ga _kamal_flags
126+_kamal_flags=(
127+  '(-v --verbose )'{-v,--verbose}'[Detailed logging]'
128diff --git a/plugins/kamal/kamal.plugin.zsh b/plugins/kamal/kamal.plugin.zsh
129new file mode 100644
130index 0000000000000000000000000000000000000000..e21ab4f928d2a29cdf3f89661448a82c1f802359
131--- /dev/null
132+++ b/plugins/kamal/kamal.plugin.zsh
133@@ -0,0 +1,25 @@
134+# Find kamal binary (local ./bin/kamal or global)
135+function _kamal_command () {
136+  if [ -x "./bin/kamal" ]; then
137+    ./bin/kamal "$@"
138+  else
139+    command kamal "$@"
140+  fi
141+}
142+
143+function which-kamal() {
144+  if [ -x "./bin/kamal" ]; then
145+    echo "Using local ./bin/kamal"
146+  else
147+    echo "Using global $(command -v kamal)"
148+  fi
149+}
150+
151+# Use `_kamal_command`` function for `kamal` command
152+alias kamal='_kamal_command'
153+
154+# Aliases
155+alias kad='kamal deploy'
156+
157+# Hook up completion
158+compdef _kamal_command=kamal