Skip to content

Instantly share code, notes, and snippets.

@arshamalh
Last active August 9, 2024 09:15
Show Gist options
  • Save arshamalh/cdd749ae03e3f73a45833050423c1d77 to your computer and use it in GitHub Desktop.
Save arshamalh/cdd749ae03e3f73a45833050423c1d77 to your computer and use it in GitHub Desktop.
My .zshrc config file including tools and aliases
autoload -Uz compinit && compinit
eval "$(starship init zsh)"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
if [ $commands[oc] ]; then
source <(oc completion zsh)
compdef _oc oc
fi
export PATH=$PATH:$HOME/.composer/vendor/bin
export PATH=$PATH:$HOME/apache-maven-3.9.8/bin
export NVM_DIR="$HOME/.nvm"
echo "Hi Champion! 🔥"
# Decode an input argument from a base64 string
bxd() {
echo $1 | base64 --decode
}
# Encode an input argument to a base64 string
bxe() {
echo $1 | base64
}
# cfg file would be lile username=...\n port=...\n host=...\n you can read the full version on man command or github docs
alias cvpn1="sudo openfortivpn -c ~/etc/vpn.cfg -p 'blahblah'"
alias cvpn2="sudo openconnect -u <username> <host>:<port>"
alias olp="oc login -u <username> -p '$(bxd <encoded_password>)' --server='<server_address>'"
alias dub="docker-compose up --build -d"
alias ocp="oc port-forward"
alias ts="date -jf %s"
alias run="go run main.go"
alias start="go run main.go start"
alias golnt="golangci-lint run --config=.golangci.yml ./..."
gomake() {
mkdir $1
cd $1
echo "package main\n\nfunc main() {\n\t\n}" | cat > main.go
go mod init $1
# Add some conditional commands for making the repo right here
code .
}
struct() {
# I for exclude, d for only directories, L for level of going inside, C for colorizing
tree $1 -dCL $2 -I vendor
# pip3 install git+https://github.com/innofang/code-counter.git
cocnt search -v $1 --ignore vendor
code $1
}
oce() {
oc exec $1 -it -- sh
}
ocpc() {
## TODO: read service exposed port and forward it, for now, it is expected that user pass the port
POD=$(oc get pods -l app=$1 -o jsonpath='{.items[0].metadata.name}')
oc port-forward $POD $2:$2
}
ocg() {
oc get $1 -l app=$2
}
ocl() {
SERVER_ADDRESS_1=https://host:port
SERVER_ADDRESS_2=https://host:port
# GLCIT => Gitlab CI Token
GLCIT_STAGING=<token>
GLCIT_004=<token>
if [[ $1 == "staging" ]]; then
oc login --token=${GLCIT_STAGING} --server=${SERVER_ADDRESS_1}
elif [[ "$1" == "004" ]]; then
oc login --token=${GLCIT_004} --server=${SERVER_ADDRESS_2}
oc project custom-project-004
elif [[ "$1" == "024" ]]; then
echo "024 token is not still provided"
# oc login --token=${GITLAB_CI_STAGING} --server=${SERVER_ADDRESS_2}
else
# Not a registered command
fi
}
ip() {
echo "External: "
curl icanhazip.com
echo "Internal: "
ipconfig getifaddr en0
}
mybranches() {
git branch -r | xargs -L1 git --no-pager show -s --oneline --author="$(git config user.name)"
}
unusedSecrets() {
envSecrets=$(oc get pods -o jsonpath='{.items[*].spec.containers[*].env[*].valueFrom.secretKeyRef.name}' | xargs -n1)
envSecrets2=$(oc get pods -o jsonpath='{.items[*].spec.containers[*].envFrom[*].secretRef.name}' | xargs -n1)
volumeSecrets=$(oc get pods -o jsonpath='{.items[*].spec.volumes[*].secret.secretName}' | xargs -n1)
pullSecrets=$(oc get pods -o jsonpath='{.items[*].spec.imagePullSecrets[*].name}' | xargs -n1)
tlsSecrets=$(oc get ingress -o jsonpath='{.items[*].spec.tls[*].secretName}' | xargs -n1)
SASecrets=$(oc get secrets --field-selector=type=kubernetes.io/service-account-token -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -n1)
diff \
<(echo "$envSecrets\n$envSecrets2\n$volumeSecrets\n$pullSecrets\n$tlsSecrets\n$SASecrets" | sort | uniq) \
<(oc get secrets -o jsonpath='{.items[*].metadata.name}' | xargs -n1 | sort | uniq)
}
# labeling and annotating resources which need to be helmified
# deprecated, but good for learning purposes.
ochelm() {
# $1 is resource type
# $2 is resource name
# $3 is namespace
oc label --overwrite $1 $2 app.kubernetes.io/managed-by=Helm
oc annotate --overwrite $1 $2 meta.helm.sh/release-name=$2
oc annotate --overwrite $1 $2 meta.helm.sh/release-namespace=$3
}
# checkout to main, remove a the current branch from local and remote, and update main
grm() {
currentBranch=$(git branch --show-current)
echo "💫 Checkout to main"
git checkout main
echo "🔥 Removing $currentBranch locally..."
git branch -D $currentBranch
echo "🔥 Removing $currentBranch remotly..."
git push origin -d $currentBranch
echo "🏹 Pull latest updates"
git pull
}
note() {
echo "- $1" >> "note.md"
}
gotcover() {
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
rm coverage.out
}
cpp() {
g++ -Wall -std=c++14 main.cpp -o main
./main
rm main
}
lower() {
echo "$1" | tr '[:upper:]' '[:lower:]'
}
listag() {
oc get istag | grep months | cut -d " " -f1 > file.txt
code file.txt
}
rmistag() {
cat file.txt | xargs -n 1 -I % oc delete istag %
rm file.txt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment