maartenjan.dev

Hi! I'm Maarten-Jan, a Software Engineer focused on Java, Kotlin, Event Sourcing, Kubernetes and of course Bash! I sometimes write down what I do.

Some random functions sitting in my .bashrc

In this short post, I'll share some semi-random functions I quite regularly use. I have them sitting in my .bashrc file for easy access.

When working on a project, I usually end up with a big list of already merged local branches. this script cleans that right up.

git-delete-merged-local-branches(){
  git branch --merged | grep -Ev "(^\*|^\+|master|main)" | xargs --no-run-if-empty git branch -d
}

When dealing with Kubernetes secrets base 64 decoding can be handy. For obvious reasons, one should not use a public website for decoding. I have a quick command for this I actually can remember:

decode(){
  echo "$1" | base64 --decode
}

A script to run on just recently downloaded Maven projects: download all the sources and Java docs. It can take a while, but having the sources and docs can be very useful.

mvn-deps() {
  mvn dependency:resolve-sources
  mvn dependency:resolve -Dclassifier=javadoc
}

For password creation, or anything else: generate a random string with a given length.

random-string() {
  re='^[0-9]+$'
  if ! [[ $1 =~ $re ]]; then
    echo "you should provide 1 number argument"!
  else
    tr -dc A-Za-z0-9 </dev/urandom | head -c $1 ; echo ''
  fi
}

What's my ip?

show-ip() {
  curl -4 icanhazip.com
}

That's it for now! Maybe someone has some use for these simple but useful functions.