Skip to content

zkdev/ultimate-hacky-terminal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 

Repository files navigation

Ultimate Hacky Terminal for Mac

I don't want to work without these

Homebrew

Install Homebrew, the "missing package manager for macOS"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

iTerm2

Install iTerm2

ZSH Shell

Install the ZSH Shell and make sure it is your default shell.
brew install zsh
chsh -s /bin/zsh

Install the Oh-My-Zsh Framework on top.

Here are some usefull plugins for Oh-My-Zsh

Install fonts and themes

Tools and Programs

  • kubectl
    necessary for kubernetes

  • kubectx
    fast switch between your kubectls

  • vundle
    the vim package manager

  • fzf
    useful search tool

  • YouCompleteMe
    basically best "IDE"

  • Zsh syntax highlighting
    smart syntax highlighter for shell

  • bpytop
    personal recommendation when it comes to system monitoring

  • dive
    tool for exploring a docker image and its layer contents

  • watch
    executes a program periodically, showing output fullscreen

Suggestions

  • dockly
    clear and handy docker container manager

  • k9s
    pretty much dockly for k8s

  • httpie
    universal HTTP REST client, better than postman!

  • neovim
    basically the future of vim - use vim if you spend serious time inside the terminal

  • fx
    handy json viewer

  • jq
    lightweight and flexible command-line JSON processor

  • hacker-quotes
    why not

  • cpulimit
    limit cpu usage of a process, helpful in diverse ways

  • step-cli
    inspect JWT tokens

  • colima
    Container Runtime without unnecessary UI (I'm looking at you DockerDesktop)

Alias

  • alias watch='watch ' # required to make alias work with watch
  • alias sudo='sudo '
  • alias k=kubectl
  • alias ktx=kubectx
  • alias kns=kubens
  • alias ll="ls -color -ahl"
  • alias ports="lsof -i -P -n | grep LISTEN"
  • alias nano=nvim
  • alias p3="python3"
  • alias gpgkeys="gpg --list-secret-keys --keyid-format LONG"
  • alias trim="sed -i 's/[ \t]*$//'"
  • alias ggrep="git grep -n"
  • alias dc=docker-compose
  • alias pip=noglob pip
  • alias prep-dive='sudo ln -sf ~/.colima/docker.sock /var/run/docker.sock'

Git Alias

  • git config --global alias.cp cherry-pick
  • git config --global alias.pr pull --rebase

Fix gnupg

Errors regarding gnupg might occurre once you want to sign your commits using gpg keys.

  • brew upgrade gnupg
  • brew link --overwrite gnupg
  • brew install pinentry-mac
  • echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
  • killall gpg-agent

Conditional Git Config

Load Git config depending on repo path

[user]
    name = zk
    email = [email protected]
    signingkey = foobar
    gpgsign = true
[alias]
    cp = cherry-pick
    pr = pull --rebase
[includeIf "gitdir:/Users/zk/dev/github.com/**"]
    path = /Users/zk/.gitconfig-zk
[includeIf "gitdir:/Users/zk/dev/github.work/**"]
    path = /Users/zk/.gitconfig-work

Macro

Kill Docker

function whaling() {
  ps ax|grep -i docker|egrep -iv 'grep|com.docker.vmnetd'|awk '{print $1}'|xargs kill
}

Force restart Logitech Mouse Daemon

function mouse() {
  ps ax|grep -i Options.app/Contents/Support/LogiMgrDaemon.app/Contents/MacOS/LogiMgrDaemon|egrep -iv 'grep --color=auto --exclude-dir'|awk '{print $1}'|xargs kill
}

JWT Decoder

function jwtd() {
    if [[ -x $(command -v jq) ]]; then
         jq -R 'split(".") | .[0],.[1] | @base64d | fromjson' <<< "${1}"
         echo "Signature: $(echo "${1}" | awk -F'.' '{print $3}')"
    fi
}

Misc

Display the current kubectx as iTerm2 Badge:

  • install iTerm2 Shell Integration: wget https://iterm2.com/misc/install_shell_integration.sh
  • to prevent misconfiguration adapt the script do directly detect zsh as your shell (line 10)
  • execute install script (chmod +x ...)
  • append following function to .zshrc right after source iterm_shell_integration
function iterm2_print_user_vars() {
  iterm2_set_user_var kube_context $(kubectl config current-context 2>/dev/null)
  iterm2_set_user_var kube_ns $(kubectl config view --minify --output 'jsonpath={..namespace}'; echo)
}
  • go to iTerm > Preferences > Profiles > General and set \(user.kube_context)\n\(user.kube_ns) as badge
  • I recommand to re-init zsh the the very end of .zshrc

Install GnuCoreUtils with g-prefix

  • brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt grep
    If you want to use them without g-prefix, adjust your PATH and MANPATH (add before anything else).
PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"

About

My personal configuration for zsh shell and iTerm.

Resources

Stars

Watchers

Forks