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

fix(install): --with-short-names flag stop working #112

Closed
davinkevin opened this issue Dec 25, 2018 · 21 comments
Closed

fix(install): --with-short-names flag stop working #112

davinkevin opened this issue Dec 25, 2018 · 21 comments

Comments

@davinkevin
Copy link

davinkevin commented Dec 25, 2018

Hi,

First, thanks for this tool which is very useful ❤️

I've installed it on a new computer and I have, when trying to install the short name version the following result with brew:

Λ\:~ kevin $ brew install kubectx --with-short-names
Warning: kubectx: this formula has no --with-short-names option so it will be ignored!
==> Downloading https://github.com/ahmetb/kubectx/archive/v0.6.2.tar.gz
Already downloaded: /Users/kevin/Library/Caches/Homebrew/downloads/495459e571c461c6b441a3687e94d26fd7a3a69128bd06b56ec8231ba0089054--kubectx-0.6.2.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

fish completions have been installed to:
  /usr/local/share/fish/vendor_completions.d
==> Summary
🍺  /usr/local/Cellar/kubectx/0.6.2: 12 files, 32.4KB, built in 2 seconds

So the --with-short-names isn't available and we can't access the kctx command line. Is it normal? Is it a bug on the installation or the documentation which should be updated?

Thanks

@ahmetb ahmetb added the Bug label Dec 25, 2018
@ahmetb
Copy link
Owner

ahmetb commented Dec 25, 2018

Hmm looks like this happened in the Homebrew repo. Homebrew/homebrew-core@f01c536

See Homebrew/homebrew-core#31510 for some of the rationale. I'm still trying to parse the explanation myself. Open to any ideas about how to fix this.

@ahmetb
Copy link
Owner

ahmetb commented Dec 25, 2018

Looks like options are gone, for good. We need to find alternatives.

We could easily tell people to do alias kctx=kubectx but the main complaint we got was "it gets in the way of tab completion when we do kubeTab" which we won't be able to solve with that.

@naseemkullah
Copy link

Could you make the "official" commands kctx and kns and if people choose to, they could alias kubectx=kctx and alias kubens=kns?

@ahmetb
Copy link
Owner

ahmetb commented Dec 28, 2018

According to brew analytics, only 20% of the people use —with-short-names option, so I don’t think distributing with the short names by default is a good idea. https://formulae.brew.sh/analytics/install/365d/

@naseemkullah
Copy link

Ah, good point.

@Hengjie
Copy link

Hengjie commented Jan 8, 2019

Perhaps another brew package can be replicated with that option on as default? So technically you can install both if you wanted both commands to run, or just one if you prefer one of it.

@ahmetb
Copy link
Owner

ahmetb commented Jan 8, 2019

Perhaps another brew package can be replicated with that option on as default?

This is a good suggestion, but I'm not positive about replicating the package management formula. We get stuff like automatic releases and install analytics with Homebrew, and I intend to keep it that way.

johnraz added a commit to johnraz/kubectx that referenced this issue Jan 13, 2019
First measure to avoid confusing people.
see ahmetb#112
ahmetb pushed a commit that referenced this issue Jan 13, 2019
First measure to avoid confusing people.
see #112
@przemolb
Copy link

Why this option (with short names) has been removed ?

@ahmetb
Copy link
Owner

ahmetb commented Jan 29, 2019

Homebrew removed options on formulas.

@przemolb
Copy link

so maybe you change a name of the package ? kctx is way more convenient that kubectx :-)

@ahmetb
Copy link
Owner

ahmetb commented Jan 29, 2019

so maybe you change a name of the package ? kctx is way more convenient that kubectx :-)

That's subjective, and I disagree. 75% users installed via Homebrew use the long form, and you can always do alias kctx=kubectx in your shell profile. Not to mention, none of the Linux distribution options offer the --with-short-names feature.

You can also download kubectx file, and save it to your /usr/local/bin as kctx, it should still work as it doesn't have dependencies to other files.

In this case, Homebrew screwed us, I wish it offered some means of keeping this functionality. I thought of forking the brew formula and hosting it myself as a tap, but that's suboptimal and we lose brew features like auto-version-bump, analytics and discoverability.

