Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,26 @@ jobs:
run: |
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out

goreleaser:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-go@v7
with:
go-version: '1.26'
# Catch a broken release config here rather than halfway through a tag.
- name: Validate release config
uses: goreleaser/goreleaser-action@v6
with:
version: '~> v2'
args: check
- name: Build snapshot
uses: goreleaser/goreleaser-action@v6
with:
version: '~> v2'
args: release --snapshot --clean --skip=publish
env:
HOMEBREW_TAP_GITHUB_TOKEN: ''
32 changes: 23 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
tags: [ '*' ]

permissions:
contents: write

jobs:
lint:
runs-on: ubuntu-24.04
Expand All @@ -21,18 +24,29 @@ jobs:
steps:
- name: Check out code 🛒
uses: actions/checkout@v7
with:
# GoReleaser needs full history and tags to resolve the version.
fetch-depth: 0

- name: Set up Go 🐹
uses: actions/setup-go@v7
with:
go-version: '1.26'

- name: Generate Release Notes 📝
if: github.ref_type == 'tag'
# Written outside the working tree: GoReleaser refuses to release from
# a dirty git state, and an untracked changelog.txt counts as dirty.
run: |
CHANGE=$(sed "/${GITHUB_REF_NAME%%-*}/,/##/!d;//d" CHANGELOG.md | awk 'NF')
echo "$CHANGE" > changelog.txt
RELEASE_TYPE=$(if [[ "$GITHUB_REF_NAME" =~ "beta" ]]; then echo "true"; else echo "false"; fi)
echo "RELEASE_TYPE=${RELEASE_TYPE}" >> $GITHUB_ENV
echo "$CHANGE" > "${RUNNER_TEMP}/changelog.txt"

- name: Create Release 🎉
uses: ncipollo/release-action@v1.21.0
if: github.ref_type == 'tag'
- name: Run GoReleaser 🚀
uses: goreleaser/goreleaser-action@v6
with:
bodyFile: "changelog.txt"
prerelease: ${{ env.RELEASE_TYPE }}
version: '~> v2'
args: release --clean --release-notes=${{ runner.temp }}/changelog.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Needs write access to radiusmethod/homebrew-awsd. Without it the
# release still publishes; only the tap update is skipped.
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ bin/
# IDEs
.idea
.vscode
dist/
96 changes: 96 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
version: 2

project_name: kxd

before:
hooks:
- go mod tidy

builds:
- id: kxd
binary: kxd
main: .
env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
ldflags:
# version is otherwise "dev"; the tag is the source of truth for releases.
- -s -w -X github.com/radiusmethod/kxd/src/cmd.version=v{{ .Version }}

archives:
- id: kxd
ids:
- kxd
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files:
- README.md
- LICENSE
- CHANGELOG.md
format_overrides:
- goos: windows
formats:
- zip

checksum:
name_template: "checksums.txt"

changelog:
# Release notes come from CHANGELOG.md via --release-notes in the workflow.
disable: true

release:
prerelease: auto
# Make re-runs idempotent. Without this, retrying a tag after a partial
# failure (a bad tap token, say) trips over the release that already exists.
mode: replace

homebrew_casks:
- name: kxd
ids:
- kxd
repository:
owner: radiusmethod
name: homebrew-kxd
branch: main
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
directory: Casks
homepage: "https://github.com/radiusmethod/kxd"
description: "Kubeconfig and context switcher in Go"
license: "MIT"
# Ship binaries even when the tap token is not configured, rather than
# failing the whole release. The workflow always defines the variable, so
# this is empty rather than missing when the secret is absent.
skip_upload: '{{ if .Env.HOMEBREW_TAP_GITHUB_TOKEN }}false{{ else }}true{{ end }}'
hooks:
post:
# The binaries are unsigned, so macOS quarantines them on download and
# Gatekeeper refuses to run them. Strip the attribute on install.
install: |
if system_command("/usr/bin/xattr", args: ["-h"]).exit_status == 0
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/kxd"]
end
caveats: |
To finish setting up kxd, add the line for your shell to its startup file:

zsh eval "$(kxd init zsh)"
bash eval "$(kxd init bash)"
fish kxd init fish | source
PowerShell kxd init powershell | Out-String | Invoke-Expression

Then open a new terminal, or source that file.

Upgrading from before v0.2.0? The line above replaces all of these, so
remove them from your shell config:

alias kxd="source _kxd"
source _kxd_autocomplete
export KUBECONFIG=$(kxd file current)

Then delete any leftover _kxd_prompt, _kxd, and _kxd_autocomplete files
from earlier manual installs.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
## v0.2.0 (August 5, 2026)

**Breaking.** kxd is now a single binary named `kxd`, set up with one line in your shell rc file. Pre-1.0, so no compatibility shims.

