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:
Jon Mosco 2018-03-15 11:53:31 -04:00
parent 8da629d98e
commit b188f4da88
4 changed files with 21 additions and 34 deletions

View File

@ -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
them to any POSIX environment that has Bash installed.
- Download the `kubectx`, `kubens` and `utils.bash` scripts.
- Download the `kubectx`, and `kubens` scripts.
- Either:
- save them all to somewhere in your `PATH`,
- or save them to a directory, then create symlinks to `kubectx`/`kubens` from

17
kubectx
View File

@ -21,15 +21,6 @@
set -eou pipefail
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"
usage() {
@ -44,6 +35,14 @@ EOF
exit 1
}
current_context() {
kubectl config view -o=jsonpath='{.current-context}'
}
get_contexts() {
kubectl config get-contexts -o=name | sort -n
}
list_contexts() {
set -u pipefail
local cur="$(current_context)"

17
kubens
View File

@ -21,15 +21,6 @@
set -eou pipefail
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"
usage() {
@ -53,6 +44,14 @@ current_namespace() {
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() {
local ctx="${1}"
echo "${KUBENS_DIR}/${ctx}"

View File

@ -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}'
}