Skip to content

Commit 9267948

Browse files
committed
Merge branch 'main' of github.com:mathiasbynens/dotfiles into mathiasbynens-main
* 'main' of github.com:mathiasbynens/dotfiles: (84 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 e5b9a91 + 66ba9b3 commit 9267948

File tree

16 files changed

+438
-335
lines changed

16 files changed

+438
-335
lines changed

.aliases

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,27 @@ 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`
2220
colorflag="--color"
21+
export LS_COLORS='no=00:fi=00:di=01;31:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
2322
else # macOS `ls`
2423
colorflag="-G"
24+
export LSCOLORS='BxBxhxDxfxhxhxhxhxcxcx'
2525
fi
2626

2727
# List all files colorized in long format
2828
alias l="ls -lF ${colorflag}"
2929

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

3333
# List only directories
3434
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'"
3535

3636
# Always use color output for `ls`
3737
alias ls="command ls ${colorflag}"
38-
export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
39-
4038

4139
# Always enable colored `grep` output
4240
# Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage.
@@ -50,27 +48,27 @@ 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
57-
alias update='sudo softwareupdate -i -a; brew update; brew upgrade --all; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update'
52+
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'
53+
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'
5857

5958
# IP addresses
6059
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
6160
alias localip="ipconfig getifaddr en0"
6261
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
6362

63+
# Show active network interfaces
64+
alias ifactive="ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'"
65+
6466
# Flush Directory Service cache
6567
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
6668

6769
# Clean up LaunchServices to remove duplicates in the “Open With” menu
6870
alias lscleanup="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
6971

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

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

110-
# Merge PDF files
111-
# Usage: `mergepdf -o output.pdf input{1,2,3}.pdf`
112-
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'
113111

114112
# Disable Spotlight
115113
alias spotoff="sudo mdutil -a -i off"
@@ -119,9 +117,8 @@ alias spoton="sudo mdutil -a -i on"
119117
# PlistBuddy alias, because sometimes `defaults` just doesn’t cut it
120118
alias plistbuddy="/usr/libexec/PlistBuddy"
121119

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

126123
# Intuitive map function
127124
# For example, to list all directories that contain a certain file:
@@ -130,15 +127,12 @@ alias map="xargs -n1"
130127

131128
# One of @janmoesen’s ProTip™s
132129
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
133-
alias "$method"="lwp-request -m '$method'"
130+
alias "${method}"="lwp-request -m '${method}'"
134131
done
135132

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

143137
# Kill all the tabs in Chrome to free up memory
144138
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
@@ -148,4 +142,7 @@ alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v exten
148142
alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
149143

150144
# Reload the shell (i.e. invoke as a login shell)
151-
alias reload="exec $SHELL -l"
145+
alias reload="exec ${SHELL} -l"
146+
147+
# Print each PATH entry on a separate line
148+
alias path='echo -e ${PATH//:/\\n}'

.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: 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 & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
#!/usr/bin/env bash
22

3-
# Simple calculator
4-
function calc() {
5-
local result="";
6-
result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')";
7-
# └─ default (when `--mathlib` is used) is 20
8-
#
9-
if [[ "$result" == *.* ]]; then
10-
# improve the output for decimal numbers
11-
printf "$result" |
12-
sed -e 's/^\./0./' `# add "0" for cases like ".5"` \
13-
-e 's/^-\./-0./' `# add "0" for cases like "-.5"`\
14-
-e 's/0*$//;s/\.$//'; # remove trailing zeros
15-
else
16-
printf "$result";
17-
fi;
18-
printf "\n";
19-
}
20-
213
# Create a new directory and enter it
224
function mkd() {
235
mkdir -p "$@" && cd "$_";
@@ -93,15 +75,6 @@ function dataurl() {
9375
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
9476
}
9577

96-
# Create a git.io short URL
97-
function gitio() {
98-
if [ -z "${1}" -o -z "${2}" ]; then
99-
echo "Usage: \`gitio slug url\`";
100-
return 1;
101-
fi;
102-
curl -i https://git.io/ -F "url=${2}" -F "code=${1}";
103-
}
104-
10578
# Start an HTTP server from a directory, optionally specifying the port
10679
function server() {
10780
local port="${1:-8000}";
@@ -129,48 +102,11 @@ function gz() {
129102
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
130103
}
131104

132-
# Syntax-highlight JSON strings or files
133-
# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
134-
function json() {
135-
if [ -t 0 ]; then # argument
136-
python -mjson.tool <<< "$*" | pygmentize -l javascript;
137-
else # pipe
138-
python -mjson.tool | pygmentize -l javascript;
139-
fi;
140-
}
141-
142105
# Run `dig` and display the most useful info
143106
function digga() {
144107
dig +nocmd "$1" any +multiline +noall +answer;
145108
}
146109

147-
# UTF-8-encode a string of Unicode symbols
148-
function escape() {
149-
printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u);
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-
156-
# Decode \x{ABCD}-style Unicode escape sequences
157-
function unidecode() {
158-
perl -e "binmode(STDOUT, ':utf8'); print \"$@\"";
159-
# print a newline unless we’re piping the output to another program
160-
if [ -t 1 ]; then
161-
echo ""; # newline
162-
fi;
163-
}
164-
165-
# Get a character’s Unicode code point
166-
function codepoint() {
167-
perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))";
168-
# print a newline unless we’re piping the output to another program
169-
if [ -t 1 ]; then
170-
echo ""; # newline
171-
fi;
172-
}
173-
174110
# Show all the names (CNs and SANs) listed in the SSL certificate
175111
# for a given domain
176112
function getcertnames() {
@@ -205,35 +141,16 @@ function getcertnames() {
205141
fi;
206142
}
207143

208-
# `s` with no arguments opens the current directory in Sublime Text, otherwise
209-
# opens the given location
210-
function s() {
211-
if [ $# -eq 0 ]; then
212-
subl .;
213-
else
214-
subl "$@";
215-
fi;
216-
}
217-
218-
# `a` with no arguments opens the current directory in Atom Editor, otherwise
219-
# opens the given location
220-
function a() {
221-
if [ $# -eq 0 ]; then
222-
atom .;
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';
223150
else
224-
atom "$@";
225-
fi;
226-
}
227-
228-
# `v` with no arguments opens the current directory in Vim, otherwise opens the
229-
# given location
230-
function v() {
231-
if [ $# -eq 0 ]; then
232-
vim .;
233-
else
234-
vim "$@";
235-
fi;
236-
}
151+
alias open='xdg-open';
152+
fi
153+
fi
237154

238155
# `o` with no arguments opens the current directory, otherwise opens the given
239156
# location

0 commit comments

Comments
 (0)