Skip to content

feat: add pre and post hook support when entering a kubert ctx shell#34

Merged
idebeijer merged 1 commit intomainfrom
feat/add-shell-hooks
Oct 24, 2025
Merged

feat: add pre and post hook support when entering a kubert ctx shell#34
idebeijer merged 1 commit intomainfrom
feat/add-shell-hooks

Conversation

@idebeijer
Copy link
Owner

@idebeijer idebeijer commented Oct 24, 2025

This PR adds pre and post hook support for the kubert ctx shell command, allowing users to execute custom shell commands before entering and after exiting a Kubernetes context shell.

Key Changes:

  • Added Hooks configuration with PreShell and PostShell fields
  • Modified shell launching logic to execute hooks and set the KUBERT_CONTEXT environment variable
  • Added comprehensive documentation with examples for configuring shell hooks

Signed-off-by: Igor de Beijer <71566757+idebeijer@users.noreply.github.com>
@idebeijer idebeijer requested a review from Copilot October 24, 2025 18:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds pre and post hook support for the kubert ctx shell command, allowing users to execute custom shell commands before entering and after exiting a Kubernetes context shell.

Key Changes:

  • Added Hooks configuration struct with PreShell and PostShell fields
  • Modified shell launching logic to execute hooks and set the KUBERT_CONTEXT environment variable
  • Added comprehensive documentation with examples for configuring shell hooks

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/config/config.go Adds Hooks struct with pre/post shell command fields and default configuration values
cmd/context.go Implements hook execution logic, extracts shell detection to getUserShell(), and sets KUBERT_CONTEXT env var
README.md Documents shell hooks feature with configuration examples and common use cases
Comments suppressed due to low confidence (1)

cmd/context.go:261

  • The executeHook() function lacks a docstring. Consider documenting the parameters (hookCommand and hookType), what the function does, and its return behavior.
func executeHook(hookCommand, hookType string) error {
	hookCmd := exec.Command(getUserShell(), "-c", hookCommand)
	hookCmd.Env = os.Environ()
	hookCmd.Stdout = os.Stdout
	hookCmd.Stderr = os.Stderr

	if err := hookCmd.Run(); err != nil {
		return fmt.Errorf("%s hook failed: %w", hookType, err)
	}

	return nil
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@idebeijer idebeijer merged commit f112578 into main Oct 24, 2025
2 checks passed
@idebeijer idebeijer deleted the feat/add-shell-hooks branch October 24, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants