Skip to content

Commit 4571122

Browse files
author
Mike McElroy
committed
Merge branch 'updated-upstream'
* updated-upstream: (63 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 cab3ac9 + 66ba9b3 commit 4571122

File tree

16 files changed

+344
-304
lines changed

16 files changed

+344
-304
lines changed

.aliases

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ alias dl="cd ~/Downloads"
1414
alias dt="cd ~/Desktop"
1515
alias p="cd ~/projects"
1616
alias g="git"
17-
alias h="history"
18-
alias j="jobs"
1917

2018
# Detect which `ls` flavor is in use
2119
if ls --color > /dev/null 2>&1; then # GNU `ls`
@@ -29,8 +27,8 @@ fi
2927
# List all files colorized in long format
3028
alias l="ls -lF ${colorflag}"
3129

32-
# List all files colorized in long format, including dot files
33-
alias la="ls -laF ${colorflag}"
30+
# List all files colorized in long format, excluding . and ..
31+
alias la="ls -lAF ${colorflag}"
3432

3533
# List only directories
3634
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'"
@@ -50,12 +48,13 @@ alias sudo='sudo '
5048
# Get week number
5149
alias week='date +%V'
5250

53-
# Stopwatch
54-
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'
55-
5651
# Get macOS Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
5752
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update; sudo gem cleanup'
5853

54+
# Google Chrome
55+
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
56+
alias canary='/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary'
57+
5958
# IP addresses
6059
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
6160
alias localip="ipconfig getifaddr en0"
@@ -70,10 +69,6 @@ alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
7069
# Clean up LaunchServices to remove duplicates in the “Open With” menu
7170
alias lscleanup="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
7271

73-
# View HTTP traffic
74-
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
75-
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
76-
7772
# Canonical hex dump; some systems have this symlinked
7873
command -v hd > /dev/null || alias hd="hexdump -C"
7974

@@ -110,9 +105,9 @@ alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && k
110105
# URL-encode strings
111106
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
112107

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

117112
# Disable Spotlight
118113
alias spotoff="sudo mdutil -a -i off"
@@ -122,9 +117,8 @@ alias spoton="sudo mdutil -a -i on"
122117
# PlistBuddy alias, because sometimes `defaults` just doesn’t cut it
123118
alias plistbuddy="/usr/libexec/PlistBuddy"
124119

125-
# Ring the terminal bell, and put a badge on Terminal.app’s Dock icon
126-
# (useful when executing time-consuming commands)
127-
alias badge="tput bel"
120+
# Airport CLI alias
121+
alias airport='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
128122

129123
# Intuitive map function
130124
# For example, to list all directories that contain a certain file:
@@ -133,12 +127,9 @@ alias map="xargs -n1"
133127

134128
# One of @janmoesen’s ProTip™s
135129
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
136-
alias "$method"="lwp-request -m '$method'"
130+
alias "${method}"="lwp-request -m '${method}'"
137131
done
138132

139-
# Make Grunt print stack traces by default
140-
command -v grunt > /dev/null && alias grunt="grunt --stack"
141-
142133
# Stuff I never really use but cannot delete either because of http://xkcd.com/530/
143134
alias stfu="osascript -e 'set volume output muted true'"
144135
alias pumpitup="osascript -e 'set volume output volume 100'"
@@ -151,7 +142,7 @@ alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v exten
151142
alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
152143

153144
# Reload the shell (i.e. invoke as a login shell)
154-
alias reload="exec $SHELL -l"
145+
alias reload="exec ${SHELL} -l"
155146

156147
# Print each PATH entry on a separate line
157148
alias path='echo -e ${PATH//:/\\n}'

.bash_profile

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

3131
# Add tab completion for many Bash commands
32-
if which brew &> /dev/null && [ -f "$(brew --prefix)/share/bash-completion/bash_completion" ]; then
33-
source "$(brew --prefix)/share/bash-completion/bash_completion";
32+
if which brew &> /dev/null && [ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]; then
33+
# Ensure existing Homebrew v1 completions continue to work
34+
export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d";
35+
source "$(brew --prefix)/etc/profile.d/bash_completion.sh";
3436
elif [ -f /etc/bash_completion ]; then
3537
source /etc/bash_completion;
3638
fi;
3739

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

.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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ export LESS_TERMCAP_md="${yellow}";
2828

2929
# Don’t clear the screen after quitting a manual page.
3030
export MANPAGER='less -X';
31+
32+
# Avoid issues with `gpg` as installed via Homebrew.
33+
# https://stackoverflow.com/a/42265848/96656
34+
export GPG_TTY=$(tty);
35+
36+
# Hide the “default interactive shell is now zsh” warning on macOS.
37+
export BASH_SILENCE_DEPRECATION_WARNING=1;

.functions

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ function dataurl() {
7575
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
7676
}
7777

78-
# Create a git.io short URL
79-
function gitio() {
80-
if [ -z "${1}" -o -z "${2}" ]; then
81-
echo "Usage: \`gitio slug url\`";
82-
return 1;
83-
fi;
84-
curl -i https://git.io/ -F "url=${2}" -F "code=${1}";
85-
}
86-
8778
# Start an HTTP server from a directory, optionally specifying the port
8879
function server() {
8980
local port="${1:-8000}";
@@ -111,48 +102,11 @@ function gz() {
111102
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
112103
}
113104

114-
# Syntax-highlight JSON strings or files
115-
# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
116-
function json() {
117-
if [ -t 0 ]; then # argument
118-
python -mjson.tool <<< "$*" | pygmentize -l javascript;
119-
else # pipe
120-
python -mjson.tool | pygmentize -l javascript;
121-
fi;
122-
}
123-
124105
# Run `dig` and display the most useful info
125106
function digga() {
126107
dig +nocmd "$1" any +multiline +noall +answer;
127108
}
128109

129-
# UTF-8-encode a string of Unicode symbols
130-
function escape() {
131-
printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u);
132-
# print a newline unless we’re piping the output to another program
133-
if [ -t 1 ]; then
134-
echo ""; # newline
135-
fi;
136-
}
137-
138-
# Decode \x{ABCD}-style Unicode escape sequences
139-
function unidecode() {
140-
perl -e "binmode(STDOUT, ':utf8'); print \"$@\"";
141-
# print a newline unless we’re piping the output to another program
142-
if [ -t 1 ]; then
143-
echo ""; # newline
144-
fi;
145-
}
146-
147-
# Get a character’s Unicode code point
148-
function codepoint() {
149-
perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))";
150-
# print a newline unless we’re piping the output to another program
151-
if [ -t 1 ]; then
152-
echo ""; # newline
153-
fi;
154-
}
155-
156110
# Show all the names (CNs and SANs) listed in the SSL certificate
157111
# for a given domain
158112
function getcertnames() {
@@ -187,35 +141,16 @@ function getcertnames() {
187141
fi;
188142
}
189143

190-
# `s` with no arguments opens the current directory in Sublime Text, otherwise
191-
# opens the given location
192-
function s() {
193-
if [ $# -eq 0 ]; then
194-
subl .;
195-
else
196-
subl "$@";
197-
fi;
198-
}
199-
200-
# `a` with no arguments opens the current directory in Atom Editor, otherwise
201-
# opens the given location
202-
function a() {
203-
if [ $# -eq 0 ]; then
204-
atom .;
205-
else
206-
atom "$@";
207-
fi;
208-
}
209-
210-
# `v` with no arguments opens the current directory in Vim, otherwise opens the
211-
# given location
212-
function v() {
213-
if [ $# -eq 0 ]; then
214-
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';
215150
else
216-
vim "$@";
217-
fi;
218-
}
151+
alias open='xdg-open';
152+
fi
153+
fi
219154

220155
# `o` with no arguments opens the current directory, otherwise opens the given
221156
# location

0 commit comments

Comments
 (0)