Fly, Penguin!

I blog so I don't forget.

Essentials

4 minute read

Let’s see with which software & configs I cannot go without. Some of this is also in my dotfiles repo.

Version: 2023-03-14

Essential software

Roughly sorted by priority, but really all of them used daily. So essential.

Nice-to-have softwawre

Mostly mac, Windows not exactly my thing.

obscure things, maybe interesting

shell aliases

# see http://is.gd/h9AB6z
# rough guide to remember:
# (g)it (l)og + (s)hort, (c)ontinuous, (l)ong, (d)iff, ...
# (g)it (d)iff + (), (c)cached, (f)iles, ...
# (g)it (s)status
# etc.
alias gco="git checkout"
alias gri="git rebase --interactive"
alias gra="git rebase --abort"
alias grc="git rebase --continue"
alias  gp="git push"
alias gpf="git push --force"
alias  gs="git status"
alias  gd="git              diff"
alias gds="git --no-pager   diff   --stat"
alias gdc="git              diff   --cached"
alias gls="git --no-pager   log    -n 40 --pretty=format:'%C(yellow)%h %ad%Creset %s %Cblue[%cn]%Cred%d%Creset' --decorate --date=short"
alias glv="git --no-pager   log    -n 30 --pretty=format:'%C(yellow)%h %ad%Creset %s %Cblue[%cn]%Cred%d%Creset%+b' --decorate --date=short"
alias glc="git              log          --pretty=format:'%C(yellow)%h %ad%Creset %s %Cblue[%cn]%Cred%d%Creset' --decorate --date=short"
alias glvc="git             log          --pretty=format:'%C(yellow)%h %ad%Creset %s %Cblue[%cn]%Cred%d%Creset%+b' --decorate --date=short"
alias gll="git log --pretty=format:'%C(yellow)%h %C(yellow reverse)%aD%Creset %s %Cblue[%cn]%Cred%d%Creset' --decorate --numstat"
alias gld="git log --pretty=format:'%C(yellow reverse)%h%Creset %C(yellow reverse)%ad%Creset %C(white reverse)%s%Creset %Cblue[%cn]%C(red reverse)% d%Creset' --decorate --date=short -p"
alias glf="git log --stat --oneline --pretty='%n%C(yellow reverse)%h%C(reset) %C(yellow)%ad%C(red)%d%C(reset) %C(white)%s%C(reset) %C(blue)[%cn]%C(reset)'"
alias gpb="git push --set-upstream origin \$(git rev-parse --abbrev-ref HEAD)"
# from here: https://stackoverflow.com/a/38404202/902327
alias git-branch-clean="git fetch -p && git branch -vv | awk '/: gone]/{print \$1}' | xargs git branch -d"
alias git-branch-clean-f="git fetch -p && git branch -vv | awk '/: gone]/{print \$1}' | xargs git branch -D"

# shell (aliases using -G are zsh specific!!)
alias -g   S=' | sort'
alias -g WCL=' | wc -l'

# ssh - force password auth
alias ssp="ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no"

# ls
unalias ls
alias ls="ls --color=auto"
alias  ll="ls -lh"
alias  la="ls -lha"
alias dir="ls -lh"

# kubernetes
alias       kd="k describe"
alias     kdds="k describe daemonset"
alias       kg="k get"
alias      kgi="k get ingress"
alias     kgpv="k get pv"
alias     kgds="k get daemonset"
alias     kdel="k delete"
alias       kc="k config"

shell functions

## GIT - *SO* convenient :)

# gitignore service :)
# try "giti list" or "giti python >> .gitignore"
function giti() { curl -L -s https://www.gitignore.io/api/$@ ;}

## PYTHON RELATED

# $1 - optional - work on WHAT. default: current path name
wo() { if [ -z "$1" ] ; then workon "$(basename "$PWD")" ; else workon "$1" ; fi }

# $1 - (OPTIONAL) name of virtual environment
cvi() {
  local ENVNAME=${1:-$(basename $PWD)}
  mkvirtualenv -p $(which python3) "$ENVNAME"
}

# $1 - (OPTIONAL) name of virtual environment
cvv() {
  local ENVNAME=${1:-$(basename $PWD)}
  python3 -m venv --prompt "$ENVNAME" .venv
  # mimic 'mkvirtualenv' behavior and activate automatically
  source .venv/bin/activate
}

## SSH STUFF

# force ssh login using a specific secret key from a file
# $1 - key file
# $2..n - parameters for ssh
ssi() {
  if [ -z "$2" ] ; then
    echo "USAGE: ssi filename ssh_param [ssh_param ...]"
    return
  fi
  local IDFILE="$1"
  [ ! -f "$IDFILE" ] && IDFILE="$HOME/.ssh/$IDFILE"
  if [ ! -f "$IDFILE" ] ; then
    echo "File '$IDFILE' not found. Looked in: ['.', '~/.ssh']"
    return
  else
    echo "Using ID file: $IDFILE"
  fi
  shift
  ssh -i "$IDFILE" -o IdentitiesOnly=yes "$@"
}

# create hash for ssh (public) keys, mainly for AWS
# see here: https://serverfault.com/a/603983, https://is.gd/OURGbO
 ssh-key-hash() {
   if [ -z "$1" ]; then
     echo "USAGE: ssh-key-hash (PUB_)KEY_FILE"
     return
   fi
   if grep -q "OPENSSH PRIVATE KEY" "$1" ; then
     echo "ERROR: OPENSSH PRIVATE KEYs are not supported (yet)."
     echo "To convert the file IN PLACE to openSSL RSA format, use the command below."
     echo "AGAIN: this WILL CHANGE the saved file!"
     echo ""
     echo "    ssh-keygen -pN \"\" -m pem -f \"$1\""
     echo ""
   elif grep -q "RSA PRIVATE KEY" "$1" ; then
     # we have a private key :)
     echo "Found RSA private key."

     echo -n "PUBkey  MD5  openssl:     "
     openssl pkey -in "$1" -pubout -outform DER | openssl md5 -c \
       | grep --color=never -Eo '(([a-z0-9]{2}:)+[a-z0-9]{2})'

     echo -n "PRIVkey SHA1 openssl:     "
     openssl pkcs8 -in "$1" -inform PEM -outform DER -topk8 -nocrypt \
       | openssl sha1 -c 2>/dev/null \
       | grep --color=never -Eo '(([a-z0-9]{2}:)+[a-z0-9]{2})'

     echo -n "PRIVkey MD5 openssl:      "
     openssl rsa -in "$1" -pubout -outform DER \
       | openssl md5 -c \
       | grep --color=never -Eo '(([a-z0-9]{2}:)+[a-z0-9]{2})'
   else
     # we have a public key
     echo -n "PUBkey MD5 AWS hash (AWS):   "
     ssh-keygen -f "$1" -e -m PKCS8 \
      | openssl pkey -pubin -outform DER \
      | openssl md5 -c
    echo -n "PUBkey MD5 ssh-keygen hash:  "
    ssh-keygen -E md5 -lf "$1" | grep --color=never -Eo '(([a-z0-9]{2}:)+[a-z0-9]{2})'
  fi
}