Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate zsh plugin #32

Open
wants to merge 13 commits into
base: generate-aliases
Choose a base branch
from
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,24 @@ All commands with the same comment will be grouped together in the generated fil
# Installation

To grab a bunch of aliases without customization get the
`aliases` file and source it in your `bashrc` or `zshrc` file.

## Bash Example
`aliases.sh` file and source it in your `bashrc` or `zshrc` file.

```bash
curl https://raw.githubusercontent.com/Dbz/kube-aliases/master/aliases -o ${HOME}/.kube-aliases
echo "source ${HOME}/.kube-aliases" >> .bashrc
curl https://raw.githubusercontent.com/Dbz/kube-aliases/master/aliases.sh -o ${HOME}/.kube-aliases.sh
echo "source ${HOME}/.kube-aliases.sh" >> .bashrc
```

## Zsh Example
## Oh-My-Zsh Example

To install this as a plugin:

```bash
curl https://raw.githubusercontent.com/Dbz/kube-aliases/master/aliases -o ${HOME}/.kube-aliases
echo "source ${HOME}/.kube-aliases" >> .zshrc
git clone https://github.com/Dbz/kube-aliases.git ~/.oh-my-zsh/custom/plugins/kube-aliases
echo "plugins+=(kube-aliases)" >> ~/.zshrc
```

If you set the `ZSH_CUSTOM` environment variable, then you should modify the git clone directory to be `$ZSH_CUSTOM/plugins/kube-aliases`.

## Generate Aliases

Coming soon
Expand Down
1 change: 1 addition & 0 deletions aliases → aliases.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash

# Manage events.
alias kcev="kubectl create events"
Expand Down
3 changes: 2 additions & 1 deletion generate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cmds:
additional:
- short: wkgp
cmd: "watch kubectl get pods"
comment: "Additional pod commands."
```

Which will generate the following file
Expand All @@ -35,7 +36,7 @@ by running

```bash
make
bin/generate-kube-aliases alias.yaml aliases
bin/generate-kube-aliases alias.yaml aliases.sh
```

# Contributing
Expand Down
5 changes: 5 additions & 0 deletions generate/pkg/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func Generate(filePath, targetPath string) error {
}
defer aliasFile.Close()

_, err = io.WriteString(aliasFile, "#!/bin/bash\n")
if err != nil {
return fmt.Errorf("Warning: could not write shebang", err)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is required. Sourcing the file should be sufficient.

Copy link
Owner Author

Choose a reason for hiding this comment

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

This definitely isn't required. I just feel like it's good practice?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe its completely ignored when the file is sourced. It doesnt hurt anything so Im okay for keeping it.

var aliasBuilder strings.Builder
var aliasCMDs types.AliasCMDs
for r := range aliases.Resources {
Expand Down
8 changes: 8 additions & 0 deletions kube-aliases.plugin.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
KALIAS=$ZSH_CUSTOM/plugins/kube-aliases
KRESOURCES=$ZSH_CUSTOM/plugins/kube-aliases/docs/resources
Dbz marked this conversation as resolved.
Show resolved Hide resolved
SHELL_NAME=$(basename $SHELL)

# Auto complete, for bash replace zsh with bash
# For some reason this is sourcing the oh-my-zsh plugin.
source <(kubectl completion $SHELL_NAME)
Dbz marked this conversation as resolved.
Show resolved Hide resolved
source ./aliases.sh