Skip to content

Commit eeab955

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: (28 commits) readme: fix link to lri’s old notes .macos: adjust toolbar title rollover delay .gitconfig: Rely on Git v2.28’s `init.defaultBranch` .gitconfig: delete `mpr` alias .gitconfig: show most recent branches first meta: rename main branch .gitconfig: make `git init` default to `main` instead of `master` (mathiasbynens#926) .gitconfig: improve `git p` alias (mathiasbynens#896) .exports: Hide zsh warning on macOS .macos: fix showing ~/Library folder in macOS 10.15 (Catalina) (mathiasbynens#917) .gitconfig: Add `g whoami` README: Fix link (mathiasbynens#902) .bash_prompt: Exit early for Chromium/Blink repo .macos: Also disable Java for local domains in Safari (mathiasbynens#769) .macos: Consolidate energy management settings .gitconfig: Simplify `git p` alias .macos: Add Hot Corner option for Lock Screen (13) .macos: Replace `Flwv` with `glyv` (mathiasbynens#886) .aliases: Make `mergepdf` preserve hyperlinks .bash_profile: Update bash-completion sourcing (mathiasbynens#864) ...
2 parents 99f6998 + 66ba9b3 commit eeab955

File tree

12 files changed

+163
-166
lines changed

12 files changed

+163
-166
lines changed

.aliases

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ fi
3131
# List all files colorized in long format
3232
alias l="ls -lF ${colorflag}"
3333

34-
# List all files colorized in long format, including dot files
35-
alias la="ls -laF ${colorflag}"
34+
# List all files colorized in long format, excluding . and ..
35+
alias la="ls -lAF ${colorflag}"
3636

3737
# List only directories
3838
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'"
@@ -109,9 +109,9 @@ alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && k
109109
# URL-encode strings
110110
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
111111

112-
# Merge PDF files
113-
# Usage: `mergepdf -o output.pdf input{1,2,3}.pdf`
114-
alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py'
112+
# Merge PDF files, preserving hyperlinks
113+
# Usage: `mergepdf input{1,2,3}.pdf`
114+
alias mergepdf='gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=_merged.pdf'
115115

116116
# Disable Spotlight
117117
alias spotoff="sudo mdutil -a -i off"
@@ -134,9 +134,6 @@ for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
134134
alias "${method}"="lwp-request -m '${method}'"
135135
done
136136

137-
# Make Grunt print stack traces by default
138-
command -v grunt > /dev/null && alias grunt="grunt --stack"
139-
140137
# Stuff I never really use but cannot delete either because of http://xkcd.com/530/
141138
alias stfu="osascript -e 'set volume output muted true'"
142139
alias pumpitup="osascript -e 'set volume output volume 100'"

.bash_profile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ for option in autocd globstar; do
2626
done;
2727

2828
# Add tab completion for many Bash commands
29-
if which brew &> /dev/null && [ -f "$(brew --prefix)/share/bash-completion/bash_completion" ]; then
30-
source "$(brew --prefix)/share/bash-completion/bash_completion";
29+
if which brew &> /dev/null && [ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]; then
30+
# Ensure existing Homebrew v1 completions continue to work
31+
export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d";
32+
source "$(brew --prefix)/etc/profile.d/bash_completion.sh";
3133
elif [ -f /etc/bash_completion ]; then
3234
source /etc/bash_completion;
3335
fi;
3436

3537
# Enable tab completion for `g` by marking it as an alias for `git`
36-
if type _git &> /dev/null && [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
38+
if type _git &> /dev/null; then
3739
complete -o default -o nospace -F _git g;
3840
fi;
3941

.bash_prompt

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,45 @@ prompt_git() {
1616
local branchName='';
1717

1818
# Check if the current directory is in a Git repository.
19-
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then
20-
21-
# check if the current directory is in .git before running git checks
22-
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then
23-
24-
# Ensure the index is up to date.
25-
git update-index --really-refresh -q &>/dev/null;
26-
27-
# Check for uncommitted changes in the index.
28-
if ! $(git diff --quiet --ignore-submodules --cached); then
29-
s+='+';
30-
fi;
31-
32-
# Check for unstaged changes.
33-
if ! $(git diff-files --quiet --ignore-submodules --); then
34-
s+='!';
35-
fi;
36-
37-
# Check for untracked files.
38-
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
39-
s+='?';
40-
fi;
41-
42-
# Check for stashed files.
43-
if $(git rev-parse --verify refs/stash &>/dev/null); then
44-
s+='$';
45-
fi;
46-
19+
git rev-parse --is-inside-work-tree &>/dev/null || return;
20+
21+
# Check for what branch we’re on.
22+
# Get the short symbolic ref. If HEAD isn’t a symbolic ref, get a
23+
# tracking remote branch or tag. Otherwise, get the
24+
# short SHA for the latest commit, or give up.
25+
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
26+
git describe --all --exact-match HEAD 2> /dev/null || \
27+
git rev-parse --short HEAD 2> /dev/null || \
28+
echo '(unknown)')";
29+
30+
# Early exit for Chromium & Blink repo, as the dirty check takes too long.
31+
# Thanks, @paulirish!
32+
# https://github.com/paulirish/dotfiles/blob/dd33151f/.bash_prompt#L110-L123
33+
repoUrl="$(git config --get remote.origin.url)";
34+
if grep -q 'chromium/src.git' <<< "${repoUrl}"; then
35+
s+='*';
36+
else
37+
# Check for uncommitted changes in the index.
38+
if ! $(git diff --quiet --ignore-submodules --cached); then
39+
s+='+';
4740
fi;
41+
# Check for unstaged changes.
42+
if ! $(git diff-files --quiet --ignore-submodules --); then
43+
s+='!';
44+
fi;
45+
# Check for untracked files.
46+
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
47+
s+='?';
48+
fi;
49+
# Check for stashed files.
50+
if $(git rev-parse --verify refs/stash &>/dev/null); then
51+
s+='$';
52+
fi;
53+
fi;
4854

49-
# Get the short symbolic ref.
50-
# If HEAD isn’t a symbolic ref, get the short SHA for the latest commit
51-
# Otherwise, just give up.
52-
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
53-
git rev-parse --short HEAD 2> /dev/null || \
54-
echo '(unknown)')";
55-
56-
[ -n "${s}" ] && s=" [${s}]";
55+
[ -n "${s}" ] && s=" [${s}]";
5756

58-
echo -e "${1}${branchName}${2}${s}";
59-
else
60-
return;
61-
fi;
57+
echo -e "${1}${branchName}${2}${s}";
6258
}
6359

