Skip to content

Commit 8549948

Browse files
committed
clean up
1 parent cc906bd commit 8549948

23 files changed

+35
-1924
lines changed

.bash_profile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
echo .bash_profile loaded
66

7+
export FASTLY_API_TOKEN="123"
8+
export FASTLY_SERVICE_ID="456"
9+
10+
export VCL_DIRECTORY="$HOME/code/buzzfeed/cdn"
11+
export VCL_MATCH_PATH="_util|www"
12+
export VCL_SKIP_PATH="fastly_boilerplate"
13+
714
if [ -f "$HOME/.bashrc" ]; then
815
# shellcheck source=/dev/null
916
source "$HOME/.bashrc"
@@ -14,8 +21,3 @@ if [ -f "$(brew --prefix)/etc/bash_completion" ]; then
1421
# shellcheck source=/dev/null
1522
source "$(brew --prefix)/etc/bash_completion"
1623
fi
17-
18-
# prevent tmux from triggering the path to be updated with duplicate items
19-
if [[ -z $TMUX ]]; then
20-
export PATH="/set/something/here:$PATH"
21-
fi

.bashrc

Lines changed: 26 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#!/usr/bin/env bash
2-
32
echo .bashrc loaded
43

5-
# Prevent shellcheck from worrying about code sourced at runtime.
6-
# https://github.com/koalaman/shellcheck/wiki/SC1090
4+
# Throughout this configuration file you'll see:
5+
#
76
# shellcheck source=/dev/null
7+
#
8+
# This prevents the shellcheck tool from worrying about code sourced at runtime.
9+
# e.g. source ~/.foo doesn't make shellcheck happy
10+
# https://github.com/koalaman/shellcheck/wiki/SC1090
811

912
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
10-
source ~/.git-prompt.sh
11-
12-
# DISABLED...
1313
# shellcheck source=/dev/null
14-
# https://github.com/jarun/googler/blob/master/auto-completion/bash/googler-completion.bash
15-
# source ~/googler-completion.bash
14+
source ~/.git-prompt.sh
1615

1716
# tells Readline to perform filename completion in a case-insensitive fashion
1817
bind "set completion-ignore-case on"
@@ -26,10 +25,6 @@ bind "set show-all-if-ambiguous on"
2625
# no bell sound on error
2726
bind "set bell-style none"
2827

29-
# DISABLED...
30-
# enable emacs like bindings (<C-a> and <C-e> for start and end of line shortcuts)
31-
# set -o emacs
32-
3328
# enable vim like bindings instead of emails (e.g. no longer use <C-a> or <C-e>)
3429
set -o vi
3530

@@ -64,27 +59,13 @@ shopt -s gnu_errfmt 2>/dev/null
6459
# ensure SIGHUP is sent to all jobs when an interactive login shell exits
6560
shopt -s huponexit 2>/dev/null
6661

67-
# custom environment variables
68-
export DROPBOX="$HOME/Dropbox"
69-
export GITHUB_USER="integralist"
70-
7162
# application configuration
72-
export GOOGLER_COLORS=bjdxxy # https://github.com/jarun/googler/
7363
export LSCOLORS="dxfxcxdxbxegedabagacad" # http://geoff.greer.fm/lscolors/
7464
export GREP_OPTIONS="--color=auto"
7565
export GREP_COLOR="1;32"
7666
export MANPAGER="less -X" # Don't clear the screen after quitting a manual page
77-
export GOPATH=$HOME/code/go
7867
export EDITOR="vim"
79-
export HOMEBREW_NO_ANALYTICS=1
80-
export SSH_PUBLIC_KEY="$HOME/.ssh/github_rsa.pub"
8168
export FZF_DEFAULT_COMMAND="ag --ignore-dir node_modules --filename-pattern ''" # can use --ignore-dir multiple times
82-
# export PROMPT_DIRTRIM=4 # truncate start of long path
83-
84-
# prevent tmux from triggering the path to be updated with duplicate items
85-
if [[ -z $TMUX ]]; then
86-
export PATH=$GOPATH/bin:$PATH
87-
fi
8869

8970
# git specific configurations
9071
export GIT_PS1_SHOWCOLORHINTS=true
@@ -165,20 +146,6 @@ function prompt() {
165146
PS1=$(printf "%*s\\r%s\\n\$ " "$(($(tput cols)+compensate))" "$(prompt_right)" "$(prompt_left)")
166147
}
167148

