~

Throw away pastebin

Just a place to throw away some text.

macOS

Never sleep:

caffeinate -u -t 3600
caffeinate -i

Use Touch ID in Terminal:

sudo cp /etc/pam.d/sudo_local.template /etc/pam.d/sudo_local

# Uncomment last line
sudo nano /etc/pam.d/sudo_local

Hide Developer in Spotlight:

cd /Applications
touch Xcode.app

# Xcode mini version
xcode-select --install

Reset launchpad:

defaults write com.apple.dock ResetLaunchPad -bool true; killall Dock

Reduce padding in menu bar (Log out then log in to apply):

defaults -currentHost write -globalDomain NSStatusItemSelectionPadding -int 6
defaults -currentHost write -globalDomain NSStatusItemSpacing -int 6

Tweak Finder:

# Use list view
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# Show filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Keep folders on top when sorting by name
defaults write com.apple.finder _FXSortFoldersFirst -bool true

killall Finder

Disable IPv6:

sudo networksetup -listallnetworkservices
sudo networksetup -setv6off Wi-Fi

Clean up leftover data:

/Library/Application Support
/Library/LaunchAgents
/Library/LaunchDaemons
/Library/Preferences
/Users/Shared
~/Library/Application Support
~/Library/Fonts (Removed)
~/Library/LaunchAgents
~/Library/Preferences

Clean up leftover shell:

/etc/bashrc
/etc/profile
/etc/zshrc
/etc/paths.d

Clean up clipboard:

pbcopy < /dev/null

Disable Smart zoom in Track pad settings to make right click instant

Fix OpenVPN Client 3

sudo launchctl unload -w /Library/LaunchDaemons/org.openvpn.client.plist
sudo launchctl load -w /Library/LaunchDaemons/org.openvpn.client.plist

Bluetooth stutter:

sudo rm /Library/Preferences/com.apple.Bluetooth.plist
sudo pkill bluetoothd

Thanks:

Firefox

about:config:

Extensions:

Thanks:

ssh config

Edit ~/.ssh/config

Host *
    IdentitiesOnly yes
    UseKeychain yes

Thanks:

git clean up

# Delete untracked
git clean -fdx

git gc

Delete .DS_Store

With find:

find . -name ".DS_Store" -print -type f -delete

With fd:

fd -H '^\.DS_Store$' -tf -X rm

sd

Remove proto options:

sd -F 'import "validate/validate.proto";' '' api/raw/*.proto
sd -F 'import "marshal-zap.proto";' '' api/raw/*.proto
sd -f s '\s\[.*?];' ';' api/raw/*.proto

fdupes

Remove duplicated files:

fdupes -rdN .

rsync

# Result is dst/src
rsync -avzP src dst

# Result is dst/* with * is from src
rsync -avzP src/ dst

Commonly flags:

Be careful flags (need dry run if not sure):

ffmpeg

# -crf: quality, 0 is lossless, more is lower quality
# -an: no audio 
# -c:a aac -b:a 128k: audio codec and bitrate
ffmpeg -i input -c:v libx265 -crf 26 -preset fast -an output.mp4

Links:

libvips

Convert:

# Add --vips-progress to show progress
vips jxlsave filename.jpg filename.jxl --keep=none
vips jpegsave filename.png filename.jpg --keep=none

# Batch convert (require fd)
fd "jpg|jpeg|png|webp|gif" --exec vips jxlsave {} {.}.jxl --keep=none
fd "jpg|jpeg|png|webp|gif" --exec-batch rm

fd "png|webp|gif" --exec vips jpegsave {} {.}.jpg --keep=none
fd "png|webp|gif" --exec-batch rm

# Rotate
vips rot filename.jxl new_filename.jxl d90

yt-dlp

Download:

yt-dlp -f - "https://www.youtube.com/watch?v=video_id"

F2

Rename:

# If dry run, remove --exec
f2 --replace "{mtime.YYYY}{mtime.MM}{mtime.DD}_{mtime.H}{mtime.mm}{mtime.ss}_{hash.md5}{ext}" --exec

# Include ImageSize (require exiftool)
f2 --replace "{mtime.YYYY}{mtime.MM}{mtime.DD}_{mtime.H}{mtime.mm}{mtime.ss}_{xt.ImageSize}_{hash.md5}{ext}" --exec

# Not include time
f2 --exclude="\d+x\d+_[a-z\d]{32}" --sort=mtime --replace "{xt.ImageSize}_{hash.md5}{ext}" --exec

# Remove space in directory
f2 --find " " --replace "_" --string-mode --only-dir --exec
Feel free to ask me via email or Mastodon.
Source code is available on GitHub Codeberg sourcehut Treehouse GitLab