2121
2222set -euf -o pipefail
2323
24+ # Stack Overflow: https://stackoverflow.com/a/246128/1122665
25+ SOURCE=" ${BASH_SOURCE[0]} "
26+ while [[ -h " $SOURCE " ]]; do
27+ PROG_DIR=" $( cd -P " $( dirname " $SOURCE " ) " > /dev/null 2>&1 && pwd ) "
28+ SOURCE=" $( readlink " $SOURCE " ) "
29+ [[ $SOURCE != /* ]] && SOURCE=" $PROG_DIR /$SOURCE "
30+ done
31+ PROG_DIR=" $( cd -P " $( dirname " $SOURCE " ) " > /dev/null 2>&1 && pwd ) "
32+
2433readonly PROG_NAME=' kubectl tmux-exec'
2534
2635declare -ra KUBECTL_SHORT_OPTS=(
@@ -71,6 +80,7 @@ Examples:
7180 ${PROG_NAME} -f - /bin/bash # read from stdin
7281
7382Options:
83+ -V, --version: Print the version information
7484 -c, --container='': Container name. If omitted, the first container in the pod will be chosen
7585 -i, --stdin=true: Pass stdin to the container (deprecated, since it's enabled by default)
7686 -t, --tty=true: Stdin is a TTY (deprecated, since it's enabled by default)
@@ -88,6 +98,15 @@ Use "kubectl options" for a list of global command-line options (applies to all
8898EOF
8999}
90100
101+ function print_version() {
102+ local version_file=" ${PROG_DIR} /../VERSION"
103+ if [[ -f " ${version_file} " ]]; then
104+ cat " ${version_file} "
105+ else
106+ echo " unknown"
107+ fi
108+ }
109+
91110function check_required_executables() {
92111 for exe in " $@ " ; do
93112 if ! which " ${exe} " 2>&1 > /dev/null; then
@@ -137,8 +156,8 @@ function array_contains() {
137156
138157function main() {
139158 local opts
140- opts=$( ggetopt -o hitdc :l:f:" $( printf ' %s:' " ${KUBECTL_SHORT_OPTS[@]} " ) " --long \
141- help,stdin,tty,detach,container:,selector:,remain-on-exit,select-layout:,file:," $( printf ' %s:,' " ${KUBECTL_LONG_OPTS[@]} " ) " ," $( printf ' %s,' " ${KUBECTL_NOARG_LONG_OPTS[@]} " ) " -- " $@ " )
159+ opts=$( ggetopt -o hVitdc :l:f:" $( printf ' %s:' " ${KUBECTL_SHORT_OPTS[@]} " ) " --long \
160+ help,version, stdin,tty,detach,container:,selector:,remain-on-exit,select-layout:,file:," $( printf ' %s:,' " ${KUBECTL_LONG_OPTS[@]} " ) " ," $( printf ' %s,' " ${KUBECTL_NOARG_LONG_OPTS[@]} " ) " -- " $@ " )
142161 eval set -- $opts
143162
144163 local selector
@@ -155,6 +174,10 @@ function main() {
155174 usage
156175 exit 0
157176 ;;
177+ -V|--version)
178+ print_version
179+ exit 0
180+ ;;
158181 -c|--container)
159182 shift
160183 container_name=" $1 "
0 commit comments