Skip to content

maxkagamine/dotfiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

maxkagamine's dotfiles

bash  |  git  |  wsl  |  unraid  |  mkvtoolnix  | ⚙ misc utils  |  sweetroll  |  more…

Behold, GNU Stow: the mod manager for your Linux home directory! Anyone who's used Vortex or MO2 to mod games like Skyrim will find this familiar: mod (dot) files are organized into separate folders, and the mod manager (stow) combines them into the game (home) directory using symlinks.

As Stow doesn't (yet) support pre/post-install hooks, I'm emulating it by placing Makefiles in the mod directories and including them from the main Makefile. This keeps mods self-contained with any needed package install steps etc., and also allows mods to depend on other mods, with Make automatically figuring out which mods need to be installed and in what order:

Dependency graph

Best part about this setup is it doesn't require any frameworks, dotfile managers, or YAML files. Just run make.

Applies the convention of loading configuration files from a directory to bashrc: after setting some common aliases and such, sources every file in ~/.config/bashrc.d/. This way the other mods can put their stuff in e.g. bashrc.d/git.sh rather than one big file as is traditional. (The system-wide /etc/profile already does this with /etc/profile.d/*.)

(Psst: if you want to change your ls colors, my file might be an easier starting-off point than --print-database. I spent the time formatting it so you don't have to.)

Git aliases and aliases (including my favorite: the alias alias, git alias) + the "gg" function I use so much I wrote an article about it, and of course what would be a Max Kagamine system without a myriad of Skyrim references (brace yourself).

Oh and empty string is git status:

Mukashi mukashi (Once upon a time)...
git status is too long,” Max thought as he sat at his desk.
So with the magic of git config --global, it became git s.
...But that was too long.
So he aliased it to gs in his bashrc; just two letters, see?
But these two, too, were too long!
So he dropped the 's', just g, now, short as can be.
But even one letter 'twas one letter too long!
And so it became, the shortest git status of all:
Empty string!

True story. This is a trick I learned a long time ago: using PROMPT_COMMAND (or a precmd hook) to compare the last history entry to that which was seen the previous time the prompt was shown, as hitting enter at an empty prompt will run the prompt command again, but the last history number will be the same. Side effect is hitting Ctrl+C (but not Ctrl+U or Alt+Shift+#) at a prompt will trigger git status, too.

Also, check out git-branch-fzf, my awesome fzf-powered interactive branch switcher with keyboard shortcuts to toggle remote branches, delete branches (including remote and even the current branch!), and to fetch the latest of a branch before switching.

wsl

For "Tamriel," my main machine running the Windows Subsystem for Linux, because I can't computer without a command line but Windows is life (at least until Bethesda releases Skyrim: Chrome OS Edition).

This Alt+V keybind to paste Windows paths as Linux paths should be useful to any WSL users. (unclip is an alias for xsel -bo, for which I've written a WSL shim that forwards clipboard access to PowerShell, which lets commands like npx serve that aren't WSL-aware copy things to your Windows clipboard).

Using Yubikey for GPG & SSH in WSL

In the past, I was using wsl2-ssh-pageant which uses socat to replace the gpg-agent socket with one that runs an exe that bridges Gpg4win. The bridge itself worked well (with a small fix), but despite my best efforts I could never get the socket shenanigans to work reliably.

In the end that was too much of a hassle, so I switched to using usbipd-win which connects the Yubikey directly to Linux. So far, this has proved much simpler. The downside is that connecting a device to WSL means disconnecting it from Windows; if you need the Yubikey to log into a website, you'll have to temporarily detach it from WSL.

  1. Install WSL USB Manager.
    • This will install usbipd-win & WSL dependencies automatically. (If on first run you get an error about the usbipd wsl command being removed, exit WSL USB Manager from the system tray and restart it to make it realize you have the new version.)
    • Move the shortcut from %appdata%\Microsoft\Windows\Start Menu\Programs into Startup so it runs at login.
  2. Right click on the Yubikey in the device list (should say "Smartcard Reader") and Attach to WSL. The Yubikey should show up now if you run lsusb in WSL.
  3. Right click again and choose "Auto-Attach Device", then "Device".
  4. In WSL, sudo apt install scdaemon pcscd
    • Installing pcscd fixes the situation where gpg --card-status only works when run as root and says "gpg: selecting card failed: No such device" otherwise. (Adding a udev rule via the "Grant User Permissions" option in WSL USB Manager didn't do anything in this case.)
  5. Set SSH_AUTH_SOCK and GPG_TTY in your .bashrc as shown here.
  6. Add enable-ssh-support to ~/.gnupg/gpg-agent.conf
  7. Add Match host * exec "gpg-connect-agent updatestartuptty /bye" to ~/.ssh/config
    • Explanation for why updatestartuptty is necessary here; running it via ssh config comes from this answer. Supposedly GPG_TTY is enough, but for whatever reason on my machine that only worked for gpg signing and not the ssh agent ¯\_(ツ)_/¯
    • Note: Without a GUI pinentry program, some Git features in VSCode (like auto-fetch) won't work until you've unlocked the card in a terminal (e.g. by running git fetch yourself).
  8. gpg --card-status and ssh [email protected] should work now!

unraid

For "Sovngarde," my NAS. There isn't much here (just a CDPATH and a function to list/monitor files on the array that are being accessed), but if you're running Unraid as well, see How to install GNU Stow on Unraid. Here's my user script, set to run on array start, if it happens to be useful:

cat /boot/config/plugins/user.scripts/scripts/install_dotfiles/script
#!/bin/bash
#name=Install dotfiles
#description=(Re)clone & install dotfiles.
#argumentDescription=Branch
#argumentDefault=master
#clearLog=true
set -eo pipefail

export PATH="/usr/local/bin:$PATH"
export HOME=/root

DOTFILES_DIR=~/dotfiles
BRANCH=${1:-master}

# Nuke existing dotfiles
rm -rfv ~/.bashrc ~/.bash_profile "$DOTFILES_DIR"

# Clean up symlinks
find ~ -xtype l -exec rm -v -- {} +
find ~ -depth -type d -empty -exec rmdir -v -- {} \;

# Clone repo
git clone -b "$BRANCH" https://github.com/maxkagamine/dotfiles.git "$DOTFILES_DIR"

# Install
cd "$DOTFILES_DIR"
make

Also take a look at:

Tools for batch remuxing MKVs using mkvtoolnix: mkv-ls shows tracks in a table similar to the GUI but groups identical track listings for batch processing with mkv-batch.

For example, if I wanted to keep only the Japanese audio and remove the Signs & Songs tracks from everything except the "Another Epilogue" special (which mkv-ls shows has different tracks):

(The escaped filenames in gray are for copy/pasting into the mkv-batch command, but for screenshot purposes I used the !() glob syntax instead.)

Additional tools:

  • mkv-cat — Concatenates the input MKVs, adding chapters for each file.
  • mkv-extract-subs — Batch extracts all subtitles from the given MKVs.
  • mkv-extract-fonts — Batch extracts all unique fonts (by filename) from the given MKVs.
  • mkv-rm-cover — Removes all image/jpeg and image/png attachments from the given MKVs.
  • mkv-clean — Removes the title and video track name (both used occasionally just to advertise the encoding group), cover image (some groups plaster the series cover on every episode), and common Windows system fonts (which are often unnecessarily included with subs and do nothing but waste space) from the given MKVs.

Miscellaneous utilities:

  • append-crc — Adds (or updates) a file's crc32 hash to its filename.
  • cron-wrapper — Wrapper script for cronjobs that prevents multiple instances, handles logging, and triggers a notification on error. Used for pull-from-seedbox and another script that runs yt-dlp to backup YouTube playlists.
  • flatten - Flattens the contents of a directory such that "foo/bar/file.jpg" is renamed to "foo - bar - file.jpg", with an optional prefix/suffix added to the filenames.
  • intersect-csvs — Creates CSVs containing only rows that exist in two or more of the given CSVs. For example, given A.csv, B.csv, and C.csv, creates A+B.csv, A+C.csv, B+C.csv, and A+B+C.csv. I used this to create a map of arcades in Tokyo that have my favorite games. It can easily be edited to handle files without a header row.
  • mkanimedir — Turns a MAL link and a bunch of episodes into a nice folder.
  • mkmoviedir — Like mkanimedir but for an IMDb link.
  • upscale — Wrapper for several AI image upscalers, with options for automatic batch processing.
  • weigh — Shows the total size of files, directories, or stdin (optionally gzipped).

I need to ask you to stop. That... committing... is making people nervous.

In case you missed it: Nuke a git repo with unrelenting force: the FUS RO DAH command

ctop and runlike functions (themselves run via docker), the latter with color (via bat) and an fzf picker.

Fancy keyboard shortcuts (also powers the aforementioned git-branch-fzf)

Because nothing on the Internet is guaranteed to be there tomorrow.