diff --git a/.aliases b/.aliases index 35446a14288..3387fa0609e 100644 --- a/.aliases +++ b/.aliases @@ -105,9 +105,9 @@ alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && k # URL-encode strings alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' -# Merge PDF files -# Usage: `mergepdf -o output.pdf input{1,2,3}.pdf` -alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py' +# Merge PDF files, preserving hyperlinks +# Usage: `mergepdf input{1,2,3}.pdf` +alias mergepdf='gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=_merged.pdf' # Disable Spotlight alias spotoff="sudo mdutil -a -i off" @@ -130,9 +130,6 @@ for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do alias "${method}"="lwp-request -m '${method}'" done -# Make Grunt print stack traces by default -command -v grunt > /dev/null && alias grunt="grunt --stack" - # Stuff I never really use but cannot delete either because of http://xkcd.com/530/ alias stfu="osascript -e 'set volume output muted true'" alias pumpitup="osascript -e 'set volume output volume 100'" diff --git a/.bash_profile b/.bash_profile index 29717373d18..f79b6145e40 100644 --- a/.bash_profile +++ b/.bash_profile @@ -26,14 +26,16 @@ for option in autocd globstar; do done; # Add tab completion for many Bash commands -if which brew &> /dev/null && [ -f "$(brew --prefix)/share/bash-completion/bash_completion" ]; then - source "$(brew --prefix)/share/bash-completion/bash_completion"; +if which brew &> /dev/null && [ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]; then + # Ensure existing Homebrew v1 completions continue to work + export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d"; + source "$(brew --prefix)/etc/profile.d/bash_completion.sh"; elif [ -f /etc/bash_completion ]; then source /etc/bash_completion; fi; # Enable tab completion for `g` by marking it as an alias for `git` -if type _git &> /dev/null && [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then +if type _git &> /dev/null; then complete -o default -o nospace -F _git g; fi; diff --git a/.bash_prompt b/.bash_prompt index 3ff63eb6821..74db549f994 100644 --- a/.bash_prompt +++ b/.bash_prompt @@ -16,49 +16,45 @@ prompt_git() { local branchName=''; # Check if the current directory is in a Git repository. - if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then - - # check if the current directory is in .git before running git checks - if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then - - # Ensure the index is up to date. - git update-index --really-refresh -q &>/dev/null; - - # Check for uncommitted changes in the index. - if ! $(git diff --quiet --ignore-submodules --cached); then - s+='+'; - fi; - - # Check for unstaged changes. - if ! $(git diff-files --quiet --ignore-submodules --); then - s+='!'; - fi; - - # Check for untracked files. - if [ -n "$(git ls-files --others --exclude-standard)" ]; then - s+='?'; - fi; - - # Check for stashed files. - if $(git rev-parse --verify refs/stash &>/dev/null); then - s+='$'; - fi; - + git rev-parse --is-inside-work-tree &>/dev/null || return; + + # Check for what branch we’re on. + # Get the short symbolic ref. If HEAD isn’t a symbolic ref, get a + # tracking remote branch or tag. Otherwise, get the + # short SHA for the latest commit, or give up. + branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ + git describe --all --exact-match HEAD 2> /dev/null || \ + git rev-parse --short HEAD 2> /dev/null || \ + echo '(unknown)')"; + + # Early exit for Chromium & Blink repo, as the dirty check takes too long. + # Thanks, @paulirish! + # https://github.com/paulirish/dotfiles/blob/dd33151f/.bash_prompt#L110-L123 + repoUrl="$(git config --get remote.origin.url)"; + if grep -q 'chromium/src.git' <<< "${repoUrl}"; then + s+='*'; + else + # Check for uncommitted changes in the index. + if ! $(git diff --quiet --ignore-submodules --cached); then + s+='+'; fi; + # Check for unstaged changes. + if ! $(git diff-files --quiet --ignore-submodules --); then + s+='!'; + fi; + # Check for untracked files. + if [ -n "$(git ls-files --others --exclude-standard)" ]; then + s+='?'; + fi; + # Check for stashed files. + if $(git rev-parse --verify refs/stash &>/dev/null); then + s+='$'; + fi; + fi; - # Get the short symbolic ref. - # If HEAD isn’t a symbolic ref, get the short SHA for the latest commit - # Otherwise, just give up. - branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ - git rev-parse --short HEAD 2> /dev/null || \ - echo '(unknown)')"; - - [ -n "${s}" ] && s=" [${s}]"; + [ -n "${s}" ] && s=" [${s}]"; - echo -e "${1}${branchName}${2}${s}"; - else - return; - fi; + echo -e "${1}${branchName}${2}${s}"; } if tput setaf 1 &> /dev/null; then diff --git a/.config/git/template/HEAD b/.config/git/template/HEAD new file mode 100644 index 00000000000..b870d82622c --- /dev/null +++ b/.config/git/template/HEAD @@ -0,0 +1 @@ +ref: refs/heads/main diff --git a/.exports b/.exports index ae9b020cad9..02cd3cdae8d 100644 --- a/.exports +++ b/.exports @@ -32,3 +32,6 @@ export MANPAGER='less -X'; # Avoid issues with `gpg` as installed via Homebrew. # https://stackoverflow.com/a/42265848/96656 export GPG_TTY=$(tty); + +# Hide the “default interactive shell is now zsh” warning on macOS. +export BASH_SILENCE_DEPRECATION_WARNING=1; diff --git a/.gitconfig b/.gitconfig index b44243359b9..b4d26657725 100644 --- a/.gitconfig +++ b/.gitconfig @@ -13,7 +13,7 @@ di = !"d() { git diff --patch-with-stat HEAD~$1; }; git diff-index --quiet HEAD -- || clear; d" # Pull in remote changes for the current repository and all its submodules - p = !"git pull; git submodule foreach git pull origin master" + p = pull --recurse-submodules # Clone a repository including all submodules c = clone --recursive @@ -56,7 +56,7 @@ # Find commits by commit message fm = "!f() { git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --decorate --date=short --grep=$1; }; f" - # Remove branches that have already been merged with master + # Remove branches that have already been merged with main # a.k.a. ‘delete merged’ dm = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d" @@ -79,6 +79,9 @@ fi \ }; f" + # Show the user email for the current repository. + whoami = config user.email + [apply] # Detect whitespace errors when applying a patch @@ -185,3 +188,7 @@ [url "git://gist.github.com/"] insteadOf = "gist:" + +[init] + + templateDir = ~/.config/git/template/ diff --git a/.macos b/.macos index 2ce16068182..e7da9cbded0 100755 --- a/.macos +++ b/.macos @@ -22,9 +22,6 @@ while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & #sudo scutil --set LocalHostName "0x6D746873" #sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "0x6D746873" -# Set standby delay to 24 hours (default is 1 hour) -sudo pmset -a standbydelay 86400 - # Disable the sound effects on boot sudo nvram SystemAudioVolume=" " @@ -96,12 +93,6 @@ defaults write com.apple.helpviewer DevMode -bool true # in the login window sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName -# Restart automatically if the computer freezes -sudo systemsetup -setrestartfreeze on - -# Never go into computer sleep mode -sudo systemsetup -setcomputersleep Off > /dev/null - # Disable Notification Center and remove the menu bar icon launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null @@ -126,20 +117,6 @@ defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false #sudo rm -rf /System/Library/CoreServices/DefaultDesktop.jpg #sudo ln -s /path/to/your/image /System/Library/CoreServices/DefaultDesktop.jpg -############################################################################### -# SSD-specific tweaks # -############################################################################### - -# Disable hibernation (speeds up entering sleep mode) -sudo pmset -a hibernatemode 0 - -# Remove the sleep image file to save disk space -sudo rm /private/var/vm/sleepimage -# Create a zero-byte file instead… -sudo touch /private/var/vm/sleepimage -# …and make sure it can’t be rewritten -sudo chflags uchg /private/var/vm/sleepimage - ############################################################################### # Trackpad, mouse, keyboard, Bluetooth accessories, and input # ############################################################################### @@ -195,6 +172,47 @@ sudo systemsetup -settimezone "Europe/Brussels" > /dev/null # Stop iTunes from responding to the keyboard media keys #launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2> /dev/null +############################################################################### +# Energy saving # +############################################################################### + +# Enable lid wakeup +sudo pmset -a lidwake 1 + +# Restart automatically on power loss +sudo pmset -a autorestart 1 + +# Restart automatically if the computer freezes +sudo systemsetup -setrestartfreeze on + +# Sleep the display after 15 minutes +sudo pmset -a displaysleep 15 + +# Disable machine sleep while charging +sudo pmset -c sleep 0 + +# Set machine sleep to 5 minutes on battery +sudo pmset -b sleep 5 + +# Set standby delay to 24 hours (default is 1 hour) +sudo pmset -a standbydelay 86400 + +# Never go into computer sleep mode +sudo systemsetup -setcomputersleep Off > /dev/null + +# Hibernation mode +# 0: Disable hibernation (speeds up entering sleep mode) +# 3: Copy RAM to disk so the system state can still be restored in case of a +# power failure. +sudo pmset -a hibernatemode 0 + +# Remove the sleep image file to save disk space +sudo rm /private/var/vm/sleepimage +# Create a zero-byte file instead… +sudo touch /private/var/vm/sleepimage +# …and make sure it can’t be rewritten +sudo chflags uchg /private/var/vm/sleepimage + ############################################################################### # Screen # ############################################################################### @@ -308,7 +326,7 @@ defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true /usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:iconSize 80" ~/Library/Preferences/com.apple.finder.plist # Use list view in all Finder windows by default -# Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv` +# Four-letter codes for the other view modes: `icnv`, `clmv`, `glyv` defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv" # Disable the warning before emptying the Trash @@ -318,7 +336,7 @@ defaults write com.apple.finder WarnOnEmptyTrash -bool false defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true # Show the ~/Library folder -chflags nohidden ~/Library +chflags nohidden ~/Library && xattr -d com.apple.FinderInfo ~/Library # Show the /Volumes folder sudo chflags nohidden /Volumes @@ -424,6 +442,7 @@ sudo ln -sf "/Applications/Xcode.app/Contents/Developer/Applications/Simulator ( # 10: Put display to sleep # 11: Launchpad # 12: Notification Center +# 13: Lock Screen # Top left screen corner → Mission Control defaults write com.apple.dock wvous-tl-corner -int 2 defaults write com.apple.dock wvous-tl-modifier -int 0 @@ -505,6 +524,7 @@ defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebK # Disable Java defaults write com.apple.Safari WebKitJavaEnabled -bool false defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled -bool false +defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabledForLocalFiles -bool false # Block pop-up windows defaults write com.apple.Safari WebKitJavaScriptCanOpenWindowsAutomatically -bool false diff --git a/.osx b/.osx index 4eacb4e03b7..df12aac66b3 100644 --- a/.osx +++ b/.osx @@ -1 +1 @@ -# 301 https://github.com/mathiasbynens/dotfiles/blob/master/.macos +# 301 https://github.com/mathiasbynens/dotfiles/blob/main/.macos diff --git a/README.md b/README.md index c6fed2ea8f5..d7bca276ad5 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,14 @@ set -- -f; source bootstrap.sh To install these dotfiles without Git: ```bash -cd; curl -#L https://github.com/mathiasbynens/dotfiles/tarball/master | tar -xzv --strip-components 1 --exclude={README.md,bootstrap.sh,.osx,LICENSE-MIT.txt} +cd; curl -#L https://github.com/mathiasbynens/dotfiles/tarball/main | tar -xzv --strip-components 1 --exclude={README.md,bootstrap.sh,.osx,LICENSE-MIT.txt} ``` To update later on, just run that command again. ### Specify the `$PATH` -If `~/.path` exists, it will be sourced along with the other files, before any feature testing (such as [detecting which version of `ls` is being used](https://github.com/mathiasbynens/dotfiles/blob/aff769fd75225d8f2e481185a71d5e05b76002dc/.aliases#L21-26)) takes place. +If `~/.path` exists, it will be sourced along with the other files, before any feature testing (such as [detecting which version of `ls` is being used](https://github.com/mathiasbynens/dotfiles/blob/aff769fd75225d8f2e481185a71d5e05b76002dc/.aliases#L21-L26)) takes place. Here’s an example `~/.path` file that adds `/usr/local/bin` to the `$PATH`: diff --git a/bootstrap.sh b/bootstrap.sh index 6844b84a624..5894c6c22f2 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -2,7 +2,7 @@ cd "$(dirname "${BASH_SOURCE}")"; -git pull origin master; +git pull origin main; function doIt() { rsync --exclude ".git/" \ diff --git a/brew.sh b/brew.sh index 5c8963d6e6d..26508ee43dd 100755 --- a/brew.sh +++ b/brew.sh @@ -22,7 +22,7 @@ brew install moreutils brew install findutils # Install GNU `sed`, overwriting the built-in `sed`. brew install gnu-sed --with-default-names -# Install Bash 4. +# Install a modern version of Bash. brew install bash brew install bash-completion2 @@ -83,6 +83,7 @@ brew install ack #brew install exiv2 brew install git brew install git-lfs +brew install gs brew install imagemagick --with-webp brew install lua brew install lynx