Created
December 1, 2023 15:02
-
-
Save thikade/f59b2750a8aae3ec3127f573865dc5a2 to your computer and use it in GitHub Desktop.
bashrc
This file contains hidden or 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
# User specific aliases and functions | |
HISTTIMEFORMAT="%d/%m/%y %T " | |
HISTSIZE=1000000 | |
HISTFILESIZE=1000000 | |
# source ~/bin/switch.sh | |
alias ll="ls -al" | |
alias sw=switch | |
# oc shortcuts | |
alias op="oc project" | |
alias oga="oc get all" | |
alias ogd="oc get deploy" | |
alias ogdc="oc get dc" | |
alias ogp="oc get pods" | |
alias ogpr="oc get pods | grep Running" | |
alias ogpw="oc get pods -owide" | |
alias ogpv="oc get pv" | |
alias ogpvc="oc get pvc" | |
alias ogapp="oc -n openshift-gitops get app" | |
alias ogr="oc get rolebinding -o wide" | |
alias ogn="oc get nodes" | |
alias ognw="oc get nodes -o wide| cut -c1-200" | |
alias op="oc project" | |
alias ocd="oc describe" | |
alias ops="oc get namespaces" | |
alias oge="oc get events --sort-by=.lastTimestamp" | |
alias oged="oc get events --sort-by=.lastTimestamp -n default" | |
alias k9s="k9s --logoless" | |
# helm shortcuts | |
alias hl="helm list" | |
alias hcm="helm-check-manifests.sh" | |
# git shortcuts | |
alias gs="git status" | |
alias gc="git commit" | |
alias gd="git diff" | |
alias gb="git branch" | |
alias gr="git remote" | |
alias ga="git add" | |
alias gr="git remote" | |
alias gco="git checkout" | |
alias gpu="git push" | |
alias gpl="git pull --ff-only" | |
#alias gl="git log --oneline --graph --decorate --pretty='format:%C(auto)%h %as %d %s'" | |
alias gl='git log --oneline --graph --decorate --pretty='\''format:%C(auto)%h %as %an %d %s'\''' | |
alias glc='git log --oneline --graph --decorate --pretty='\''format:%C(auto)%h %as %an %d %s'\'' --left-right --boundary ' | |
alias gld="git log -p --graph --decorate" | |
alias glv="git log --name-only --graph --decorate" | |
alias gitc='git -c http.sslVerify=false' | |
alias virc="vi ~/.bashrc; source ~/.bashrc" | |
# context handling | |
alias lc="oc config get-contexts" | |
alias uc="export KUBECONFIG=\$HOME/.kube/config-combined; oc config use-context" | |
alias ocl="export KUBECONFIG=\$HOME/.kube/config-combined && oc login -u $K8S_USER" | |
alias ocdev="uc dev; if ! oc whoami &>/dev/null; then ocl; fi; refreshNS" | |
alias octest="uc test; if ! oc whoami &>/dev/null; then ocl; fi; refreshNS" | |
alias ocprod="uc prod; if ! oc whoami &>/dev/null; then ocl; fi; refreshNS" | |
alias oclab="uc lab; if ! oc whoami &>/dev/null; then ocl; fi; refreshNS" | |
function get_namespaces { | |
NSLIST=$(oc get ns -o custom-columns="NAME:.metadata.name" --no-headers) | |
echo "$NSLIST" | |
} | |
function refreshNS { | |
complete -W "$(get_namespaces)" op | |
echo "List of namespaces refreshed for cluster: $(op)" | |
} | |
refreshNS | |
alias ogevery="oc api-resources --verbs=list --namespaced -o name| sort |xargs -n1 oc get --show-kind --ignore-not-found " | |
source ~/bin/oc_completion.sh | |
source ~/bin/helm_completion.sh | |
function ogall { | |
# get all names as a bash array | |
NAMES=( $(oc api-resources \ | |
--namespaced \ | |
--verbs list \ | |
-o name \ | |
| grep -v packagemanifest ) \ | |
) | |
# Now join names into single string delimited with comma | |
# Note *, not @ | |
IFS=, | |
NAMES="${NAMES[*]}" | |
COUNT="${#NAMES[*]}" | |
unset IFS | |
echo "found $COUNT CRs" | |
# --show-kind is enabled implicitly | |
oc get --ignore-not-found "$NAMES" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment