Last active
March 15, 2018 12:27
-
-
Save pgerber/7a2a6083a1075135f5eee17a97ea84b3 to your computer and use it in GitHub Desktop.
OpenShift bashrc Command Collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS1='[$(sed -r "/^current-context: / { s/[^:]+: (toco-)((n)ice(-))?([^/]+)\/.*/\3\4\5/; /test|^n-master$/ s/.*/\[\e[38;5;2m\]&/; s/.*/\[\e[38;5;1m\]&/; q }; d" ~/.kube/config)\[\e[39m\]]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
p() | |
{ | |
case $# in | |
0) | |
oc projects -q | sed -n 's/^toco-nice-// p' | |
;; | |
1) | |
oc project "toco-nice-$1" && oc get pods | |
;; | |
*) | |
echo "ERROR: too many arguments" >&2 | |
echo "Usage: ${FUNCNAME[0]} [INSTALLATION]" >&2 | |
return 1 | |
;; | |
esac | |
} | |
__autocomplete_p() | |
{ | |
COMPREPLY=() | |
if [ $COMP_CWORD -eq 1 ]; then | |
local project | |
for project in $(oc projects -q 2>/dev/null); do | |
local typed=${COMP_WORDS[1]} | |
if [[ "$project" =~ ^toco-nice-"$typed" ]]; then | |
COMPREPLY+=("${project#toco-nice-}") | |
fi | |
done | |
fi | |
} | |
complete -F __autocomplete_p p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment