Skip to content

Instantly share code, notes, and snippets.

@jherskow
Last active September 6, 2022 12:33
Show Gist options
  • Save jherskow/5e2144ca32b68107d96de6d5a977a1ca to your computer and use it in GitHub Desktop.
Save jherskow/5e2144ca32b68107d96de6d5a977a1ca to your computer and use it in GitHub Desktop.
Useful Shell Scripts
# print a line and then execute it. useful for composing scripts.
function peval() {
echo ">> $*"
eval $*
}
#grab path to project folder from git
function git_path() {
echo $(git rev-parse --show-toplevel)
}
# get the name of the repo you are in
function cur_service_name() {
echo $(basename $(git_path)) # take only the name of the folder from the path
}
# run k env by grabbing the current service name (works for hydra apps as well)
function kk() {
local service_name=$(cur_service_name)
local pwd=$(PWD) # take only the name of the service
if [ "$service_name" = "5rr_v2" ]; then
service_name="v2"
fi
if [[ "$pwd" =~ hydra ]]; then # hydras
local hydra_name=$(echo "$pwd" | sed 's/.*\/\(.*hydra\).*$/\1/')
local app_name=$(echo "$pwd" | sed 's/.*\/apps\/\([^\/]*\).*$/\1/')
local app_underscore=${app_name//-/_}
local service_name=$hydra_name".""$app_underscore"
fi
peval "k env $1 $service_name"
}
alias kt='kk test'
alias kl='kk local'
alias kd='kk kubernetes_dev'
alias kml='kk minikube_local'
alias kma='kk minikube_aws'
# open the jenkins deploy for the current repo (inclduing hydras)
function jen() {
if [ -n "$2" ]; then
local service_name="$2"
else
local service_name=$(cur_service_name) # take only the name of the service
local pwd=$(PWD)
fi
local base=""
local suf=""
case $1 in
d| dev)
local base="https://jenkins.fiverrdev.com/job/"
local suf="_kubernetes_dev/"
;;
p| prod)
local base="https://jenkins.fiverr-gw.com/job/"
local suf="_kubernetes_prod/"
;;
esac
if [ "$service_name" = "5rr_v2" ]; then # v2 has different naming
case $1 in
p| prod)
local service_name="fiverr_V2_FRONTEND_production/"
local suf=""
;;
esac
fi
if [[ "$pwd" =~ hydra ]]; then # hydras
local hydra_name=$(echo "$pwd" | sed 's/.*\/\(.*hydra\).*$/\1/')
local app_name=$(echo "$pwd" | sed 's/.*\/apps\/\([^\/]*\).*$/\1/')
local app_underscore=${app_name//-/_}
local service_name=$hydra_name"_""$app_underscore"
fi
peval "open $base$service_name$suf" # run the command - will open your default browser
}
alias jd='jen dev'
alias jp='jen prod'
# opens the github repo of the current service, showing the most recent commits
function repo() {
local pwd=$(PWD)
if [ -n "$1" ]; then
local service_name="$1"
else
local service_name=$(cur_service_name) # take only the name of the service
fi
if [[ "$pwd" =~ hydra ]]; then # hydras
local hydra_name=$(echo "$pwd" | sed 's/.*\/\(.*hydra\).*$/\1/')
local service_name=$hydra_name
fi
peval "open https://github.com/fiverr/$service_name/commits" # run the command - will open your default browser
}
# clone a service to your pc by name
function fget() {
peval "cd /Volumes/fiverr_dev"
peval "git clone git@github.com:fiverr/$1.git"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment