Dev Notes
ZSH
Files
| What |
How |
| Open a finder window |
open . |
| Find a file |
find ~ -name "*.zim" 2>/dev/null |
| Find an executable (in path) |
command -v executable-to-find |
| E.g., find the Rust compiler (if it exists) |
command -v rustc |
| Get info about a file |
file foo |
| Chain commands (only run second if first succeeds) |
git fetch && git status |
| rm a non-empty directory |
rm -rf directory-name |
File sync
| What |
How |
| One way recursive file sync (note trailing slashes) |
rsync -avh --progress /path/to/local/folder/ /Volumes/YourNAS/folder/ |
Environment
| What |
How |
| Show current environment variables |
printenv |
Show current $PATH. Note: $path is an array version of $PATH, and print -l puts array elements on new lines |
print -l $path |
A more generic version. Note: tr “translates” colon into newlines. |
echo $PATH | tr ':' '\n' |
| Show mounted drives |
lsblk |
| Get network info |
ip a
ip route |
| Show running process in a helpful format |
top -o state |
chmod
| What |
How |
| Make a file executable: |
chmod +x file |
Pure BASH Bible
The goal of this book is to document commonly-known and lesser-known methods of doing various tasks using only built-in bash features. Using the snippets from this bible can help remove unneeded dependencies from scripts and in most cases make them faster.
Eleventy
| What |
How |
| Build site |
npx @11ty/eleventy |
| Build site and start local server |
npx @11ty/eleventy --serve |
GIT
Create a local repo
| What |
How |
| Create a repo |
git init |
| Create a .gitignore |
cat > .gitignore <<EOF
# macOS
.DS_Store
EOF |
| Stage and commit |
git add .
git commit -m "Initial project" |
Create repo on GitHub
| What |
How |
| Add the GitHub remote |
git remote add origin https://github.com/username/project.git |
| Push commits |
git branch -M main #rename default branch to 'main'
git push -u origin main #push and set upstream |
Create a feature branch
| What |
How |
| Create a branch |
git checkout -b feature-branch
git push -u origin feature-branch |
Merge latest main into feature branch
| What |
How |
| Ensure main is up-to-date |
git switch main
git pull origin main |
| Switch back to branch |
git switch feature-branch |
| Merge main |
git merge main |
Replace main with (successful) feature branch
| What |
How |
| Switch to main |
git checkout main |
| Replace main with branch |
git merge --squash feature-branch
git commit -m "Implement feature X" |
| Delete branch |
(see below) |
Abandon a feature branch
| What |
How |
| Switch back to main |
git checkout main |
| Delete branch |
(see below) |
Delete a feature branch
| What |
How |
| Remove local branch |
git branch -d feature-branch |
| Force delete the branch (if necessary) |
git branch -D feature-branch |
| Remove remote branch |
git push origin --delete feature-branch |
Case-only renames
This is a gotcha on MacOS, as APFS is "case preserving" but not "case sensitive".
- Never rename
foo → Foo in one step. Always go through a third name.
- When doing case-only renames, isolate them in a single commit.
- Do case-only renames in git. Not in editor or Finder.
- If doing "real" renames (
Assets/Models → Assets/Meshes), do that in editor.
- If doing structural moves (
Assets/Models → Assets/World/Models), do that in editor.
- Don't mix case-only renames and structural changes in a single commit.
- If you have
~/Design, the fact that you can cd ~/design or even cd ~/dEsIgN and it works is normal and expected 🤯 It's just how APFS works (for understandable reasons, but still...)
- When in doubt, use
pwd and pwd -P to see logical vs. physical path name
| What |
How |
| Rename foo → Foo |
git mv foo __foo_tmp__
git mv __foo_tmp__ Foo
git commit -m "Rename foo --> Foo" |
| Rename Assets/foo → Assets/Foo |
git mv Assets/foo Assets/__foo_tmp__
git mv Assets/__foo_tmp__ Assets/Foo
git commit -m "Rename Assets/foo --> Assets/Foo" |
| Sanity check - you should see exactly what you expect, once |
git diff --name-status HEAD~1
git ls-tree -r HEAD --name-only | grep -i assets |
| When squashing, git may complain about untracked files. It's safe to remove them. |
rm -rf Assets |
GIT LFS
If local repo contains LFS pointers (~500 bytes) instead of actual binary files:
| What |
How |
| Ensure Git LFS filters are registered. Safe to run multiple times. |
git lfs install |
| Pull the real LFS objects (i.e., the actual binary files) |
git lfs pull |
| Update working tree - replace pointers with actual binary files |
git lfs checkout |
Note: Shouldn't have to do this manually. Git LFS should "smudge" (replace pointer with real file) automatically during normal git operations. It supposed to be transparent.
Archive management
| What |
How |
| Zip (secure) |
7z a -tzip -mem=AES256 -p archive.zip /path/to/files_or_folder |
| Zip (split into 2GB volumes) |
7z a -tzip -mem=AES256 -p -bb3 archive.zip /path/to/files_or_folder |
| Unzip |
7z x archive.7z |