From 03c8c6427add7c17f5d0478ed7bb2066308b1f7f Mon Sep 17 00:00:00 2001 From: Sandjaie Ravi <12917663+sandjaie@users.noreply.github.com> Date: Sat, 1 Aug 2020 23:57:59 +0200 Subject: [PATCH 1/2] [segment] added kubecontext segment --- .gitignore | 139 +++++++++++++++++++++++ powerline_shell/colortrans.py | 4 +- powerline_shell/segments/kubecontext.py | 15 +++ powerline_shell/themes/basic.py | 3 + powerline_shell/themes/default.py | 2 + powerline_shell/themes/gruvbox.py | 3 + powerline_shell/themes/solarized_dark.py | 3 + powerline_shell/themes/washed.py | 3 + setup.py | 4 +- 9 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 powerline_shell/segments/kubecontext.py diff --git a/.gitignore b/.gitignore index ec4610be..08a3c775 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,142 @@ config.json powerline-shell.json .DS_Store *sublime* + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/powerline_shell/colortrans.py b/powerline_shell/colortrans.py index 1c385522..6939259c 100755 --- a/powerline_shell/colortrans.py +++ b/powerline_shell/colortrans.py @@ -106,13 +106,13 @@ def rgbstring2tuple(s): (95, 175, 215): 74, (95, 175, 255): 75, (95, 215, 0): 76, - (95, 215, 95) : 77, + (95, 215, 95): 77, (95, 215, 135): 78, (95, 215, 175): 79, (95, 215, 215): 80, (95, 215, 255): 81, (95, 255, 0): 82, - (95, 255, 95) : 83, + (95, 255, 95): 83, (95, 255, 135): 84, (95, 255, 175): 85, (95, 255, 215): 86, diff --git a/powerline_shell/segments/kubecontext.py b/powerline_shell/segments/kubecontext.py new file mode 100644 index 00000000..fde425e1 --- /dev/null +++ b/powerline_shell/segments/kubecontext.py @@ -0,0 +1,15 @@ +""" +Shows the exported kubectl context +e.g $ export KUBECONFIG=~/.kube/config-staging-cluster +""" +from ..utils import BasicSegment +import os + + +class Segment(BasicSegment): + def add_to_powerline(self): + kubecontext = os.environ.get("KUBECONFIG") + if kubecontext: + self.powerline.append(" kctx:%s " % os.path.basename(kubecontext), + self.powerline.theme.KUBECONFIG_FG, + self.powerline.theme.KUBECONFIG_BG) diff --git a/powerline_shell/themes/basic.py b/powerline_shell/themes/basic.py index bd4d2f9e..6163cab8 100644 --- a/powerline_shell/themes/basic.py +++ b/powerline_shell/themes/basic.py @@ -43,3 +43,6 @@ class Color(DefaultColor): TIME_FG = 8 TIME_BG = 7 + + KUBECONFIG_FG = 14 + KUBECONFIG_BG = 8 diff --git a/powerline_shell/themes/default.py b/powerline_shell/themes/default.py index da0c0034..b971c2fb 100644 --- a/powerline_shell/themes/default.py +++ b/powerline_shell/themes/default.py @@ -75,6 +75,8 @@ class DefaultColor(object): TIME_FG = 250 TIME_BG = 238 + KUBECONFIG_FG = 38 + KUBECONFIG_BG = 239 class Color(DefaultColor): """ diff --git a/powerline_shell/themes/gruvbox.py b/powerline_shell/themes/gruvbox.py index 1326ea46..5cfdaa7c 100644 --- a/powerline_shell/themes/gruvbox.py +++ b/powerline_shell/themes/gruvbox.py @@ -109,3 +109,6 @@ class Color(DefaultColor): TIME_FG = light2 TIME_BG = dark4 + + KUBECONFIG_BG = neutral_blue + KUBECONFIG_FG = dark2 diff --git a/powerline_shell/themes/solarized_dark.py b/powerline_shell/themes/solarized_dark.py index ec0f41bf..4ceb6923 100644 --- a/powerline_shell/themes/solarized_dark.py +++ b/powerline_shell/themes/solarized_dark.py @@ -42,3 +42,6 @@ class Color(DefaultColor): TIME_FG = 15 TIME_BG = 10 + + KUBECONFIG_FG = 7 + KUBECONFIG_BG = 2 diff --git a/powerline_shell/themes/washed.py b/powerline_shell/themes/washed.py index d2935095..bda6b8a4 100644 --- a/powerline_shell/themes/washed.py +++ b/powerline_shell/themes/washed.py @@ -42,3 +42,6 @@ class Color(DefaultColor): TIME_FG = 8 TIME_BG = 7 + + KUBECONFIG_FG = 0 + KUBECONFIG_BG = 7 diff --git a/setup.py b/setup.py index 87482e21..465fea26 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( - name="powerline-shell", + name="powerline-shell-test", version="0.7.0", description="A pretty prompt for your shell", author="Buck Ryan", @@ -27,6 +27,6 @@ ], entry_points=""" [console_scripts] - powerline-shell=powerline_shell:main + powerline-shell-test=powerline_shell:main """, ) From 5a54246802f8a45a0050f581da2b39014e358e32 Mon Sep 17 00:00:00 2001 From: Sandjaie Ravi <12917663+sandjaie@users.noreply.github.com> Date: Sat, 1 Aug 2020 23:57:59 +0200 Subject: [PATCH 2/2] [segment] added kubecontext segment [segment] added kubecontext segement [segment] added kubecontext segement [segment] added kubecontext segement --- .gitignore | 90 +------------------ powerline_shell/colortrans.py | 2 +- .../{kubecontext.py => kube_context.py} | 11 +-- powerline_shell/themes/basic.py | 5 +- powerline_shell/themes/default.py | 5 +- powerline_shell/themes/gruvbox.py | 5 +- powerline_shell/themes/solarized_dark.py | 5 +- powerline_shell/themes/washed.py | 4 +- setup.py | 4 +- 9 files changed, 27 insertions(+), 104 deletions(-) rename powerline_shell/segments/{kubecontext.py => kube_context.py} (52%) diff --git a/.gitignore b/.gitignore index 08a3c775..f27e5f8e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,11 @@ tags config.json powerline-shell.json .DS_Store + +# editors *sublime* +.vscode/ +.idea/ # Byte-compiled / optimized / DLL files __pycache__/ @@ -38,16 +42,6 @@ share/python-wheels/ *.egg MANIFEST -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - # Unit test / coverage reports htmlcov/ .tox/ @@ -63,59 +57,6 @@ coverage.xml .pytest_cache/ cover/ -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - # Environments .env .venv @@ -125,26 +66,3 @@ ENV/ env.bak/ venv.bak/ -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ diff --git a/powerline_shell/colortrans.py b/powerline_shell/colortrans.py index 6939259c..c1e991b0 100755 --- a/powerline_shell/colortrans.py +++ b/powerline_shell/colortrans.py @@ -100,7 +100,7 @@ def rgbstring2tuple(s): (95, 135, 215): 68, (95, 135, 255): 69, (95, 175, 0): 70, - (95, 175, 95) : 71, + (95, 175, 95): 71, (95, 175, 135): 72, (95, 175, 175): 73, (95, 175, 215): 74, diff --git a/powerline_shell/segments/kubecontext.py b/powerline_shell/segments/kube_context.py similarity index 52% rename from powerline_shell/segments/kubecontext.py rename to powerline_shell/segments/kube_context.py index fde425e1..8285b89a 100644 --- a/powerline_shell/segments/kubecontext.py +++ b/powerline_shell/segments/kube_context.py @@ -8,8 +8,9 @@ class Segment(BasicSegment): def add_to_powerline(self): - kubecontext = os.environ.get("KUBECONFIG") - if kubecontext: - self.powerline.append(" kctx:%s " % os.path.basename(kubecontext), - self.powerline.theme.KUBECONFIG_FG, - self.powerline.theme.KUBECONFIG_BG) + kube_context = os.environ.get("KUBECONFIG") + if kube_context: + self.powerline.append(" kctx:%s " % os.path.basename(kube_context), + self.powerline.theme.KUBE_CONTEXT_FG, + self.powerline.theme.KUBE_CONTEXT_BG) + diff --git a/powerline_shell/themes/basic.py b/powerline_shell/themes/basic.py index 6163cab8..71e32f15 100644 --- a/powerline_shell/themes/basic.py +++ b/powerline_shell/themes/basic.py @@ -44,5 +44,6 @@ class Color(DefaultColor): TIME_FG = 8 TIME_BG = 7 - KUBECONFIG_FG = 14 - KUBECONFIG_BG = 8 + KUBE_CONTEXT_FG = 14 + KUBE_CONTEXT_BG = 8 + diff --git a/powerline_shell/themes/default.py b/powerline_shell/themes/default.py index b971c2fb..fa089ae2 100644 --- a/powerline_shell/themes/default.py +++ b/powerline_shell/themes/default.py @@ -75,8 +75,9 @@ class DefaultColor(object): TIME_FG = 250 TIME_BG = 238 - KUBECONFIG_FG = 38 - KUBECONFIG_BG = 239 + KUBE_CONTEXT_FG = 38 + KUBE_CONTEXT_BG = 239 + class Color(DefaultColor): """ diff --git a/powerline_shell/themes/gruvbox.py b/powerline_shell/themes/gruvbox.py index 5cfdaa7c..e5b9a03d 100644 --- a/powerline_shell/themes/gruvbox.py +++ b/powerline_shell/themes/gruvbox.py @@ -110,5 +110,6 @@ class Color(DefaultColor): TIME_FG = light2 TIME_BG = dark4 - KUBECONFIG_BG = neutral_blue - KUBECONFIG_FG = dark2 + KUBE_CONTEXT_FG = neutral_blue + KUBE_CONTEXT_BG = dark2 + diff --git a/powerline_shell/themes/solarized_dark.py b/powerline_shell/themes/solarized_dark.py index 4ceb6923..3f1dccb7 100644 --- a/powerline_shell/themes/solarized_dark.py +++ b/powerline_shell/themes/solarized_dark.py @@ -43,5 +43,6 @@ class Color(DefaultColor): TIME_FG = 15 TIME_BG = 10 - KUBECONFIG_FG = 7 - KUBECONFIG_BG = 2 + KUBE_CONTEXT_FG = 7 + KUBE_CONTEXT_BG = 2 + diff --git a/powerline_shell/themes/washed.py b/powerline_shell/themes/washed.py index bda6b8a4..19f06df1 100644 --- a/powerline_shell/themes/washed.py +++ b/powerline_shell/themes/washed.py @@ -43,5 +43,5 @@ class Color(DefaultColor): TIME_FG = 8 TIME_BG = 7 - KUBECONFIG_FG = 0 - KUBECONFIG_BG = 7 + KUBE_CONTEXT_FG = 0 + KUBE_CONTEXT_BG = 7 diff --git a/setup.py b/setup.py index 465fea26..87482e21 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( - name="powerline-shell-test", + name="powerline-shell", version="0.7.0", description="A pretty prompt for your shell", author="Buck Ryan", @@ -27,6 +27,6 @@ ], entry_points=""" [console_scripts] - powerline-shell-test=powerline_shell:main + powerline-shell=powerline_shell:main """, )