168-
function toggle_hidden() {
169-
setting=$(defaults read com.apple.finder AppleShowAllFiles)
170-
171-
if [ "$setting" == "NO" ]; then
172-
echo "Enabling hidden files"
173-
defaults write com.apple.finder AppleShowAllFiles YES
174-
else
175-
echo "Disabling hidden files"
176-
defaults write com.apple.finder AppleShowAllFiles NO
177-
fi
178-
179-
killall Finder
180-
}
181-
182149
function gc {
183150
if [ -z "$1" ]; then
184151
printf "\\n\\tUse: gc <checkout-branch-name>\\n"
@@ -196,23 +163,6 @@ function gcb {
196163
fi
197164
}
198165

199-
function dotf {
200-
# shellcheck disable=SC2164
201-
202-
if [ -z "$1" ]; then
203-
pushd "$PWD" && dotfiles && popd
204-
else
205-
pushd "$1" && dotfiles && popd
206-
fi
207-
}
208-
209-
function merge-diff {
210-
# show all of the commits that were merged in by <commit>
211-
# but none of the commits that were already on the branch
212-
# you get to see this (sort of) when using my `git lg` alias (see my .gitconfig)
213-
git log "$1^-"
214-
}
215-
216166
function headers {
217167
# Note: also possible by using 2>&1 after curl
218168
# which allows piping of output
@@ -250,25 +200,6 @@ function headers {
250200
echo "$response" | sort | tail -n +3 | grep -Ei "$pattern"
251201
}
252202

253-
function replace {
254-
# given an extension ($1), find all files with that extension,
255-
# then search each file for the specified text ($2) and
256-
# replace it with the specified text ($3)
257-
local extension=$1
258-
local f=$2
259-
local r=$3
260-
find . -type f -name "*.$extension" -exec gsed -i "s/$f/$r/g" {} +
261-
}
262-
263-
function age {
264-
local filename changed now elapsed
265-
filename=$1
266-
changed=$(perl -MFile::stat -e "print stat(\"${filename}\")->mtime")
267-
now=$(date +%s)
268-
elapsed=$(("$now"-"$changed"))
269-
echo $elapsed
270-
}
271-
272203
function search {
273204
local flags=${1:-}
274205
local pattern=$2
@@ -282,61 +213,16 @@ function search {
282213
# disabled because \\\\b for literal \b (with double quotes) is ridiculous
283214
printf '\n\tExample:\n\t\tsearch -- "def\\b" ~/code/buzzfeed/mono/site_router'
284215
printf '\n\t\tsearch "--files Dockerfile -C 5" "FROM node" ./'
285-
printf '\n\t\tsearch "--files Dockerfile -C 5" "FROM node" ./'
286216
printf '\n\t\tsearch --exclude-ipath "(.venv|.rig)" "arn:aws:s3"'
287217
printf '\n\t\tsearch "-A 5" "..." ./ # shows 5 lines before search results'
288218
printf '\n\t\tsearch "-B 5" "..." ./ # shows 5 lines after search results\n'
289219
return
290220
fi
291221

292-
time sift -n -X json --err-show-line-length --exclude-ipath $exclude $flags "$pattern" "$directory"
222+
time sift -n -X json --err-show-line-length --exclude-ipath "$exclude" "$flags" "$pattern" "$directory"
293223
# time grep --exclude-dir .git -irlno $pattern $directory
294224
}
295225

296-
function hmac {
297-
# share a secret "key" between client and server
298-
# then if you both generate the same hmac you're ok
299-
#
300-
# example (generates hexidecimal output):
301-
# hmac mds5 "some data to encrypt" "key"
302-
#
303-
# example (convert hexidecimal to binary then encode as Base64)
304-
# hmac sha256 "some data to encrypt" "key" -binary | base64
305-
digest="$1"
306-
data="$2"
307-
key="$3"
308-
shift 3 # this moves the positional arguments (`help shift`)
309-
# meaning we can use $@ to print out remaining args
310-
echo -n "$data" | openssl dgst "-$digest" -hmac "$key" "$@"
311-
}
312-
313-
function spotify {
314-
# pick random track to start playing playlist from
315-
local max=${1:-10}
316-
echo $((1 + RANDOM % max))
317-
}
318-
319-
function search_git {
320-
# search_git 'def f'
321-
git rev-list --all | xargs git grep "$1"
322-
}
323-
324-
function vimin {
325-
# usage: echo foo | vimin 'norm VgU'
326-
#
327-
# explanation of how vim handles stdin
328-
# https://gist.github.com/Integralist/2b01cfdaf9c85efb0de6e2b2085896c3
329-
330-
# store off standard input piped to this function
331-
read -d '' -r stdin
332-
333-
# capture the first parameter passed to this function
334-
local cmd="$1"
335-
336-
# re-pipe the standard input to vim with correct flags
337-
echo "$stdin" | vim - -es --not-a-term +"$cmd" +'%p' +'qa!'
338-
}
339-
340226
# shellcheck disable=SC2034
341227
read -r -d '' git_icons <<- EOF
342228
* unstaged changes
@@ -362,74 +248,54 @@ connectivity debugging steps...
362248
nslookup google.com 8.8.8.8
363249
nslookup google.com 192.168.1.1
364250
251+
> you can also use Cloudfare's 1.1.1.1 resolvers
252+
> you can change via Network UI tab in macOS (dns sub tab)
253+
> or via terminal: https://superuser.com/a/86188
254+
365255
* can we curl an endpoint:
366256
curl -Lsvo /dev/null http://google.com/
367257
368258
* also check performance:
369259
speedtest-cli
370260
EOF
371261

372-
# the following variables are necessary to determine the appropriate formatted
373-
# output (used by the `list` alias defined below)...
374-
375-
# shellcheck disable=SC2034
376-
bold=$(tput bold)
377-
# shellcheck disable=SC2034
378-
normal=$(tput sgr0)
379-
380262
# custom alias'
381263
#
382264
# note: use `type <alias>` to see what is assigned to an alias/fn/builtin/keyword
383265
# alternatively use the `list` alias to show all defined alias' from this file
384266

385-
alias list='cat ~/.bashrc | grep "^alias" | gsed -En "s/alias (\w+)=(.+)/${bold}\1\n ${normal}\2\n/p"'
386-
alias ascii='man 7 ascii'
387-
alias brew_openssl='/usr/local/opt/openssl/bin/openssl'
388-
alias builtins="enable -a" # list all shell builtins
389267
alias c-="git checkout -"
390268
alias c="clear"
391269
alias cm="git checkout master"
270+
alias dns="scutil --dns | grep 'nameserver\\[[0-9]*\\]'"
271+
alias dnshelp='echo "$dns_help"'
272+
alias gb="git branch"
273+
alias gbd="git branch -D"
274+
alias gpr="git pull --rebase origin master"
392275

393-
alias commands_dir='echo $PATH | tr ":" "\n" | sort | egrep "^/(usr|bin)"'
394-
alias commands='for i in $(commands_dir):; do eval "ls -l $i"; done'
276+
# shellcheck disable=SC2034
277+
bold=$(tput bold)
278+
# shellcheck disable=SC2034
279+
normal=$(tput sgr0)
280+
alias list='cat ~/.bashrc | grep "^alias" | gsed -En "s/alias (\w+)=(.+)/${bold}\1\n ${normal}\2\n/p"'
395281

396-
# Note:
282+
# Note: for the ll alias output...
283+
#
397284
# Slash ('/') immediately after each pathname is a directory
398285
# Asterisk ('*') after each pathname is an executable
399286
# At sign ('@') after each pathname is a symbolic link
400287
# Equals sign ('=') after each pathname is a socket
401288
# Percent sign ('%') after each pathname is a whiteout
402289
# Vertical bar ('|') after each pathname is a FIFO
403-
404-
alias copy="tr -d '\\n' | pbcopy" # e.g. echo $DEV_CERT_PATH | copy
405-
alias datesec='date +%s'
406-
alias did="vim +'normal Go' +'r!date' ~/did.txt"
407-
alias dns="scutil --dns | grep 'nameserver\\[[0-9]*\\]'"
408-
alias dnshelp='echo "$dns_help"'
409-
alias dotfiles="ls -a | grep '^\\.' | grep --invert-match '\\.DS_Store\\|\\.$'"
410-
alias drm='docker rm $(docker ps -a -q)'
411-
alias drmi='docker rmi $(docker images -q)'
412-
alias gb="git branch"
413-
alias gbd="git branch -D"
414-
alias gcp="git cherry-pick -"
415-
alias getcommit="git rev-parse HEAD | tr -d '\\n' | pbcopy"
416-
alias gitupstream="echo git branch -u origin/\\<branch\\>"
417-
alias gpr="git pull --rebase origin master"
418-
alias irc="irssi"
419290
alias ll="ls -laGpFHh"
291+
420292
alias ls="ls -GpF"
421-
alias muttb="mutt -F ~/.muttrc-buzzfeed"
422-
alias nvimupdate="brew reinstall --HEAD neovim" # brew reinstall --env=std neovim
423-
alias pipall="pip freeze --local | grep -v '^\\-e' | cut -d = -f 1 | xargs -n1 pip install -U"
424293
alias psw="pwgen -sy 20 1" # brew install pwgen
425294
alias r="source ~/.bash_profile" # this also sources .bashrc and also causes `pass` autocomplete to be reloaded
426295
alias sizeit="du -ahc" # can also add on a path at the end `sizeit ~/some/path`
427296
alias sshagent='eval "$(ssh-agent -s)" && ssh-add -K ~/.ssh/github_rsa'
428-
alias sshconfig='nvim -c "norm 12ggVjjjgc" -c "wq" ~/.ssh/config && cat ~/.ssh/config | awk "/switch/ {for(i=0; i<=3; i++) {getline; print}}"'
429-
alias sshkey="cd ~/.ssh && ssh-keygen -t rsa -b 4096 -C 'mark.mcdx@gmail.com'"
430297
alias sshvm="ssh dev.buzzfeed.io"
431298
alias tmuxy='bash ~/tmux.sh'
432-
alias uid='echo $(uuidgen)'
433299
alias updates="softwareupdate --list" # --install --all (or) --install <product name>
434300
alias v='$HOME/code/buzzfeed/mono/scripts/rig_vm'
435301
alias wat='echo "$git_icons"'
@@ -438,44 +304,12 @@ alias wut='echo "$git_icons"'
438304
eval "$(pyenv init -)"
439305
eval "$(pipenv --completion)"
440306

441-
# lazyload nvm
442-
# all props goes to http://broken-by.me/lazy-load-nvm/
443-
# grabbed from reddit @ https://www.reddit.com/r/node/comments/4tg5jg/lazy_load_nvm_for_faster_shell_start/
444-
#
445-
# NOTE: this will cause some confusing behaviour when opening fresh terminal prompt
446-
# in that a previously installed command (e.g. npm install -g dockly) won't exist
447-
# e.g. executing the `dockly` command will fail unless you execute `nvm` first
448-
# this is because we're lazy loading nvm and so it won't auto-load its default node version
449-
450-
lazynvm() {
451-
unset -f nvm node npm
452-
export NVM_DIR=~/.nvm
453-
# shellcheck source=/dev/null
454-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
455-
}
456-
457-
nvm() {
458-
lazynvm
459-
nvm "$@"
460-
}
461-
462-
node() {
463-
lazynvm
464-
node "$@"
465-
}
466-
467-
npm() {
468-
lazynvm
469-
npm "$@"
470-
}
471-
472307
# shellcheck source=/dev/null
473308
# https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh
474309
source ~/.bash-preexec.sh
475310

476311
# preexec executes just BEFORE a command is executed
477312
# preexec() { echo "just typed $1"; }
478-
479313
# precmd executes just AFTER a command is executed, but before the prompt is shown
480314
precmd() { prompt; }
481315

@@ -485,7 +319,7 @@ precmd() { prompt; }
485319
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
486320

487321
# we want Ctrl+f to 'find' files using fzf and copy filename to clipboard
488-
# we use `copy`, which is an alias for trimming newline before using pbcopy
322+
# we use `copy`, which is an alias for trimming newline before using pbcopy
489323
bind -x '"\C-f": fzf --preview="cat {}" --preview-window=top:50%:wrap | copy'
490324

491325
# shellcheck disable=SC2016

0 commit comments

Comments
 (0)