mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-08-09 11:17:44 +00:00
Incorporate utils.bash into each executable to help simplify packaging
for Linux and other platforms. This adds to PR #32 remove unused functions
This commit is contained in:
parent
8da629d98e
commit
b188f4da88
@ -93,7 +93,7 @@ This command will set up bash/zsh/fish completion scripts automatically.
|
|||||||
Since `kubectx`/`kubens` are written in Bash, you should be able to instal
|
Since `kubectx`/`kubens` are written in Bash, you should be able to instal
|
||||||
them to any POSIX environment that has Bash installed.
|
them to any POSIX environment that has Bash installed.
|
||||||
|
|
||||||
- Download the `kubectx`, `kubens` and `utils.bash` scripts.
|
- Download the `kubectx`, and `kubens` scripts.
|
||||||
- Either:
|
- Either:
|
||||||
- save them all to somewhere in your `PATH`,
|
- save them all to somewhere in your `PATH`,
|
||||||
- or save them to a directory, then create symlinks to `kubectx`/`kubens` from
|
- or save them to a directory, then create symlinks to `kubectx`/`kubens` from
|
||||||
|
17
kubectx
17
kubectx
@ -21,15 +21,6 @@
|
|||||||
set -eou pipefail
|
set -eou pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \
|
|
||||||
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")"
|
|
||||||
|
|
||||||
if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then
|
|
||||||
source "${SCRIPT_DIR}/utils.bash"
|
|
||||||
else
|
|
||||||
source "${SCRIPT_DIR}/../include/utils.bash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
KUBECTX="${HOME}/.kube/kubectx"
|
KUBECTX="${HOME}/.kube/kubectx"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@ -44,6 +35,14 @@ EOF
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_context() {
|
||||||
|
kubectl config view -o=jsonpath='{.current-context}'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_contexts() {
|
||||||
|
kubectl config get-contexts -o=name | sort -n
|
||||||
|
}
|
||||||
|
|
||||||
list_contexts() {
|
list_contexts() {
|
||||||
set -u pipefail
|
set -u pipefail
|
||||||
local cur="$(current_context)"
|
local cur="$(current_context)"
|
||||||
|
17
kubens
17
kubens
@ -21,15 +21,6 @@
|
|||||||
set -eou pipefail
|
set -eou pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \
|
|
||||||
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")"
|
|
||||||
|
|
||||||
if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then
|
|
||||||
source "${SCRIPT_DIR}/utils.bash"
|
|
||||||
else
|
|
||||||
source "${SCRIPT_DIR}/../include/utils.bash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
KUBENS_DIR="${HOME}/.kube/kubens"
|
KUBENS_DIR="${HOME}/.kube/kubens"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@ -53,6 +44,14 @@ current_namespace() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_context() {
|
||||||
|
kubectl config view -o=jsonpath='{.current-context}'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_namespaces() {
|
||||||
|
kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}'
|
||||||
|
}
|
||||||
|
|
||||||
namespace_file() {
|
namespace_file() {
|
||||||
local ctx="${1}"
|
local ctx="${1}"
|
||||||
echo "${KUBENS_DIR}/${ctx}"
|
echo "${KUBENS_DIR}/${ctx}"
|
||||||
|
11
utils.bash
11
utils.bash
@ -1,11 +0,0 @@
|
|||||||
current_context() {
|
|
||||||
kubectl config view -o=jsonpath='{.current-context}'
|
|
||||||
}
|
|
||||||
|
|
||||||
get_contexts() {
|
|
||||||
kubectl config get-contexts -o=name | sort -n
|
|
||||||
}
|
|
||||||
|
|
||||||
get_namespaces() {
|
|
||||||
kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}'
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user