[
  {
    "path": ".github/workflows/release.yml",
    "content": "name: release\non:\n  release:\n    types: [published]\njobs:\n  main:\n    runs-on: ubuntu-latest\n    env:\n      ARCHIVE_NAME: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}\n    steps:\n      - name: download-source\n        run: curl -sL \"${{ github.event.release.tarball_url }}\" >\"$ARCHIVE_NAME\".tar.gz\n      - name: unzip-source\n        run: mkdir \"$ARCHIVE_NAME\" && tar -xzf \"$ARCHIVE_NAME\".tar.gz -C \"$ARCHIVE_NAME\" --strip-components 1\n      - name: check-version\n        run: '[[ $(\"$ARCHIVE_NAME\"/k1s -v) = \"${{ github.event.release.tag_name }}\" ]]'\n      - name: clean-source\n        run: rm -rf \"$ARCHIVE_NAME\"/{.github,assets}\n      - name: create-archive\n        run: tar -czf \"$ARCHIVE_NAME\".tar.gz \"$ARCHIVE_NAME\"\n      - name: create-checksum\n        id: create-checksum\n        run: |\n          sha256sum \"$ARCHIVE_NAME\".tar.gz >checksum.txt\n          echo \"::set-output name=checksum::$(cut -d ' ' -f 1 checksum.txt)\"\n      - name: upload-archive\n        id: upload-archive\n        uses: actions/upload-release-asset@v1\n        with:\n          upload_url: ${{ github.event.release.upload_url }}\n          asset_path: ${{ env.ARCHIVE_NAME }}.tar.gz\n          asset_name: ${{ env.ARCHIVE_NAME }}.tar.gz\n          asset_content_type: application/gzip\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n      - name: upload-checksum\n        id: upload-checksum\n        uses: actions/upload-release-asset@v1\n        with:\n          upload_url: ${{ github.event.release.upload_url }}\n          asset_path: checksum.txt\n          asset_name: checksum.txt\n          asset_content_type: text/plain\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n      - name: trigger-formula-upgrade\n        run: |\n         curl -s -X POST \\\n           -H \"Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}\" \\\n           -H \"Accept: application/vnd.github.v3+json\" \\\n           https://api.github.com/repos/weibeld/homebrew-tap/dispatches \\\n           -d '\n             {\n               \"event_type\": \"upgrade-formula\",\n               \"client_payload\": {\n                 \"formula\": \"k1s\",\n                 \"url\": \"${{ steps.upload-archive.outputs.browser_download_url }}\",\n                 \"sha256\": \"${{ steps.create-checksum.outputs.checksum }}\"\n               }\n             }\n           '\n      - if: failure() \n        name: abort\n        run: |\n          curl -s -X DELETE \\\n            -H \"Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}\" \\\n            -H \"Accept: application/vnd.github.v3+json\" \\\n            https://api.github.com/repos/${{ github.event.repository.full_name }}/releases/${{ github.event.release.id }}\n          curl -s -X DELETE \\\n            -H \"Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}\" \\\n            -H \"Accept: application/vnd.github.v3+json\" \\\n            https://api.github.com/repos/${{ github.event.repository.full_name }}/git/refs/tags/${{ github.event.release.tag_name }}\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2020 Daniel Weibel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# k1s: The world's simplest Kubernetes dashboard\n\nA minimalistic Kubernetes dashboard implemented with 50 lines of Bash code.\n\n![Screencast](https://raw.githubusercontent.com/weibeld/k1s/master/assets/screencast-1.gif)\n\n## Contents\n\n1. [Introduction](#introduction)\n1. [Installation](#installation)\n1. [Usage](#usage)\n1. [Examples](#examples)\n\n## Introduction\n\n### What is it?\n\nA minimalistic Kubernetes dashboard showing the current state of Kubernetes resources of a specific type in real-time. The entire tool consists merely of a Bash script with about 50 lines of code.\n\n### What is it not?\n\nIt's not a production-grade dashboard with many features. It's mainly intended for educational purposes.\n\n### How does it work?\n\nWith a lot of highly condensed Bash scripting. [This article](https://itnext.io/the-worlds-simplest-kubernetes-dashboard-k1s-4246e03191df) explains how it works in detail.\n\n## Installation\n\n### On macOS\n\n```bash\nbrew install weibeld/tap/k1s\n```\n\n### On other systems\n\nSimply download the [`k1s`](k1s) script, make it executable, and move it to any directory in your `PATH`.\n\nFor example:\n\n```bash\nwget https://raw.githubusercontent.com/weibeld/k1s/master/k1s\nchmod +x k1s\nmv k1s /usr/local/bin\n```\n\n### Dependencies\n\nThe `k1s` script depends on the following tools:\n\n#### [`jq`](https://stedolan.github.io/jq/)\n\n| OS    | Installation              |\n|-------|---------------------------|\n| macOS | `brew install jq`         |\n| Linux | `sudo apt-get install jq` |\n\n#### [`watch`](https://linux.die.net/man/1/watch)\n\n| OS    | Installation               |\n|-------|----------------------------|\n| macOS | `brew install watch`       |\n| Linux | — _(installed by default)_ |\n\n\n#### [`curl`](https://curl.haxx.se/)\n\n| OS    | Installation               |\n|-------|----------------------------|\n| macOS | — _(installed by default)_ |\n| Linux | sudo apt-get install curl  |\n\n#### [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/)\n\n| OS    | Installation                                                        |\n|-------|---------------------------------------------------------------------|\n| macOS | `brew install kubernetes-cli`                                       |\n| Linux | _See https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/_ |\n\n## Usage\n\nk1s runs directly on your local machine and it uses the usual [kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) configuration on your machine. That means, it connects to the same cluster that also `kubectl` connects to by default.\n\nThe command-line interface is as follows:\n\n```bash\nk1s [<namespace>] [<resource-type>]\n```\n\nBoth arguments are optional. The default values are:\n\n| Argument          | Default value |\n|-------------------|---------------|\n| `<namespace>`     | `default`     |\n| `<resource-type>` | `pods`        |\n\nThe `<namespace>` argument may be set to any valid namespace in the cluster. In addition, `<namespace>` may be set to `-` to imply \"all namespaces\" for namespaced resource types and \"no namespace\" for non-namespaced resource types (e.g. ClusterRoles).\n\n> You can find out which resource types are namespaced or non-namespaced with `kubectl api-resources --namespaced=true|false`.\n\nThe `<resource-type>` argument may be set to any valid resource type name (including their singular, plural and short forms).\n\n> You can list all supported resource type names with `kubectl api-resources`.\n\nTo exit the dashboard, type _Ctrl-C_.\n\n## Examples\n\nBelow is an example usage scenario for k1s. It uses multiple instances of k1s for observing what's going on under the hood when scaling a Deployment:\n\n![Example application](https://raw.githubusercontent.com/weibeld/k1s/master/assets/screencast-2.gif)\n\n> Note how during the rolling update, you can observe how the replica count of the Deployment always stays within a certain range. You can influence this range with the [`maxSurge` and `maxUnavailable`](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment) settings in the Deployment specification.\n\nTo recreate the above example, launch three instances of k1s in separate terminal windows (or in different [tmux](https://github.com/tmux/tmux/wiki) panes, as shown above):\n\n```bash\nk1s default deployments\n```\n\n```bash\nk1s default replicasets\n```\n\n```bash\nk1s default pods\n```\n\nThen, create a Deployment:\n\n```bash\nkubectl create deployment dep1 --image=nginx\n```\n\nScale the Deployment:\n\n```bash\nkubectl scale deployment dep1 --replicas=10\n```\n\nPatch the Deployment with a new container image, which causes a rolling update:\n\n```bash\nkubectl patch deployment dep1 -p '{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"nginx\",\"image\":\"nginx:1.19.0\"}]}}}}'\n```\n\n> You can also manually edit the Deployment with `kubectl edit deployment dep1`.\n\nFinally, delete the Deployment:\n\n```bash\nkubectl delete deployment dep1\n```\n\n### Advanced usage scenarios\n\nHere's a list of more advanced usage scenarios contributed by users of k1s:\n\n- [**mjbright/k1s-scenarios**](https://github.com/mjbright/k1s-scenarios) by Mike Bright\n\n> If you want to have your work added, file an issue, or directly make a pull request with your link added to this list.\n"
  },
  {
    "path": "assets/screencast-1.cast",
    "content": "{\"version\": 2, \"width\": 84, \"height\": 21, \"timestamp\": 1593185131, \"env\": {\"SHELL\": \"/usr/local/bin/bash\", \"TERM\": \"xterm-256color-italic\"}}\n[0.657895, \"o\", \"$ \"]\n[1.101685, \"o\", \"k\"]\n[1.235786, \"o\", \"1\"]\n[1.496861, \"o\", \"s \"]\n[1.897668, \"o\", \"\\r\\n\"]\n[1.91724, \"o\", \"Loading.\"]\n[2.030647, \"o\", \".\"]\n[2.138282, \"o\", \".\"]\n[2.243864, \"o\", \".\"]\n[2.348929, \"o\", \".\"]\n[2.57038, \"o\", \"\\u001b[?1049h\\u001b[1;23r\\u001b(B\\u001b[m\\u001b[4l\\u001b[?7h\\u001b[39;49m\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[H\\u001b[2J\\u001b(B\\u001b[0;1m\\u001b[36m ____ ____ ____\\r\\u001b[2d||\\u001b[33mk\\u001b[36m |||\\u001b[33m1\\u001b[36m |||\\u001b[33ms\\u001b[36m ||  \\u001b[39;49mKubernetes Dashboard\\r\\u001b[3d\\u001b[36m||__|||__|||__||  \\u001b[39;49mNamespace: default\\r\\u001b[4d\\u001b[36m|/__\\\\|/__\\\\|/__\\\\|  \\u001b[39;49mResources: pods\\u001b[23;84H\\u001b(B\\u001b[m\"]\n[3.026397, \"o\", \"\\r\\u001b[6ddep1-679646f769-6mvw8 \\u001b[32mRunning\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[4.847726, \"o\", \"\\r\\u001b[7ddep1-679646f769-dlfc8 \\u001b[33mPending\\r\\u001b[8d\\u001b[39;49mdep1-679646f769-4pr49 \\u001b[33mPending\\u001b[23;84H\"]\n[4.848158, \"o\", \"\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[4.957132, \"o\", \"\\r\\u001b[9ddep1-679646f769-xstqh \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.069276, \"o\", \"\\u001b[7;23H\\u001b[33mNonReady\\u001b[9;23HNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.180257, \"o\", \"\\r\\u001b[10ddep1-679646f769-lvc4t \\u001b[33mPending\\r\\u001b[11d\\u001b[39;49mdep1-679646f769-q88hw \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.291331, \"o\", \"\\r\\u001b[12ddep1-679646f769-ppxt2 \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.398926, \"o\", \"\\u001b[8;23H\\u001b[33mNonReady\\r\\u001b[13d\\u001b[39;49mdep1-679646f769-srnt9 \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.51378, \"o\", \"\\r\\u001b[14ddep1-679646f769-9kxmj \\u001b[33mPending\\r\\u001b[15d\"]\n[5.514223, \"o\", \"\\u001b[39;49mdep1-679646f769-g7k79 \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.629058, \"o\", \"\\u001b[10;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.741583, \"o\", \"\\r\\u001b[16ddep1-679646f769-bptnv \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.853425, \"o\", \"\\r\\u001b[17ddep1-679646f769-tjr26 \\u001b[33mPending\\u001b[23;84H\"]\n[5.853706, \"o\", \"\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[5.965097, \"o\", \"\\r\\u001b[18d\"]\n[5.965282, \"o\", \"dep1-679646f769-c2zhv \\u001b[33mPending\\r\\u001b[19d\\u001b[39;49mdep1-679646f769-xhf4x \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[6.07627, \"o\", \"\\u001b[13;23H\\u001b[33mNonReady\\r\\u001b[20d\\u001b[39;49mdep1-679646f769-8648p \\u001b[33mPending\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[6.184427, \"o\", \"\\u001b[11;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[6.293423, \"o\", \"\\u001b[12;23H\"]\n[6.293573, \"o\", \"\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[6.520265, \"o\", \"\\u001b[14;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[6.629172, \"o\", \"\\u001b[16;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[6.772947, \"o\", \"\\u001b[15;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[6.889021, \"o\", \"\\u001b[18;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[7.004074, \"o\", \"\\u001b[17;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[7.114631, \"o\", \"\\u001b[19;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[7.223945, \"o\", \"\\u001b[20;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[8.23783, \"o\", \"\\u001b[7;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[9;23H\"]\n[8.23801, \"o\", \"\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[8.39273, \"o\", \"\\u001b[12;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[8.505807, \"o\", \"\\u001b[14;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[15;23H\"]\n[8.506057, \"o\", \"\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[8.642491, \"o\", \"\\u001b[13;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[8.757216, \"o\", \"\\u001b[8;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[9.098919, \"o\", \"\\u001b[16;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[9.21307, \"o\", \"\\u001b[18;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[9.322855, \"o\", \"\\u001b[17;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[9.541535, \"o\", \"\\u001b[10;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[20;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[9.771465, \"o\", \"\\u001b[11;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[9.883156, \"o\", \"\\u001b[19;23H\\u001b[32mRunning\\u001b[39;49m\\u001b(B\\u001b[m\\u001b[K\\u001b[23;84H\"]\n[12.566988, \"o\", \"\\u001b[13;23H\\u001b[33mNonReady\\u001b[20;23HNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[12.682312, \"o\", \"\\u001b[11;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[12.797111, \"o\", \"\\u001b[19;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.018158, \"o\", \"\\u001b[16;23H\\u001b[33mNonReady\\u001b[18;23H\"]\n[13.01841, \"o\", \"NonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.128622, \"o\", \"\\u001b[12;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.239701, \"o\", \"\\u001b[14;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.348012, \"o\", \"\\u001b[10;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.45917, \"o\", \"\\u001b[7;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.571527, \"o\", \"\\u001b[9;23H\\u001b[33mNonReady\\u001b[15;23HNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.684304, \"o\", \"\\u001b[17;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.796256, \"o\", \"\\u001b[8;23H\\u001b[33mNonReady\\u001b[23;84H\\u001b[39;49m\\u001b(B\\u001b[m\"]\n[13.909609, \"o\", \"\\r\\u001b[20d\\u001b[J\\u001b[23;84H\"]\n[14.12678, \"o\", \"\\r\\u001b[11d\"]\n[14.127052, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[14.23544, \"o\", \"\\r\\u001b[15d\"]\n[14.235671, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[14.343304, \"o\", \"\\r\\u001b[12d\"]\n[14.343614, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[14.796269, \"o\", \"\\r\\u001b[15d\"]\n[14.796494, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[14.911517, \"o\", \"\\r\\u001b[15d\\u001b[J\\u001b[23;84H\"]\n[15.569182, \"o\", \"\\r\\u001b[11d\"]\n[15.569546, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[16.129254, \"o\", \"\\r\\u001b[11d\"]\n[16.129508, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[16.800396, \"o\", \"\\r\\u001b[9d\"]\n[16.800663, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[17.914649, \"o\", \"\\r\\u001b[8d\"]\n[17.91496, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[19.708182, \"o\", \"\\r\\u001b[8d\"]\n[19.708397, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[19.931705, \"o\", \"\\r\\u001b[8d\\u001b[M\\u001b[23;84H\"]\n[20.042911, \"o\", \"\\r\\u001b[7d\"]\n[20.043268, \"o\", \"\\u001b[M\\u001b[23;84H\"]\n[20.271227, \"o\", \"\\r\\u001b[7d\\u001b[J\\u001b[23;84H\"]\n"
  },
  {
    "path": "k1s",
    "content": "#!/bin/bash\n\n[[ \"$1\" = -v || \"$1\" = --version ]] && { echo \"0.1.2\"; exit; }\nfor d in jq watch curl kubectl; do which \"$d\" >/dev/null || { echo \"Missing dependency: $d\"; exit 1; }; done\nns=${1:-default}; res=${2:-pods}\n\nc() { echo -e \"\\033[$1m\"; }\ncc() { echo -e \"\\033[$1;1m\"; }\n\nprintf Loading && while true; do printf . && sleep 0.1; done &\n\nset -o pipefail\npath=$(kubectl get \"$res\" \"$([[ \"$ns\" = - ]] && echo --all-namespaces || echo -n=$ns)\" -v 6 2>&1 >/dev/null | grep GET | tail -n 1 | sed -n 's#.*https://[^/]*\\([a-z0-9/.-]*\\).*#\\1#p')\npid=$?\nkill -9 \"$!\" && wait \"$!\" 2>/dev/null\n[[ \"$pid\" -ne 0 ]] && echo -e \"\\nInvalid resource type: $res\" && exit 1\n[[ $(echo -n \"${path//[^\\/]}\" | wc -c) -lt 5 ]] && ns=-\nres=${path##*/}\n\nexec 3< <(kubectl proxy -p 0)\nport=$(head -n 1 <&3 | sed 's/.*:\\([0-9]\\{4,5\\}\\).*/\\1/')\n\nfile=$(mktemp)\ncat <<EOF >\"$file\"\n$(cc 36) ____ ____ ____\n||$(cc 33)k$(cc 36) |||$(cc 33)1$(cc 36) |||$(cc 33)s$(cc 36) ||  $(cc 0)Kubernetes Dashboard$(cc 36)\n||__|||__|||__||  $(cc 0)Namespace: $ns$(cc 36)\n|/__\\|/__\\|/__\\|  $(cc 0)Resources: $res$(c 0)\n\nEOF\n\ncurl -N -s \"http://localhost:$port$path?watch=true\" |\n  while read -r event; do\n    name=$(jq -r '.object.metadata.name' <<<\"$event\")\n    case \"$res\" in\n    pods)\n      phase=$(jq -r '.object.status.phase' <<<\"$event\")\n      is_ready=$(jq -r 'if .object.status | has(\"conditions\") then .object.status.conditions[] | if select(.type==\"Ready\").status==\"True\" then \"1\" else \"\" end else \"\" end' <<<\"$event\")\n      is_scheduled=$(jq -r 'if .object.status | has(\"conditions\") then .object.status.conditions[] | if select(.type==\"PodScheduled\").status==\"True\" then \"1\" else \"\" end else \"\" end' <<<\"$event\")\n      [[ \"$is_scheduled\" && ! \"$is_ready\" ]] && info=NonReady || info=$phase\n      [[ \"$info\" = Running ]] && info=$(c 32)$info$(c 0) || info=$(c 33)$info$(c 0) ;;\n    deployments|replicasets|statefulsets)\n      spec=$(jq -r '.object.spec.replicas' <<<\"$event\")\n      stat=$(jq -r '.object.status.readyReplicas // 0' <<<\"$event\")\n      [[ \"$stat\" = \"$spec\" ]] && info=\"$(c 32)($stat/$spec)$(c 0)\" || info=\"$(c 33)($stat/$spec)$(c 0)\"\n      [[ \"$stat\" = \"0\" ]] && info=\"$(c 31)($stat/$spec)$(c 0)\" ;;\n    esac\n    case $(jq -r .type <<<\"$event\") in\n      ADDED) echo \"$name $info\" >>\"$file\" ;;\n      MODIFIED) sed -i.bkp \"s/^$name .*$/$name ${info//\\//\\\\/}/\" \"$file\" ;;\n      DELETED) sed -i.bkp \"/^$name .*$/d\" \"$file\";;\n    esac\n  done &\n\nwatch -ctn 0.1 cat \"$file\"\n"
  }
]