git trim -- 23.02.2023 %
Easy clean up branches from local that are old or already merged on remote.
$ git trim -s -p
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.
Easy clean up branches from local that are old or already merged on remote.
$ git trim -s -p
Recently I noticed some of the images on my site had GPS metadata info. Thats not very private! So I did some googling and found this solution.
$ exiftool -GPS*= $(fd -e jpg -e png -e jpeg)
I always forget how to upgrade my Pleroma servicer when a new version comes out so I’m writing it here. If you are unsure of what you are doing please consult the official docs.
My Pleroma instance: social.travisshears.xyz
Start by sshing into the server and switching to the pleroma user.
$ sudo su pleroma -s $SHELL
Then stop the server request the update, migrate the db and start it again.
$ ./bin/pleroma stop
$ ./bin/pleroma_ctl update
$ ./bin/pleroma_ctl migrate
$ ./bin/pleroma daemon
Boom new version!
Got a repo with sensitive data you don’t want to push to a remote server you don’t control? Have a NAS setup on our home network? Here is how to setup a folder on that NAS to act as a git remote.
*Step 1:
Change directorys to the NAS and clone the local folder with the –bare option.
$ cd /Volumes/travis/git
$ git clone --bare ~/.password-store
This creates /Volumes/travis/git/.password-store but without a working directory. Basically its just the /.git part of the repo.
Step 2:
Setup the NAS file path to be a git remote on the repo.
$ cd ~/.password-store
$ git remote add nas /Volumes/travis/git/travisshears.com.git
...
Step 3:
Done. Now jus push.
$ git push nas
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 10 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.30 KiB | 1.30 MiB/s, done.
I was doing some housekeeping on a Node.JS project today. Wanted to update all
the dependencies to their latest versions. At first I tried npm update
but
come to find out that is ment more for upgrading single packages and not
major versions. In the end after some googling I found
npm-check-updates.
To upgrade the dependencies of a project without installing anything else I ran:
$ npx npm-check-updates -u
It updated the package.json so it must be followed up by a:
$ npm i
Which will install the new packages and update the package-lock.json.
Who doesn’t want the cool “verified” badge in Gitlab.
coolness badge
To get this we must sign our commits via gpg.
Step 1: Figure out which key you are going to use
$ gpg --list-keys
pub rsa3072 2020-01-01 [SC] [expires: 2030-01-01]
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
uid [ultimate] Travis Shears <travis.shears@cool-company.com>
sub rsa3072 2020-01-01 [E] [expires: 2030-01-01]
pub rsa2048 2020-01-01 [SC] [expires: 2030-01-01]
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
uid [ultimate] Travis Shears <t@travisshears.com>
sub rsa2048 2020-01-01 [E] [expires: 2030-01-01]
In this case I’ll use key travis.shears@cool-company.com.
Step two: Configure git to sign commits with the gpg key
Edit your ~/.gitconfig to look something like this
[user]
name = Travis Shears
email = travis.shears@cool-company.com
signingkey = AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[commit]
gpgsign = true
We added the signingkey so git knows which key to use and we specified gpgsign so git knows we want to sign all commits.
Step three: Copy your public gpg key to clipboard
$ gpg --armor --export AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | pbcopy
You can also do it with the email of the key
$ gpg --armor --export travis.shears@cool-company.com | pbcopy
Step four: Paste your public gpg key into settings page of your favorite version control site, ex: Github, Gitlab, Source Hut.
Got a new Macbook Pro with the start of my new job and I love it. Except. It did not come with and english keyboard. Now every time I try to type the backslash (`) or tilde (~) instead I get “§” or “±” 😔. Lucky for me there are a bunch of people with the same issue.
This base command to remap the key is:
$ hidutil property --set '{"UserKeyMapping":
[{"HIDKeyboardModifierMappingSrc":0x700000064,
"HIDKeyboardModifierMappingDst":0x700000035}]
}'
but to make this survive a computer restart things get a little more complicated. For that you need you need a LaunchDaemon.
/Library/LaunchDaemons/org.custom.backslash-key-remap-fix.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.custom.backslash-key-remap-fix</string>
<key>ProgramArguments</key>
<array>
<string>/Users/travis.shears/projects/scripts/bin/backslash-key-remap-fix.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
</dict>
</plist>
/Users/travis.shears/projects/scripts/bin/backslash-key-remap-fix.sh
#/bin/sh -e
hidutil property --set '{"UserKeyMapping":
[{"HIDKeyboardModifierMappingSrc":0x700000064,
"HIDKeyboardModifierMappingDst":0x700000035}]
}'
sources:
Before changing laptops I backed up all my personal projects to my NAS. When I transfer them back the file modes got messed up and a git status returned this:
diff --git a/docker/Dockerfile b/docker/Dockerfile
old mode 100644
new mode 100755
diff --git a/lib/DeployTool/CLI.rakumod b/lib/DeployTool/CLI.rakumogpg --list-secret-keys --keyid-format LONG <EMAIL>d
old mode 100644
new mode 100755
diff --git a/lib/DeployTool/Config.rakumod b/lib/DeployTool/Config.rakumod
old mode 100644
new mode 100755
Git diff shell magic, thanks to Stanislav Khromov, to the rescue!
$ git diff -p -R --no-ext-diff --no-color \
| grep -E "^(diff|(old|new) mode)" --color=never \
| git apply
This command uses git diff and some clever grep logic to swap the file modes back to what git remembers them as.
I also converted the snippet to a shell script here
source: Stanislav Khromov’s blog
Just moved computers and thus moved my pass store. After importing my gpg keys, explained in this snippet, I had to trust them in order to stop the annoying warnings everytime I created a new password.