Tag: cli

  • Hugo: index vs. _index

    I renamed ./content/about.md to ./content/index.md, and poof! … all tags gone, all blog postings gone.

    What?!

    It makes sense, if you think about it.

    index.md is a special file, which automatically marks the directory it is in as a so-called “leaf-bundle“, which then makes all the files and directories and all directories become “irrelevant” – a leaf bundle has no children.

    So, what I actually wanted to do was to rename it to _index.md, which marks ./content as what it is – a branch bundle.

    Or in short: don’t put index.md files in ./content. If you want to update your home page, use _index.md.

    Sources:

  • Unix path too long for domain socket

    I wanted to SSH into a machine, and I got a very weird error message: unix_listener: path "/Users/me/.ssh/sockets/myservername_ansible@000-servername001.subdomain.main-domain-in-use.de-22.gFthlK8q5qNkrXW4" too long for Unix domain socket.

    This seems to be the culprit:

    • I am “persisting” SSH connections in my SSH config folder, precisely here: $HOME/.ssh/sockets
    • The configuration for this is: Host ... ControlMaster auto ControlPath ~/.ssh/sockets/%r@%h-%p ControlPersist 600
    • Before opening a connection, SSH looks for an existing socket in $HOME/.ssh/sockets, and if found re-uses it
    • There is a 100-something length limit for “path to a socket” under Mac OS
    • This path length limit was overshot with that 106-character long path

    Solution: Shorten the path by using %C instead of %r@%h-%p:

    Host ...
      ControlMaster auto
      ControlPath ~/.ssh/sockets/%C
    

    That is it.

    Sources:

  • Fix tmux on Mac

    I started tmux. Every time i pressed <BACKSPACE> got got a … space. This felt wrong, so the internets had a solution ready.

    This is it:

    mkdir -p $HOME/.config/tmux
    echo 'set-option default-terminal "screen-256color"' > $HOME/.config/tmux/tmux.conf
    

    Apparently the Mac OS ncurses database on Mac does not contain the settings for tmux’s default value of tmux-256color, but the ones for screen.

    Sources (including some more ways to fix it):

  • AWS – Forced MFA and the CLI

    Let’s say you want to force every user to enable MFA for AWS IAM accounts. Sure, that is possible.

    Now there’s just one problem: This does not work on the CLI. The credentials in $HOME/.aws/credentials are “static”, they never have a aws:MultiFactorAuthPresent flag attached.

    That would mean that CLI users are either not forced to use MFA, or they just can’t use the CLI any more. Which would – for example – break terraform.

    There’s a solution though. Just get a token using aws sts get-session-token --serial-number ... --token-code ....

    To ease this process (cause it’s really annoying) I created this function, which you can add to your .bashrc or .zshrc (or equivalent shell startup script).

    Enjoy.

    Update 2026-09-03: source available on github

  • Extract parts of a git repo as new one

    Situation: You have a repository with a subdirectory my/repo/part, which became large and own-project-worthy. You can copy the files into a new repo, but you’ll lose all git history.

    What would be just perfect is: From all commits ever made in this repository, …

    • only keep the parts of all commits which concern files under ./my/repo/part/**
    • remove the path prefix ./my/repo/part/.

    So, basically, rewrite and filter all git commits.

    There’s an app for that: git-filter-repo. And that’s how you use it:

    # clone the repository parallel to the existing one
    git clone git@github.com:me-and/my-repo fool-around-here
    cd fool-around-here
    
    # remove all other files except the ones you want
    # (yup, it's that easy)
    git-filter-repo --path my/repo/part
    
    # move all files to the repository root
    git-filter-repo --subdirectory-filter my/repo/part
    
    # set a new origin URL
    git remote set-url origin git@github.com:me-and/my-new-empty-prepared-repo
    
    # push.
    git push
    

    The git history has been rewritten 1984-style. For git it has always been exactly like this now.

  • jq snippets

    Delete any object which contains a "keyname": "keyvalue" pair anywhere in the JSON:

    cat x.json| jq 'del(..|select(objects and .keyname == "keyvalue"))'
    

    If keyname contains a dash (“-“), use one of those notations:

    cat x.json | jq 'del(..|select(objects and .["key-name"] == "keyvalue"))'
    cat x.json | jq 'del(..|select(objects and ."key-name" == "keyvalue"))'
    

    Delete all objects anywhere that contain a certain key:

    cat x.json | jq 'del(..|select(objects and .key?)'
    

    Delete a certain key from all objects everywhere:

    cat x.json | jq 'del(..|.response?)'
    

    Useful sources:

  • GOPATH and GOROOT

    go has some unique concepts, one of them is a system-wide (user-wide) central go directory where things “happen” (e.g. modules being downloaded, etc.). For example, if you perform hugo mod get you essentially perform go mod get, which then downloads required modules … into your $GOPATH. Or $GOROOT/something, I really don’t quite get it, and I don’t care unless it stops working. Which it did.

    You often read “Just look into $GOPATH and see if it’s there”. Unfortunately I never set the value so there is no environment variable. The default of $HOME/go does not exist on my mac. Now what?

    Thanks to 0x434d53 I now know to do this, which prints the values used by go:

    go env
    
  • Completely delete teams on a Mac

    If teams is acting up sometimes (read: almost always) the only way to stop it is by deleting it completely. Microsoft has an answer on Microsoft answers on how to do it, I put it into a script. Here it is.

    This might not be absolutely everything though, cause it still remembered my account which I used last time.

    #!/usr/bin/env bash
    
    # source: microsoft
    # https://answers.microsoft.com/en-us/msteams/forum/all/how-to-completely-remove-teams-from-mac/2499239d-d491-43cb-a9c1-acbee7223b8d
    
    
    # $1 - full path to file / dir to delete
    delete_teams_file() {
        DELETE_ME=$1
        if [[ -d $1 ]] ; then
            echo -n "DELETE      $DELETE_ME ... "
            rm -rf "$DELETE_ME"
            echo "done."
        else
            echo "Not found - $DELETE_ME"
        fi
    }
    
    set -euo pipefail
    
    # prepare sudo entry
    echo "Prepare sudo ..."
    sudo echo "sudo prep successful :)"
    
    DELETE_BASE="$HOME/Library/Caches/com.microsoft."
    for DELETE_DIR in teams teams.shipit ; do
        delete_teams_file "${DELETE_BASE}${DELETE_DIR}"
    done
    
    DELETE_BASE="$HOME/Library/Application Support/Microsoft/Teams"
    delete_teams_file "$DELETE_BASE"
    
    sudo rm -rf "/Applications/Microsoft Teams.app"
    
    echo "All done."
    
  • Hugo migration experiences

    The goal was to switch to hugo as a static blogging engine. My reasons were:

    • super easy hosting (planned was S3 & CloudFront, it is now Netlify – which is insanely easy and I don’t need my homepage-builder image any longer)
    • no database any more, everything in git, including git push deployments
    • super quick page loads

    While trying this I found a couple of drawbacks, mainly …

    • way less themes than WordPress (well, big surprise), in by far not the same quality
    • theme switching is, if it gets improved a lot, still a PITA (right now let’s just not talk about it)
    • it is insanely hard to debug your page if something does not work
    • currently no comment engine

    It is a double-edged sword. During the migration process I often wished for a quick WYSIWYG “new blog post” editor like in WordPress, at the same time I loved the security git gave me – it’s nearly impossible to lose images, posts, whatever in your blog, it will always be “somewhere” in git. But there are already ways to get around that (it seems forestry.io is exactly that).

    So, here we are now. The state is:

    • currently, no comments available
    • cause I hate ads and don’t want to introduce ad-supported Disqus, and I also don’t want to pay for it
    • the plan is to add a self-hosted commenting engine though
    • all posts transferred, including all images (as far as I can tell)
    • a somewhat final theme (50:50 that this will be changed again)

    … and all of this took WAY longer that I expected.

  • Convert RAW files on a Mac using “sips”

    I recently needed to convert Canon *.CR2 RAW files to JPEG. What I did not know is that a Mac brings all you need preinstalled in form of a CLI tool called sips.

    for i in *.CR2; do
      sips -s format jpeg $i --out "${i%.*}.jpg"
    done
    

    Also: man sips works just fine for more information.

    Source: Coderwall