GithubHelp home page GithubHelp logo

aluxian / fish-kube-prompt Goto Github PK

View Code? Open in Web Editor NEW
86.0 2.0 31.0 76 KB

⎈ kubectl context/namespace in your fish shell prompt

License: MIT License

Shell 100.00%
kubernetes fish fish-shell shell prompt kubectl

fish-kube-prompt's Introduction

fish-kube-prompt

⎈ kubectl context/namespace in your fish shell prompt

preview

Install

mkdir -p ~/.config/fish/functions/
cd ~/.config/fish/
git clone https://github.com/aluxian/fish-kube-prompt
ln -s ../fish-kube-prompt/functions/__kube_prompt.fish functions/
ln -s ../fish-kube-prompt/functions/kube_ps.fish functions/

Then create or edit ~/.config/fish/functions/fish_prompt.fish to include __kube_prompt:

function fish_prompt
  echo -s (set_color blue) (__kube_prompt) (set_color $fish_color_cwd) " " (prompt_pwd) (set_color normal) "> "
end

Speed

Running the kubectl commands to get the context and namespace every time the prompt is shown would slow down the prompt significantly. Therefore, fish-kube-prompt caches the context and namespace by only calling kubectl when the env var KUBECONFIG has changed since the last cache update, or when the 'last modified' timestamp of the files in KUBECONFIG is newer than the timestamp of the last cache update.

This was not my idea, I took it from jonmosco/kube-ps1.

Config

You can toggle the prompt on or off like this:

kube_ps on
kube_ps off

kube_ps is a simple function that just updates a universal variable __kube_ps_enabled.

Many choices have been hard-coded (e.g. colors, delimiters). If there's anything you'd like to customize, please add an env var and send a PR.

Credits

Inspired from the awesome work of:

Author

Alexandru Rosianu (https://github.com/aluxian/dotfiles-fish)

License

MIT

fish-kube-prompt's People

Contributors

aluxian avatar pgilad avatar ulidtko avatar vpistis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fish-kube-prompt's Issues

stat: cannot read file system information for '%m': No such file or directory

I ran into following error trying to use your prompt. On every call there is:

/usr/bin/stat: cannot read file system information for '%m': No such file or directory
/bin/test: extra argument ‘    ID: 74a6a6b4b6341869 Namelen: 255     Type: ext2/ext3’

This issue is different that #1. It's probably OS dependent, but on Fedora there parameters for stat looks different.

       -f, --file-system
              display file system status instead of file status

       -c  --format=FORMAT
              use the specified FORMAT instead of the default; output a newline after each use of FORMAT

In addition:

       %m     mount point

and:

       %Y     time of last data modification, seconds since Epoch

To make it work on Fedora 27 with stat 8.27 I needed to change the stat call to:

/usr/bin/stat -c '%Y' "$conf"

stat: cannot read file system information

Hi,

first of all thanx for this prompt functions, a great solution for me :)

I have encountered some problem, this is the error/warning message:

stat: cannot read file system information for '%m': No such file or directory
test: Expected a combining operator like '-a' at index 1

Thank you

ctx not updated

Hi,

the context don't change after using kctx -.
I don't know if this is only a macos problem, I use fish version 2.7.1.

There is other init or configuration steps?

tx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.