Homebrew

Install homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Create bundle:

brew bundle dump

Install bundle:

brew bundle install

Useful tools

Dotfiles

Install dotfiles: TBD

Java (jenv)

jenv helps managing multiple Java versions.

Shell config

Add path to your .zshrc:

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

(optional) support for mvn a.o.

ensure that JAVA_HOME is correct:

$ jenv enable-plugin export

make Maven aware of the Java version in use (and switch when your project does):

$ jenv enable-plugin maven

Adding new Java versions

Install new Java version via brew (e.g. brew install adoptopenjdk11).

List installed versions:

$ /usr/libexec/java_home -V

Add new version:

$ jenv add <jdk_path>

vim

Install vim-plug:

sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
       https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
Note
Install plugins by :PlugInstall. See more on https://github.com/junegunn/vim-plug

iterm2

Installation

Install iterm2 via homebrew:

brew install --cask iterm2

Color theme

Download theme:

curl -O https://raw.githubusercontent.com/MartinSeeler/iterm2-material-design/master/material-design-colors.itermcolors

Import theme in iterm2: Profiles > Colors > Presets…​

Additional settings

Skipping words, go to start/end

Change the key mapping preset to Natural Text Editing in order to skip words or go to start/end of line: Profiles > Keys > Key Mappings > Presets…​

zsh

ohmyzsh

Installation

$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Plugins

zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

List of Plugins:

git
brew
docker
history
macos
zsh-autosuggestions
zsh-syntax-highlighting

Styling / Theme

Clone theme:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Change zsh theme in .zshrc by adding/replacing: ZSH_THEME="powerlevel10k/powerlevel10k"

Additional config

# 1password ssh agent
export SSH_AUTH_SOCK=~/.1password/agent.sock

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# nvm
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

# gem
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH

export PATH="/opt/homebrew/opt/ruby/bin:$PATH"

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

export PATH="/usr/local/opt/libpq/bin:$PATH"

# pnpm
export PNPM_HOME="/Users/scas/Library/pnpm"
export PATH="$PNPM_HOME:$PATH"

Mac Settings

Finder

  • Default folder

  • Airdrop

Docks

  • Delay

  • Animation

  • Spacer

Keyboard

  • disable spelling correction

Siri

  • Voice Feedback

  • Type to siri

Desktop

  • Hot corners

AWS

Enabling autocompletion for AWS CLI

As I am often using autocompletion, here is how to enable it for the AWS CLI:

autoload -Uz compinit && compinit
autoload bashcompinit && bashcompinit
complete -C aws_completer aws

Switching between AWS profiles

If you are using multiple AWS profiles for different AWS accounts, you can switch between them by setting the AWS_PROFILE and temporary credentials environment variable. Therefor, you can use the following script:

awsp script
#!/bin/bash

if [ -z "$1" ]; then  echo "Usage: awsp profilename"; return; fi
   exists="$(aws configure get aws_access_key_id --profile "$1")"
   role_arn="$(aws configure get role_arn --profile "$1")"
   if [[ -n $exists || -n $role_arn ]]; then
       if [[ -n $role_arn ]]; then
           source_profile="$(aws configure get source_profile --profile "$1")"
           if [[ -n $source_profile ]]; then
              profile=$source_profile
           else
              profile=$1
           fi
           mfa_serial="$(aws configure get mfa_serial --profile "$profile")"
           
           unset AWS_REGION
           region="$(aws configure get region --profile "$1")"
           if [[ -z "$region" ]]; then
                region="$(aws configure get region --profile "$profile")"
           fi

           echo "Assuming role $role_arn using profile $profile"
           if [[ -n $mfa_serial ]]; then
                if command -v op > /dev/null 2>&1; then
                    echo "Retrieving otp via 1password"
                    mfa_token=$(op item get <AWS User Item> --otp)  
                else
                    echo "Please enter your MFA token for $mfa_serial:"
                    read mfa_token
                fi
               JSON="$(aws sts assume-role --profile="$profile" --role-arn "$role_arn" --role-session-name session-"$profile" --serial-number "$mfa_serial" --token-code "$mfa_token")"
           else
               JSON="$(aws sts assume-role --profile="$profile" --role-arn "$role_arn" --role-session-name session-"$profile")"
           fi

           aws_access_key_id="$(echo "$JSON" | jq -r '.Credentials.AccessKeyId')"
           aws_secret_access_key="$(echo "$JSON" | jq -r '.Credentials.SecretAccessKey')"
           aws_session_token="$(echo "$JSON" | jq -r '.Credentials.SessionToken')"
       else
           aws_access_key_id="$(aws configure get aws_access_key_id --profile "$1")"
           aws_secret_access_key="$(aws configure get aws_secret_access_key --profile "$1")"
           aws_session_token=""
       fi
       export AWS_REGION=$region
       export AWS_DEFAULT_PROFILE=$1
	   export AWS_PROFILE=$1
       export AWS_ACCESS_KEY_ID=$aws_access_key_id
       export AWS_SECRET_ACCESS_KEY=$aws_secret_access_key
       [[ -z "$aws_session_token" ]] && unset AWS_SESSION_TOKEN || export AWS_SESSION_TOKEN=$aws_session_token

       echo "Switched to AWS Profile: $1";
       aws configure list
   fi
Note
1password is used to retrieve the MFA token via the op command, so you have to replace the <AWS User Item> with the name of your AWS user item in 1password. If you don’t have op installed, a prompt will ask you for the MFA token.

Gitlab

Creating merge requests (the cool way)

The following script will extract the jira story out of the branch name and create a merge request with a title and description. The target branch is selected via fzf by listing all origin branches. After creating the merge request it will be opened in the browser for convenience.

Note
You need to have glab and fzf installed.
Example 1. Create merge request

#!/bin/bash

pwd=$(pwd)

current_branch=$(cd "$pwd" && git rev-parse --abbrev-ref HEAD) current_jira_story=$(echo "$current_branch" | grep -Eo 'CAIPI-[0-9]+')

read -p "Please enter jira task [current: $current_jira_story]:" jira_story jira_story="${jira_story:-$current_jira_story}"

current_mr_title=$(git log -1 --pretty=%B) read -p "Please enter title [current: $current_mr_title]:" mr_title mr_title="[$jira_story] - ${mr_title:-$current_mr_title}"

target_branch=$((cd "$pwd" && git branch -r) | fzf | xargs | sed 's/^origin\///')

glab mr create --title "$mr_title" --description "[$jira_story]" --target-branch "$target_branch" --remove-source-branch --draft --web

Save this script in a bin folder and make it executable or integrate it as a function in your .zshrc or .bashrc. In my case I have a ~/bin folder in my path and stored the script in glmr:

glmr

Creating merge request (develop → main)

The following script will create a merge request from develop to main with a title and description:

Example 2. Create merge request

#!/bin/bash

glab mr create \ --title "Merge develop into main" \ --description "chore: merge develop into main" \ --source-branch "develop" \ --target-branch "main" \ --web

Idea

Starting idea from command line

If you want to open a specific project from the command line in a cool way, you can use the following command:

#!/bin/bash

find ~/Workspace -maxdepth 3 -type d -name .idea | sed 's|/.idea$||' | fzf | xargs idea

Note
Fuzzy finder is required and you have to replace the workspace directory (~/Workspace) with your root directory.

When you use an alias or create a script in a bin folder it will look like this:

oidea