* Added `kxd init <shell>` — `eval "$(kxd init zsh)"` now replaces the `kxd` alias, the completion `source`, and the `export KUBECONFIG=$(kxd file current)` persistence line. Supports bash, zsh, fish, and PowerShell.
* Added `kxd shellenv [shell]`, which prints the export/unset statement for the active kubeconfig. This is what the generated function evals.
* Added fish support. PowerShell setup is now one line instead of building a binary and dot-sourcing two scripts by hand.
* The binary is installed as `kxd`, not `_kxd_prompt`. The generated integration calls it through `command kxd`, which skips the shell function of the same name.
* Removed `scripts/` entirely: `_kxd`, `_kxd_autocomplete`, `_kxd.ps1`, and `_kxd_autocomplete.ps1`. `make install` now installs one file.
* `~/.kxd` parsing and the `~/.kube` path join now live only in the Go code, instead of being reimplemented in every wrapper script.
* Values are shell-quoted, so kubeconfig filenames containing spaces or quotes work.
* Completion now covers the `file`/`context`/`namespace` subcommands and their arguments, not just top-level config names. Namespace values are excluded on purpose, since listing them calls the live cluster.
* **Behavior change:** `kxd <unknown-config>` now writes its warning to stderr and exits 1, instead of writing to stdout and exiting 0. Scripts relying on the old exit code need updating. This keeps ANSI color codes out of the command substitutions the shell integration evals.

Releases are now built by GoReleaser:

* Releases ship prebuilt binaries for macOS, Linux, and Windows on amd64 and arm64, with `checksums.txt`. Installing no longer compiles from source, and Windows binaries are published for the first time.
* Homebrew distribution moves from a formula to a **cask**, generated on each tag. Reinstall with `brew uninstall kxd && brew install radiusmethod/kxd/kxd` if brew complains about the change.
* `kxd version` now reports the git tag, injected at build time. `make install` derives it from `git describe`, and a plain `go build` reports `dev`.
* Prerelease tags must now be SemVer-hyphenated (`v0.3.0-beta1`), not `v0.3.0beta`.

To upgrade: replace your shell config lines as described in "Upgrading from pre-v0.2.0" in the README, then delete any leftover `_kxd_prompt`, `_kxd`, and `_kxd_autocomplete` files. Your `~/.kxd` file is unchanged and carries over.

## v0.1.4 (May 22, 2026)
* Updated Kubernetes client libraries (client-go v0.36.1), cobra (v1.10.2), and Go toolchain to 1.26.

Expand Down
42 changes: 20 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
BINDIR = /usr/local/bin
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS = -s -w -X github.com/radiusmethod/kxd/src/cmd.version=$(VERSION)

help: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

install: ## Install Target
GOOS= GOARCH= GOARM= GOFLAGS= go build -o ${BINDIR}/_kxd_prompt
cp scripts/_kxd ${BINDIR}/_kxd
cp scripts/_kxd_autocomplete ${BINDIR}/_kxd_autocomplete
@echo " -=-=--=-=-=-=-=-=-=-=-=-=-=-=- "
@echo " __ __ _ __ ____ "
@echo " / //_/ | |/ / / __ \ "
@echo " / ,< | / / / / / "
@echo " / /| | / | / /_/ / "
@echo " /_/ |_| /_/|_| /_____/ "
@echo " "
@echo " To Finish Installation add "
@echo " "
@echo " alias kxd=\"source _kxd\" "
@echo " "
@echo " to your bash profile or zshrc "
@echo " then open new terminal or "
@echo " source that file "
@echo " "
@echo " -=-=--=-=-=-=-=-=-=-=-=-=-=-=- "
GOOS= GOARCH= GOARM= GOFLAGS= go build -ldflags="$(LDFLAGS)" -o ${BINDIR}/kxd
@echo " -=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=- "
@echo " __ __ _ __ ____ "
@echo " / //_/ | |/ / / __ \ "
@echo " / ,< | / / / / / "
@echo " / /| | / | / /_/ / "
@echo " /_/ |_| /_/|_| /_____/ "
@echo " "
@echo " To Finish Installation add "
@echo " "
@echo " eval \"\$$(kxd init zsh)\" "
@echo " "
@echo " to your zshrc (or bash profile, "
@echo " with 'init bash') then open a new "
@echo " terminal or source that file "
@echo " "
@echo " -=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=- "

uninstall: ## Uninstall Target
rm -f ${BINDIR}/_kxd
rm -f ${BINDIR}/_kxd_autocomplete
rm -f ${BINDIR}/_kxd_prompt
rm -f ${BINDIR}/kxd

.PHONY: test test-coverage docs
test: ## Run tests
Expand Down
13 changes: 3 additions & 10 deletions Makefile_Windows
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
BINDIR = C:\tools

# Requires `make` with PowerShell as the shell. Easiest way:
# make -f Makefile_Windows SHELL=pwsh.exe install
# `cp` / `rm` resolve to PowerShell aliases, `New-Item` is PowerShell-native.
BINDIR = C:\tools\kxd

install: ## Install Target
go build -o ${BINDIR}/kxd/_kxd_prompt.exe
cp scripts/_kxd.ps1 ${BINDIR}/kxd/_kxd.ps1
cp scripts/_kxd_autocomplete.ps1 ${BINDIR}/kxd/_kxd_autocomplete.ps1
New-Item -ItemType File -Path ~/.kxd -Force
go build -o ${BINDIR}\kxd.exe

uninstall: ## Uninstall Target
rm -Force -Recurse ${BINDIR}/kxd
rm -Force ${BINDIR}\kxd.exe
Loading
Loading