6460
if tput setaf 1 &> /dev/null; then

.exports

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export MANPAGER='less -X';
3333
# https://stackoverflow.com/a/42265848/96656
3434
export GPG_TTY=$(tty);
3535

36+
# Hide the “default interactive shell is now zsh” warning on macOS.
37+
export BASH_SILENCE_DEPRECATION_WARNING=1;
38+
3639
# Node rdkafka
3740
export LDFLAGS="-L/usr/local/opt/openssl/lib"
3841
export CPPFLAGS="-I/usr/local/opt/openssl/include"

.functions

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,11 @@ function gz() {
102102
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
103103
}
104104

105-
# Syntax-highlight JSON strings or files
106-
# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
107-
function json() {
108-
if [ -t 0 ]; then # argument
109-
python -mjson.tool <<< "$*" | pygmentize -l javascript;
110-
else # pipe
111-
python -mjson.tool | pygmentize -l javascript;
112-
fi;
113-
}
114-
115105
# Run `dig` and display the most useful info
116106
function digga() {
117107
dig +nocmd "$1" any +multiline +noall +answer;
118108
}
119109

120-
# UTF-8-encode a string of Unicode symbols
121-
function escape() {
122-
printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u);
123-
# print a newline unless we’re piping the output to another program
124-
if [ -t 1 ]; then
125-
echo ""; # newline
126-
fi;
127-
}
128-
129110
# Show all the names (CNs and SANs) listed in the SSL certificate
130111
# for a given domain
131112
function getcertnames() {
@@ -160,25 +141,16 @@ function getcertnames() {
160141
fi;
161142
}
162143

163-
# `s` with no arguments opens the current directory in Sublime Text, otherwise
164-
# opens the given location
165-
function s() {
166-
if [ $# -eq 0 ]; then
167-
subl .;
168-
else
169-
subl "$@";
170-
fi;
171-
}
172-
173-
# `v` with no arguments opens the current directory in Vim, otherwise opens the
174-
# given location
175-
function v() {
176-
if [ $# -eq 0 ]; then
177-
vim .;
144+
# Normalize `open` across Linux, macOS, and Windows.
145+
# This is needed to make the `o` function (see below) cross-platform.
146+
if [ ! $(uname -s) = 'Darwin' ]; then
147+
if grep -q Microsoft /proc/version; then
148+
# Ubuntu on Windows using the Linux subsystem
149+
alias open='explorer.exe';
178150
else
179-
vim "$@";
180-
fi;
181-
}
151+
alias open='xdg-open';
152+
fi
153+
fi
182154

183155
# `o` with no arguments opens the current directory, otherwise opens the given
184156
# location

.gitconfig

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
[alias]
22

3-
# View abbreviated SHA, description, and history graph of the latest 20 commits
3+
# View abbreviated SHA, description, and history graph of the latest 20 commits.
44
l = log --pretty=oneline -n 20 --graph --abbrev-commit
55
# Scope to current directory
66
ld = log --pretty=oneline -n 20 --graph --abbrev-commit -- .
77
# Without graph
88
lr = log --pretty=oneline -n 20 --abbrev-commit
99

10-
# View the current working tree status using the short format
10+
# View the current working tree status using the short format.
1111
s = status -s
1212

1313
# Show the diff between the latest commit and the current state
1414
# d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat"
1515
d = !"git diff-index --quiet HEAD -- || clear; git diff --patch-with-stat"
1616

17-
# `git di $number` shows the diff between the state `$number` revisions ago and the current state
17+
# `git di $number` shows the diff between the state `$number` revisions ago and the current state.
1818
di = !"d() { git diff --patch-with-stat HEAD~$1; }; git diff-index --quiet HEAD -- || clear; d"
1919

20-
# Pull in remote changes for the current repository and all its submodules
21-
p = !"git pull; git submodule foreach git pull origin master"
20+
# Pull in remote changes for the current repository and all its submodules.
21+
p = pull --recurse-submodules
2222

23-
# Clone a repository including all submodules
23+
# Clone a repository including all submodules.
2424
c = clone --recursive
2525

26-
# Commit all changes
26+
# Commit all changes.
2727
ca = !git add -A && git commit -av
2828

29-
# Switch to a branch, creating it if necessary
29+
# Switch to a branch, creating it if necessary.
3030
go = "!f() { git checkout -b \"$1\" 2> /dev/null || git checkout \"$1\"; }; f"
3131

3232
# Show verbose output about tags, branches or remotes
3333
tags = tag -l
34-
branches = branch -a
35-
remotes = remote -v
34+
branches = branch --all
35+
remotes = remote --verbose
3636

37-
# List aliases
37+
# List aliases.
3838
aliases = config --get-regexp alias
3939

40-
# Amend the currently staged files to the latest commit
40+
# Amend the currently staged files to the latest commit.
4141
amend = commit --amend --reuse-message=HEAD
4242

43-
# Credit an author on the latest commit
43+
# Credit an author on the latest commit.
4444
credit = "!f() { git commit --amend --author \"$1 <$2>\" -C HEAD; }; f"
4545

46-
# Interactive rebase with the given number of latest commits
46+
# Interactive rebase with the given number of latest commits.
4747
reb = "!r() { git rebase -i HEAD~$1; }; r"
4848

4949
# Remove the old tag with this name and tag the latest commit with it.
@@ -61,7 +61,7 @@
6161
# Find commits by commit message
6262
fm = "!f() { git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --decorate --date=short --grep=$1; }; f"
6363

64-
# Remove branches that have already been merged with master
64+
# Remove branches that have already been merged with main.
6565
# a.k.a. ‘delete merged’
6666
dm = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
6767

@@ -71,42 +71,34 @@
7171
# Log current branch
7272
b = "!git branch | grep '\\*' | xargs -n 1 | grep -v '\\*'"
7373

74-
# List contributors with number of commits
74+
# List contributors with number of commits.
7575
contributors = shortlog --summary --numbered
7676

77-
# Merge GitHub pull request on top of the current branch or,
78-
# if a branch name is specified, on top of the specified branch
79-
mpr = "!f() { \
80-
declare currentBranch=\"$(git symbolic-ref --short HEAD)\"; \
81-
declare branch=\"${2:-$currentBranch}\"; \
82-
if [ $(printf \"%s\" \"$1\" | grep '^[0-9]\\+$' > /dev/null; printf $?) -eq 0 ]; then \
83-
git fetch origin refs/pull/$1/head:pr/$1 && \
84-
git checkout -B $branch && \
85-
git rebase $branch pr/$1 && \
86-
git checkout -B $branch && \
87-
git merge pr/$1 && \
88-
git branch -D pr/$1 && \
89-
git commit --amend -m \"$(git log -1 --pretty=%B)\n\nCloses #$1.\"; \
90-
fi \
91-
}; f"
77+
# Show the user email for the current repository.
78+
whoami = config user.email
9279

9380
[apply]
9481

95-
# Detect whitespace errors when applying a patch
82+
# Detect whitespace errors when applying a patch.
9683
whitespace = fix
9784

85+
[branch]
86+
87+
# Show most recently changed branches first.
88+
sort = -committerdate
89+
9890
[core]
9991

100-
# Use custom `.gitignore` and `.gitattributes`
92+
# Use custom `.gitignore` and `.gitattributes`.
10193
excludesfile = ~/.gitignore
10294
attributesfile = ~/.gitattributes
10395

104-
# Treat spaces before tabs and all kinds of trailing whitespace as an error
96+
# Treat spaces before tabs and all kinds of trailing whitespace as an error.
10597
# [default] trailing-space: looks for spaces at the end of a line
10698
# [default] space-before-tab: looks for spaces before tabs at the beginning of a line
10799
whitespace = space-before-tab,-indent-with-non-tab,trailing-space
108100

109-
# Make `git rebase` safer on macOS
101+
# Make `git rebase` safer on macOS.
110102
# More info: <http://www.git-tower.com/blog/make-git-rebase-safe-on-osx/>
111103
trustctime = false
112104

@@ -123,7 +115,7 @@
123115

124116
# Use colors in Git commands that are capable of colored output when
125117
# outputting to the terminal. (This is the default setting in Git ≥ 1.8.4.)
126-
ui = true
118+
ui = auto
127119

128120
[color "branch"]
129121

@@ -149,23 +141,23 @@
149141
[commit]
150142

151143
# https://help.github.com/articles/signing-commits-using-gpg/
152-
gpgsign = false
144+
gpgsign = true
153145
template = /Users/zwang/.stCommitMsg
154146

155147
[diff]
156148

157-
# Detect copies as well as renames
149+
# Detect copies as well as renames.
158150
renames = copies
159151
tool = Kaleidoscope
160152

161153
[diff "bin"]
162154

163-
# Use `hexdump` to diff binary files
155+
# Use `hexdump` to diff binary files.
164156
textconv = hexdump -v -C
165157

166158
[help]
167159

168-
# Automatically correct and execute mistyped commands
160+
# Automatically correct and execute mistyped commands.
169161
autocorrect = 1
170162

171163
[merge]

0 commit comments

Comments
 (0)