Snippets are one of my favorite parts of programming. The shear endless depth of command line tricks and customizations is so exciting! Here is a collection I maintain for myself to comeback to.

Also navigable by list of snippet types here.

per company git config -- 03.06.2022 %

Started new job this week and I wanted to have a seprate email on my work related repos then my personal ones. Cool thing is git supports conditional config file includes!


# per-user git config
name = Travis Shears
email =

[includeIf "gitdir:~/company-x/"]
  path = .gitconfig-company-x


# Company X spefic git config
name = Travis Shears
email =

Now any commits made under the directory ~/company-x will use the email and not my personal email.


\- [ git ]

ios xcode simulator dark mode -- 02.05.2022 %

Recently I was testing an IOS app on my wifes phone. The UI was completly broken. Turns out she had dark mode enabled. That led me down the path of adding dark mode support to the app. Which is testable via the Xcode simulator if you know how to enable it.

Command + Shift + A: Toggles dark mode


\- [ xcode ]

bash extract file name -- 17.03.2022 %

Comparing the following shows how to use basename to extract just the file name from a full path.

$ for file in ./content/**/*.md ; do echo $file ; done | head -10

$ for file in ./content/**/*.md ; do file=$(basename $file) && echo $file ; done
\- [ sh, bash ]

s3 move folder / rename folder -- 17.03.2022 %

Working on my Oblastle game today. In an effort to standardize the way I store images for the game in S3 I needed to move all the files with key image-service/images/oblastle/flags/ to /image-service/images/oblastle/flag/.

Here is how I did it:

$ aws s3 mv s3://travisshears.images/image-service/images/oblastle/flags/ s3://travisshears.images/image-service/images/oblastle/flag/ --recursive --profile personal


\- [ s3, aws ]

s3 copy recursive -- 03.03.2022 %

Where were you –recursive when I was hacking around with for file * ; do aws s3 cp $file…..

$ aws s3 cp ./ s3://travisshears.images/image-service/images/oblastle/context/ --profile personal --recursive
upload: ./us-ak.jpg to s3://travisshears.images/image-service/images/oblastle/context/us-ak.jpg
upload: ./us-co.jpg to s3://travisshears.images/image-service/images/oblastle/context/us-co.jpg
upload: ./us-ar.jpg to s3://travisshears.images/image-service/images/oblastle/context/us-ar.jpg
upload: ./us-ca.jpg to s3://travisshears.images/image-service/images/oblastle/context/us-ca.jpg
upload: ./us-al.jpg to s3://travisshears.images/image-service/images/oblastle/context/us-al.jpg
upload: ./us-ct.jpg to s3://travisshears.images/image-service/images/oblastle/context/us-ct.jpg

–recursive is an easy win to upload a bunch of files to s3.

\- [ aws, s3 ]

imagemagik .png to .jpg with white background -- 03.03.2022 %

Working on some .png map files today. I needed to covert them to small .jpg’s for uses in Oblastle. Problem being by default the transparent part fills into to black. Here is how to make it white:

$ ls

$ for file in *.png ; do magick mogrify -format jpg -resize '500' -background white -flatten  $file; done

$ ls

$ rm ./*.png

The important bit being -background white -flatten.


\- [ imagemagik ]

lower case string -- 13.02.2022 %

TR is a Unix until to translate characters I recently learned about as part of this awk snippet.

$ echo "TRAVIS" | tr '[:upper:]' '[:lower:]'


\- [ tr ]

awk last column -- 13.02.2022 %

My first awk snippet! Today I needed to get all the file extensions in directory for a blog post I’m writing.

I solved it with:

$ fd . --type f | awk -F"." '{print $(NF)}' |  tr  '[:upper:]' '[:lower:]' | sort | uniq | pbcopy

Break down

fd . –type f, lists all the files in a directory recursively.

awk -F"." ‘{print $(NF)}’, the -F"." tells awk to split columns on “.”. The ’{print $(NF)’} tells awk to print the last column. Normally you do something like ’{print $2}’ to print the second column.

tr ‘[:upper:]’ ‘[:lower:]’, tr is a Unix until to translate characters. In this case all upper case letters will be translated to lower case. I’ve created a seprate snippet for it as well.

sort | uniq, a classic combo sorts the results then gets rid of duplicates.

pbcopy, anther common one for me pipes the result into the clipboard.


\- [ awk ]

close the garden -- 24.01.2022 %

Started playing with garden cli today. After playing around with the local kubernetes deployments I found it annoying it left some system containers running when I was finished. To get rid of these run the following from the project directory (the dir with

$ garden delete env

$ garden plugins local-kubernetes uninstall-garden-services
\- [ garden-cli ]

remove brew packages -- 18.01.2022 %

Trying to clean up my laptop a bit today by removing some unused brew packages.

Normally I would use brew list but this also list packages that are dependicies. Here is a way to list the top level packages:

$ brew leaves

$ brew uninstall neomutt newsboat travisshears/tap/deploy_tool weechat


\- [ brew ]