@dotLou
Copy link

dotLou commented Jan 29, 2019

This isn't a full solution, but I've gotten around this by adding to my ~/.zshrc (~/.bashrc should work too) file:

if [ $(command -v kubectx) ] && ! [ $(command -v kctx) ]; then
  CMD="$(which kubectx)"
  ln -s $CMD /usr/local/bin/kctx || alias kctx=$CMD
fi
if [ $(command -v kubens) ] && ! [ $(command -v kns) ]; then
  CMD="$(which kubens)"
  ln -s $CMD /usr/local/bin/kns || alias kns=$CMD
fi

I do the symlink first because that actually works for things like kctx - whereas that didn't work for me with the alias but I fall back on the alias in case /usr/local/bin is inaccessible.

@ahmetb
Copy link
Owner

ahmetb commented Jan 29, 2019

@dotLou if you're putting things in your bashrc/zshrc, you might as well just create an alias instead of making a permanent symlink. :)

The main reason why people asked for shorter names like kctx is because when they type kube and hit TabTab for shell completion, instead of getting kubectl they also got kubectx so it wouldn't automatically complete to kubectl because it had multiple options.

@przemolb
Copy link

so maybe you change a name of the package ? kctx is way more convenient that kubectx :-)

That's subjective, and I disagree. 75% users installed via Homebrew use the long form, and you can always do alias kctx=kubectx in your shell profile. Not to mention, none of the Linux distribution options offer the --with-short-names feature.

Are you 100% sure they know that it can be installed and used with short name ? I am pretty sure that if it was by default they wouldn't use the long name.

@dotLou
Copy link

dotLou commented Jan 29, 2019

@dotLou if you're putting things in your bashrc/zshrc, you might as well just create an alias instead of making a permanent symlink. :)

So you got me thinking about the || alias stuff, but I got that from another bit of code that's weirder. I had an issue with alias kctx="kubectx " with the space, but I don't actually need that in this case (I do use that for things like alias k="kubectl " so I can use it inside of things like watch k get pods as it doesn't work without the space.. anyway).

So for those watching, just do:

if [ $(command -v kubectx) ] && ! [ $(command -v kctx) ]; then
  alias kctx=kubectx
fi
if [ $(command -v kubens) ] && ! [ $(command -v kns) ]; then
  alias kns=kubens
fi

@max-lobur
Copy link

Simplest fix: max-lobur/dotfiles@722238e

@ahmetb
Copy link
Owner

ahmetb commented Feb 1, 2019

If you alias, then somehow mask the kubectx/kubens executables (so kube/tab/tab completion doesn’t bring it up) you’re good to go. 👍🏼

@max-lobur
Copy link

max-lobur commented Feb 1, 2019

@ahmetb I use k for kubectl so I don't have that issue :)

@gordonbondon
Copy link

gordonbondon commented Apr 1, 2019

I've added this to remove full names so that they don't appear in completion. Now I just need to remember to update versions in bash profile :) :

if [ $(command -v kubectx) ]; then
  brew unlink kubectx
  version=$(brew info kubectx --json | jq -r '.[].versions.stable')
  ln -s /usr/local/Cellar/kubectx/$version/bin/kubectx /usr/local/bin/kctx
  ln -s /usr/local/Cellar/kubectx/$version/bin/kubens /usr/local/bin/kns
  ln -s /usr/local/Cellar/kubectx/$version/etc/bash_completion.d/kubectx /usr/local/etc/bash_completion.d/kubectx
  ln -s /usr/local/Cellar/kubectx/$version/etc/bash_completion.d/kubens /usr/local/etc/bash_completion.d/kubens
fi

Updated my snippet to include version detection and fix for completion

@ahmetb
Copy link
Owner

ahmetb commented Apr 1, 2019

@gordonbondon you can use brew info kubectx --json | jq -r '.[].linked_keg' to retrieve version string.

@ye ye mentioned this issue Apr 18, 2019
@arbourd
Copy link

arbourd commented Jul 24, 2019

I think this can be closed as aliasing is the only real path forward here if using homebrew :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants