1
mirror of https://github.com/jakejarvis/dotfiles.git synced 2025-09-15 23:15:30 -04:00

🚀 massive overhaul using zinit & starship

This commit is contained in:
2023-01-19 22:00:11 -05:00
parent 2f51d538a5
commit 5bcbf0afd1
37 changed files with 1317 additions and 4188 deletions

0
zsh/.zprofile Normal file
View File

View File

@@ -1,84 +1,14 @@
# uncomment to profile slow startup time
# zmodload zsh/zprof
# path to this directory:
export ZSH_CUSTOM=~/.dotfiles/zsh
# Path to cloned dotfiles repo
export DOTFILES=$HOME/.dotfiles
# Path to oh-my-zsh installation
export ZSH=$HOME/.oh-my-zsh
# Default to nano 'cause I'm a wimp
export EDITOR="nano"
export VISUAL="code"
# export BROWSER="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
# export BROWSER="/Applications/Firefox.app/Contents/MacOS/firefox"
# Adjust history for speed
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
# Oh My ZSH settings
ZSH_CUSTOM=$DOTFILES/zsh
ZSH_THEME="agnoster"
DEFAULT_USER=jake
# Oh My ZSH plugins
plugins=(
colorize
history
macos
vscode
gitignore
gnu-utils
zsh-syntax-highlighting
zsh-autosuggestions
)
# Perform compinit only once a day for speed
# https://gist.github.com/ctechols/ca1035271ad134841284#gistcomment-2308206
autoload -Uz compinit
for dump in ~/.zcompdump(N.mh+24); do
# echo "reloading compinit"
compinit
# load .zsh files from the above dir in this order:
for _dotzsh in "$ZSH_CUSTOM"/custom/{common,env,path,aliases,functions,plugins,macos}.zsh; do
if [[ -f "$_dotzsh" ]]; then
source "$_dotzsh"
fi
done
compinit -C
unset _dotzsh
# Load everything!
source $ZSH/oh-my-zsh.sh
export ZPLUG_HOME=~/.zplug
source $ZPLUG_HOME/init.zsh
# Fix slow paste problem w/ zsh-syntax-highlighting plugin
# https://github.com/zsh-users/zsh-syntax-highlighting/issues/295
zstyle ':bracketed-paste-magic' active-widgets '.self-*'
# Prettify `ls`
# `man ls` to decode this mess
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
# Other miscellaneous settings
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_INSECURE_REDIRECT=1
# export HOMEBREW_CASK_OPTS=--require-sha
export NEXT_TELEMETRY_DISABLED=1
export GATSBY_TELEMETRY_DISABLED=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export SAM_CLI_TELEMETRY=0
export AZURE_CORE_COLLECT_TELEMETRY=0
export CHECKPOINT_DISABLE=1
# 1Password integrations
# https://developer.1password.com/docs/ssh/get-started/#step-4-configure-your-ssh-or-git-client
export SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
# https://developer.1password.com/docs/cli/shell-plugins/
source $HOME/.config/op/plugins.sh
# iTerm2
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# uncomment to profile slow startup time
# zprof
# zmodload -u zsh/zprof
if [[ -f ~/.zshrc.local ]]; then
source ~/.zshrc.local
fi

View File

@@ -1,20 +1,16 @@
# Enable aliases to be sudo'ed
# allow sudo-able aliases
alias sudo="sudo "
# restore colors to GNU ls
alias ls="ls -G --color=tty"
# colorful ls
alias ls="ls -G --color=auto"
alias ll="ls -lah"
alias la="ls -a"
alias l="ls -lh"
alias l="ll"
# typos
alias cd..="cd .."
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias ~="cd ~"
# easier dotfile tinkering
alias shreload="exec \$SHELL"
# Git
# git
alias g="git"
alias gc="git commit -m" # + commit message
alias gca="git add . && git commit -m" # + commit message
@@ -26,54 +22,43 @@ alias gpom="git push origin main"
alias glom="git pull origin main"
alias gpo="git push origin" # + branch name
alias glo="git pull origin" # + branch name
alias gphm="git push hosted main" # self-hosted git
alias gb="git checkout" # + existing branch name
alias gbn="git checkout -b" # + new branch name
alias grm="git rebase -i origin/main"
alias gsub="git submodule update --recursive --remote"
alias gundo="git reset --soft HEAD~1"
alias greset="git reset"
alias gres="git reset"
alias github="gh repo view --web"
alias gist="gh gist create --web"
glall() {
# pull all remote branches
# https://stackoverflow.com/a/10312587
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done
git fetch --all
git pull --all
}
# Docker
alias d="docker"
# docker
alias dps="docker ps -a"
# build and run:
# https://stackoverflow.com/questions/45141402/build-and-run-dockerfile-with-one-command/59220656#59220656
dbar() {
docker build --no-cache . | tee /dev/tty | tail -n1 | cut -d' ' -f3 | xargs -I{} docker run --rm -i {}
# build and run:
# https://stackoverflow.com/questions/45141402/build-and-run-dockerfile-with-one-command/59220656#59220656
docker build --progress=plain --no-cache . | tee /dev/tty | tail -n1 | cut -d' ' -f3 | xargs -I{} docker run --rm -i {}
}
dsh() {
docker exec -it "$1" /bin/sh
}
dhub() {
# search docker hub by tag
curl -sS "https://registry.hub.docker.com/v2/repositories/$1/tags/" | jq '."results"[]["name"]' | sort
}
alias dc="docker-compose"
alias dcu="docker-compose up -d"
alias dcd="docker-compose down"
alias dcr="docker-compose down && docker-compose up -d"
alias dcl="docker-compose logs -f"
alias dc="docker compose"
alias dcu="docker compose up -d"
alias dcd="docker compose down"
alias dcr="docker compose down && docker compose up -d"
alias dcl="docker compose logs -f"
# Multipass
# multipass
alias mp="multipass"
mpl() {
# creates VM and opens its bash shell
# `mpl test1 20.04`
multipass launch ${2:-22.04} --cpus 4 --mem 4G --disk 20G --name "$1" && \
# `mpl test1 4G 20.04`
multipass launch "${2:-jammy}" --cpus 4 --mem "${3:-2G}" --disk 20G --name "$1" && \
multipass shell "$1"
}
alias mpls="multipass list"
alias mpsh="multipass shell"
alias mpk="multipass stop"
alias mpd="multipass delete"
alias mps="multipass shell"
# Node/NPM/Yarn
alias npr="npm run"
@@ -81,36 +66,46 @@ alias fresh_npm="rm -rf node_modules package-lock.json && npm install"
alias fresh_yarn="rm -rf node_modules yarn.lock && yarn install"
# Hugo
# install from source
make_hugo() {
# parentheses lets us cd to Hugo path without changing our current location
(
cd "$GOPATH/src/github.com/gohugoio/hugo" \
&& /bin/bash -c "$GOPATH/bin/hugo env" \
&& bash -c "$GOPATH/bin/hugo env" \
&& git checkout master \
&& mage uninstall \
&& git pull origin master \
&& git reset --hard HEAD \
&& mage -v hugo \
&& HUGO_BUILD_TAGS=extended mage -v install \
&& /bin/bash -c "$GOPATH/bin/hugo env"
&& bash -c "$GOPATH/bin/hugo env"
)
}
# install from brew
alias hugo_brew="brew upgrade hugo --fetch-HEAD --build-from-source"
# run `hugo config` first to make sure we're in a Hugo directory:
alias hugo_clean="hugo config 1>/dev/null && rm -rf public/ resources/ build/"
# SSH
alias sshalt="ssh -p 2222"
alias moshalt="mosh --ssh=\"ssh -p 2222\""
alias pubkey="more ~/.ssh/id_ed25519.pub | pbcopy | echo '=> Public key copied to clipboard.'"
alias pubkey_rsa="more ~/.ssh/id_rsa.pub | pbcopy | echo '=> Public key copied to clipboard.'"
# an original creation, see https://github.com/jakejarvis/simpip
alias ipv4="curl -4 simpip.com --max-time 1 --proto-default https --silent"
alias ipv6="curl -6 simpip.com --max-time 1 --proto-default https --silent"
alias ip="ipv4; ipv6"
alias ip-local="ipconfig getifaddr en0"
alias ips="ip; ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
# Tailscale: https://tailscale.com/kb/1080/cli/?tab=macos
# keys
alias pubkey="pbcopy < ~/.ssh/id_ed25519.pub && echo '=> Public key copied to clipboard.'"
alias pubkey_rsa="pbcopy < ~/.ssh/id_rsa.pub && echo '=> Public key copied to clipboard.'"
# tailscale: https://tailscale.com/kb/1080/cli/?tab=macos
alias tailscale="/Applications/Tailscale.app/Contents/MacOS/Tailscale"
alias tscl="tailscale"
# youtube-dl
alias youtube-dl="yt-dlp" # fork: https://github.com/yt-dlp/yt-dlp
alias ytdl="youtube-dl -f bestvideo+bestaudio"
alias ytmp3="youtube-dl -f bestaudio -x --audio-format mp3 --audio-quality 320K"
# fun
# misc.
alias screenfetch="neofetch"
alias weather="curl 'https://wttr.in/?format=v2'"

53
zsh/custom/common.zsh Normal file
View File

@@ -0,0 +1,53 @@
autoload -U colors && colors
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
autoload -Uz select-word-style
select-word-style shell
# ---
setopt notify
setopt complete_in_word
setopt always_to_end
setopt extended_history
setopt hist_expire_dups_first
# setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_verify
setopt share_history
setopt inc_append_history
setopt rc_quotes
setopt autocd
setopt extended_glob
setopt glob_dots
unsetopt case_glob
unsetopt beep # kindly stfu
unsetopt correct
unsetopt correct_all
# ---
bindkey -e
bindkey "^[^[[D" backward-word
bindkey "^[^[[C" forward-word
# ---
export LC_ALL="${LC_ALL:-en_US.UTF-8}"
export LANG="${LANG:-en_US.UTF-8}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export HISTFILE=~/.zsh_history
export HISTSIZE=10000
export SAVEHIST=10000
export EDITOR="nano" # don't judge me
export VISUAL="code"
# https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/theme-and-appearance.zsh#L5
# export LS_COLORS="Gxfxcxdxbxegedabagacad"

9
zsh/custom/env.zsh Normal file
View File

@@ -0,0 +1,9 @@
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_INSECURE_REDIRECT=1
# export HOMEBREW_CASK_OPTS=--require-sha
export NEXT_TELEMETRY_DISABLED=1
export GATSBY_TELEMETRY_DISABLED=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export SAM_CLI_TELEMETRY=0
export AZURE_CORE_COLLECT_TELEMETRY=0
export CHECKPOINT_DISABLE=1

84
zsh/custom/functions.zsh Normal file
View File

@@ -0,0 +1,84 @@
# Make a new directory and `cd` right into it (this seems like a no-brainer)
mkcd() {
mkdir -p -- "$1" &&
cd -P -- "$1" || return
}
# Start an HTTP server from a directory, optionally specifying the port
serve() {
local port="${1:-8090}"
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn't break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
# Extract a compressed archive without worrying about which tool to use
extract() {
if [[ -f "$1" ]]; then
case "$1" in
*.tar.bz2)
tar xjf "$1"
;;
*.tar.gz)
tar xzf "$1"
;;
*.bz2)
bunzip2 "$1"
;;
*.rar)
unrar x "$1"
;;
*.gz)
gunzip "$1"
;;
*.tar)
tar xf "$1"
;;
*.tbz2)
tar xjf "$1"
;;
*.tgz)
tar xzf "$1"
;;
*.zip)
unzip "$1"
;;
*.Z)
uncompress "$1"
;;
*.7z)
7z x "$1"
;;
*)
echo "'$1' cannot be extracted via extract()"
;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Create a git.io short URL (custom slug optional)
# ex: gitio https://github.com/jakejarvis/dotfiles [jakesdotfiles] => https://git.io/jakesdotfiles
# https://blog.github.com/2011-11-10-git-io-github-url-shortener
gitio() {
local PARAMS RESPONSE
PARAMS="-F \"url=$1\""
if [[ -n "$2" ]]; then
PARAMS="$PARAMS -F \"code=$2\""
fi
RESPONSE=$(eval "curl -i https://git.io $PARAMS 2>&1" | grep "Location: ")
echo "${RESPONSE//Location: /}"
}
# Push a local SSH public key to another machine
# https://github.com/rtomayko/dotfiles/blob/rtomayko/.bashrc
push_ssh_cert() {
local _host
[[ -f ~/.ssh/id_ed25519.pub ]] || ssh-keygen -t ed25519
for _host in "$@"; do
echo "$_host"
ssh "$_host" "\cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_ed25519.pub
done
}

View File

@@ -1,22 +1,23 @@
# Rosetta hacks for M1 Macs
# all of this is only for macOS
if [[ ! "$(uname)" = "Darwin" ]]; then
return
fi
# export BROWSER="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
export BROWSER="/Applications/Firefox.app/Contents/MacOS/firefox"
# Rosetta hacks for M1
alias intel="arch -x86_64 /bin/zsh"
alias arm="arch -arm64 "$HOMEBREW_PREFIX"/bin/zsh"
alias arm="arch -arm64 zsh"
# My own creation! See: https://github.com/jakejarvis/simpip
alias ipv4="curl -4 simpip.com --max-time 1 --proto-default https --silent"
alias ipv6="curl -6 simpip.com --max-time 1 --proto-default https --silent"
alias ip="ipv4; ipv6"
alias ip-local="ipconfig getifaddr en0"
alias ips="ip; ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
alias dns-clear="networksetup -setdnsservers Wi-Fi"
alias dns-check="networksetup -getdnsservers Wi-Fi"
alias dns-set="networksetup -setdnsservers Wi-Fi "
alias dns-set-cloudflare="dns-set 1.1.1.1 1.0.0.1"
alias dns-set-google="dns-set 8.8.8.8 8.8.4.4"
alias flush="sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache"
# Update: brew, npm, gems, pip, app store, macos
# check & install updates for:
# - brew
# - node/npm
# - ruby/gems
# - pip
# - app store
# - macos
# - zinit
system_update() {
NC="\033[0m"
YELLOW="\033[0;33m"
@@ -25,6 +26,7 @@ system_update() {
brew update
brew upgrade
# avoid annoying `(latest) != latest` cask updates:
# shellcheck disable=SC2046
brew upgrade $(brew outdated --greedy --verbose | awk '$2 !~ /(latest)/ {print $1}')
brew cleanup
@@ -37,8 +39,8 @@ system_update() {
echo -e "${YELLOW}Updating Ruby and gems...${NC}"
CONFIGURE_OPTS="$RUBY_CONFIGURE_OPTS" \
rbenv install --skip-existing $(rbenv install -l | grep -v - | tail -1) && \
rbenv global $(rbenv install -l | grep -v - | tail -1)
rbenv install --skip-existing "$(rbenv install -l | grep -v - | tail -1)" && \
rbenv global "$(rbenv install -l | grep -v - | tail -1)"
gem install bundler foreman
gem update
gem cleanup
@@ -54,8 +56,9 @@ system_update() {
echo -e "${YELLOW}Checking for macOS system updates...${NC}"
softwareupdate --list
echo -e "${YELLOW}Updating Oh-My-ZSH...${NC}"
omz update
echo -e "${YELLOW}Updating zinit...${NC}"
zinit self-update
zinit update --all
}
alias rehide="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"
@@ -66,18 +69,24 @@ alias verify_sign="codesign --verify --deep --verbose"
alias gpu="system_profiler SPDisplaysDataType"
alias cpu="sysctl -n machdep.cpu.brand_string"
alias screenfetch="neofetch"
alias ripfinder="sudo killall Finder"
alias ripdock="sudo killall Dock"
alias ripmenu="sudo killall SystemUIServer NotificationCenter"
alias ripfinder="killall Finder"
alias ripdock="killall Dock"
alias ripmenu="killall SystemUIServer NotificationCenter"
# open current directory in Finder
alias finder="open -a Finder ./"
alias finder="open -a Finder ."
alias dns-clear="networksetup -setdnsservers Wi-Fi"
alias dns-check="networksetup -getdnsservers Wi-Fi"
alias dns-set="networksetup -setdnsservers Wi-Fi "
alias dns-set-cloudflare="dns-set 1.1.1.1 1.0.0.1"
alias dns-set-google="dns-set 8.8.8.8 8.8.4.4"
alias flush="sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache"
# uncomment to use VS Code insiders build
# alias code="code-insiders"
alias vs="code ./"
alias vs="code ."
# Xcode simulators
alias ios="open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app"

49
zsh/custom/path.zsh Normal file
View File

@@ -0,0 +1,49 @@
# a lot of this file only applies to macOS
if [[ "$(uname)" = "Darwin" ]]; then
# set PATH, MANPATH, etc., for Homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"
# remap macOS core utils to GNU equivalents (from coreutils, findutils, gnu-*, etc.):
# https://gist.github.com/skyzyx/3438280b18e4f7c490db8a2a2ca0b9da?permalink_comment_id=3049694#gistcomment-3049694
for gbin in "$(brew --prefix)"/opt/*/libexec/gnubin; do
export PATH="$gbin:$PATH"
done
# Ensure `man` refers to the new binaries:
for gman in "$(brew --prefix)"/opt/*/libexec/gnuman; do
export MANPATH="$gman:$MANPATH"
done
unset gbin gman
# OpenJDK
export PATH="$HOMEBREW_PREFIX/opt/openjdk/bin:$PATH"
# metasploit
export PATH="/opt/metasploit-framework/bin:$PATH"
# macOS-only fixes for rbenv/ruby below
# shellcheck disable=SC2155
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1) --with-readline-dir=$(brew --prefix readline) --with-libyaml-dir=$(brew --prefix libyaml)"
fi
# go
export GOPATH="$HOME/golang"
export PATH="$GOPATH/bin:$PATH"
# rbenv
if command -v rbenv 1>/dev/null 2>&1; then
eval "$(rbenv init -)"
fi
# rust/cargo
export PATH="$HOME/.cargo/bin:$PATH"
# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
# volta
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"

203
zsh/custom/plugins.zsh Normal file
View File

@@ -0,0 +1,203 @@
# check for zinit and clone if not installed
ZINIT_HOME="$HOME/.local/share/zinit/zinit.git"
if [[ ! -d "$ZINIT_HOME" ]]; then
mkdir -p "$(dirname "$ZINIT_HOME")"
git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
# initialize zinit
# shellcheck disable=SC1091
source "$ZINIT_HOME/zinit.zsh"
# ensure compinit recognizes zinit's changes
autoload -Uz _zinit
# shellcheck disable=SC2154
(( ${+_comps} )) && _comps[zinit]=_zinit
# various zinit add-ons
zinit light zdharma-continuum/zinit-annex-patch-dl
# async support
zinit ice wait lucid \
atload"async_init" \
src"async.zsh"
zinit light mafredri/zsh-async
# z
zinit ice wait lucid blockf \
atclone"
mv -vf z.1 ${ZINIT[MAN_DIR]}/man1
" \
atpull"%atclone" \
atload"_Z_DATA=~/.zdata" \
src"z.sh"
zinit light rupa/z
# grab exa (better ls) binary
zinit ice from"gh-r" as"command" \
mv"bin/exa* -> exa" \
atclone"
mv -vf completions/exa.zsh _exa
mv -vf man/exa.1 ${ZINIT[MAN_DIR]}/man1
mv -vf man/exa_colors.5 ${ZINIT[MAN_DIR]}/man5
" \
atpull"%atclone" \
atload"
alias ls='exa --color=auto -GF --icons --group-directories-first'
alias ll='exa --color=auto -1laF --git --icons --group-directories-first --ignore-glob=\".DS_Store*|~*\"'
alias lt='ll -T -L=2'
"
zinit light ogham/exa
# grab bat (better cat) binary
zinit ice from"gh-r" as"command" \
mv"bat-*/bat -> bat" \
atclone"
mv -vf bat-*/autocomplete/bat.zsh _bat
mv -vf bat-*/bat.1 ${ZINIT[MAN_DIR]}/man1
" \
atpull"%atclone" \
atload"alias cat='bat --paging=never --color=auto --style=\"numbers,changes\" --theme=\"Dracula\"'"
zinit light sharkdp/bat
# grab fd binary
# TODO: preview commands are an absolute sh*tshow, maybe use .lessfilter?
# https://github.com/Aloxaf/fzf-tab/wiki/Preview#show-file-contents
# shellcheck disable=SC2016
zinit ice from"gh-r" as"command" \
mv"fd-*/fd -> fd" \
atclone"
mv -vf fd-*/autocomplete/_fd _fd
mv -vf fd-*/fd.1 ${ZINIT[MAN_DIR]}/man1
" \
atpull"%atclone" \
atload'
FZF_FD_OPTS="--color always --hidden --follow --exclude .git --exclude node_modules"
FZF_PREVIEW_FILE_COMMAND="bat --color=always --paging=never --style=plain --theme=Dracula"
FZF_PREVIEW_DIR_COMMAND="exa -1a --color=always --icons --group-directories-first"
FZF_DEFAULT_OPTS="--no-mouse --bind \"tab:accept,ctrl-y:preview-page-up,ctrl-v:preview-page-down,ctrl-e:execute-silent(\${VISUAL:-code} {+} >/dev/null 2>&1)\""
FZF_DEFAULT_COMMAND="fd --type f $FZF_FD_OPTS"
FZF_ALT_C_OPTS="--ansi --preview \"$FZF_PREVIEW_DIR_COMMAND {} 2>/dev/null\""
FZF_ALT_C_COMMAND="fd --type d . $FZF_FD_OPTS"
FZF_CTRL_T_OPTS="--ansi --bind \"ctrl-w:execute(\${EDITOR:-nano} {1} >/dev/tty </dev/tty)+refresh-preview\" --preview \"$FZF_PREVIEW_FILE_COMMAND {} 2>/dev/null\""
FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
'
zinit light sharkdp/fd
# grab fzf binary from release & other files from source
zinit ice from"gh-r" as"command" \
dl"https://raw.githubusercontent.com/junegunn/fzf/master/shell/key-bindings.zsh -> key-bindings.zsh" \
dl"https://raw.githubusercontent.com/junegunn/fzf/master/shell/completion.zsh -> _fzf" \
dl"https://raw.githubusercontent.com/junegunn/fzf/master/man/man1/fzf.1 -> ${ZINIT[MAN_DIR]}/man1/fzf.1" \
dl"https://raw.githubusercontent.com/junegunn/fzf/master/man/man1/fzf-tmux.1 -> ${ZINIT[MAN_DIR]}/man1/fzf-tmux.1" \
src"key-bindings.zsh"
zinit light junegunn/fzf
# all the colors
# https://github.com/sharkdp/vivid/tree/master/themes
# shellcheck disable=SC2016
zinit ice from"gh-r" as"command" \
mv"vivid-*/vivid -> vivid" \
atload'export LS_COLORS="$(vivid generate snazzy)"'
zinit load sharkdp/vivid
# direnv
zinit ice from"gh-r" as"command" \
mv"direnv* -> direnv" \
atclone"./direnv hook zsh > zhook.zsh" \
atpull"%atclone" \
src"zhook.zsh"
zinit light direnv/direnv
# history substring searching
# only bind these keys once they're ready
bindkey -r "^[[A"
bindkey -r "^[[B"
zinit ice wait lucid \
atload"
zmodload zsh/terminfo
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
"
zinit light zsh-users/zsh-history-substring-search
# tab completions via fzf
# TODO: fix git-* completions, apparently there's some conflict with brew's git
# https://github.com/Aloxaf/fzf-tab/wiki/Preview#git
zinit ice wait lucid \
atload"
zstyle ':completion:*' verbose yes
zstyle ':completion:*' list-colors \${(s.:.)LS_COLORS}
zstyle ':completion:*:descriptions' format '[%d]'
zstyle ':completion::complete:*:*:files' ignored-patterns '.DS_Store' 'Icon?' '.Trash'
zstyle ':completion::complete:*:*:globbed-files' ignored-patterns '.DS_Store' 'Icon?' '.Trash'
zstyle ':completion::complete:rm:*:globbed-files' ignored-patterns
zstyle ':fzf-tab:*' fzf-command fzf
zstyle ':fzf-tab:*' fzf-bindings \
'tab:accept' \
'ctrl-y:preview-page-up' \
'ctrl-v:preview-page-down' \
'ctrl-e:execute-silent(${VISUAL:-code} \${realpath:-\$word} >/dev/null 2>&1)' \
'ctrl-w:execute(${EDITOR:-nano} \${realpath:-\$word} >/dev/tty </dev/tty)+refresh-preview'
zstyle ':fzf-tab:*' fzf-min-height 15
zstyle ':fzf-tab:complete:git-(add|diff|restore):*' fzf-preview \
'git --no-pager diff --color=always --no-ext-diff \${realpath:-\$word} | delta'
zstyle ':fzf-tab:complete:git-log:*' fzf-preview \
'git --no-pager log --color=always --format=oneline --abbrev-commit --follow \${realpath:-\$word}'
zstyle ':fzf-tab:complete:man:*' fzf-preview \
'man \$word'
zstyle ':fzf-tab:complete:brew-(install|uninstall|search|info):*-argument-rest' fzf-preview \
'brew info \$word'
zstyle ':fzf-tab:complete:(-command-|-parameter-|-brace-parameter-|export|unset|expand):*' fzf-preview \
'echo \${(P)word}'
zstyle ':fzf-tab:complete:*:options' fzf-preview
zstyle ':fzf-tab:complete:*:options' fzf-flags '--no-preview'
zstyle ':fzf-tab:complete:*:argument-1' fzf-preview
zstyle ':fzf-tab:complete:*:argument-1' fzf-flags '--no-preview'
zstyle ':fzf-tab:complete:*:*' fzf-preview \
'($FZF_PREVIEW_FILE_COMMAND \$realpath || $FZF_PREVIEW_DIR_COMMAND \$realpath) 2>/dev/null'
"
zinit light Aloxaf/fzf-tab
# autosuggestions, trigger precmd hook upon load
zinit ice wait lucid \
atload"_zsh_autosuggest_start"
zinit light zsh-users/zsh-autosuggestions
# additional completions
zinit ice wait lucid blockf as"completion" \
atpull"zinit creinstall -q ."
zinit light zsh-users/zsh-completions
# syntax highlighting
zinit ice wait lucid \
atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay"
zinit light zsh-users/zsh-syntax-highlighting
# oh-my-zsh leftovers
# https://github.com/ohmyzsh/ohmyzsh/tree/master/lib
zinit snippet OMZ::lib/clipboard.zsh
zinit snippet OMZ::lib/termsupport.zsh
# iTerm2 integration
zinit ice lucid \
if'[[ "$TERM_PROGRAM" = "iTerm.app" ]]' \
pick"shell_integration/zsh" \
sbin"utilities/*"
zinit light gnachman/iTerm2-shell-integration
# 1Password plugins: https://developer.1password.com/docs/cli/shell-plugins/
zinit ice \
if"command -v op &>/dev/null" \
atclone"op completion zsh > _op || true"
zinit snippet ~/.config/op/plugins.sh
# starship prompt
zinit ice from"gh-r" as"command" \
atclone"
./starship init zsh > init.zsh
./starship completions zsh > _starship
" \
atpull"%atclone" \
src"init.zsh"
zinit light starship/starship

View File

@@ -1,171 +0,0 @@
# Make a new directory and `cd` right into it (this seems like a no-brainer)
mkcd() {
mkdir -p -- "$1" &&
cd -P -- "$1"
}
# Start an HTTP server from a directory, optionally specifying the port
serve() {
local port="${1:-8090}"
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn't break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
# Extract a compressed archive without worrying about which tool to use
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Create a git.io short URL (custom slug optional)
# ex: gitio https://github.com/jakejarvis/dotfiles [jakesdotfiles] => https://git.io/jakesdotfiles
# https://blog.github.com/2011-11-10-git-io-github-url-shortener
gitio() {
PARAMS="-F \"url=$1\""
if [ -n "$2" ]; then PARAMS="$PARAMS -F \"code=$2\""; fi
RESPONSE=$(eval "curl -i https://git.io $PARAMS 2>&1" | grep "Location: ")
echo "${RESPONSE//Location: /}"
}
# Push a local SSH public key to another machine
# https://github.com/rtomayko/dotfiles/blob/rtomayko/.bashrc
push_ssh_cert() {
local _host
[ -f ~/.ssh/id_ed25519.pub ] || ssh-keygen -t ed25519
for _host in "$@";
do
echo $_host
ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_ed25519.pub
done
}
# upload file(s) to https://transfer.sh
# https://github.com/dutchcoders/transfer.sh#bash-and-zsh-with-delete-url-delete-token-output-and-prompt-before-uploading
transfer()
{
local file
declare -a file_array
file_array=("${@}")
if [[ "${file_array[@]}" == "" || "${1}" == "--help" || "${1}" == "-h" ]]
then
echo "${0} - Upload arbitrary files to \"transfer.sh\"."
echo ""
echo "Usage: ${0} [options] [<file>]..."
echo ""
echo "OPTIONS:"
echo " -h, --help"
echo " show this message"
echo ""
echo "EXAMPLES:"
echo " Upload a single file from the current working directory:"
echo " ${0} \"image.img\""
echo ""
echo " Upload multiple files from the current working directory:"
echo " ${0} \"image.img\" \"image2.img\""
echo ""
echo " Upload a file from a different directory:"
echo " ${0} \"/tmp/some_file\""
echo ""
echo " Upload all files from the current working directory. Be aware of the webserver's rate limiting!:"
echo " ${0} *"
echo ""
echo " Upload a single file from the current working directory and filter out the delete token and download link:"
echo " ${0} \"image.img\" | awk --field-separator=\": \" '/Delete token:/ { print \$2 } /Download link:/ { print \$2 }'"
echo ""
echo " Show help text from \"transfer.sh\":"
echo " curl --request GET \"https://transfer.sh\""
return 0
else
for file in "${file_array[@]}"
do
if [[ ! -f "${file}" ]]
then
echo -e "\e[01;31m'${file}' could not be found or is not a file.\e[0m" >&2
return 1
fi
done
unset file
fi
local upload_files
local curl_output
local awk_output
du --total --block-size="K" --dereference "${file_array[@]}" >&2
# be compatible with "bash"
if [[ "${ZSH_NAME}" == "zsh" ]]
then
read $'upload_files?\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "transfer.sh"? (Y/n): \e[0m'
elif [[ "${BASH}" == *"bash"* ]]
then
read -p $'\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "transfer.sh"? (Y/n): \e[0m' upload_files
fi
case "${upload_files:-y}" in
"y"|"Y")
# for the sake of the progress bar, execute "curl" for each file.
# the parameters "--include" and "--form" will suppress the progress bar.
for file in "${file_array[@]}"
do
# show delete link and filter out the delete token from the response header after upload.
# it is important to save "curl's" "stdout" via a subshell to a variable or redirect it to another command,
# which just redirects to "stdout" in order to have a sane output afterwards.
# the progress bar is redirected to "stderr" and is only displayed,
# if "stdout" is redirected to something; e.g. ">/dev/null", "tee /dev/null" or "| <some_command>".
# the response header is redirected to "stdout", so redirecting "stdout" to "/dev/null" does not make any sense.
# redirecting "curl's" "stderr" to "stdout" ("2>&1") will suppress the progress bar.
curl_output=$(curl --request PUT --progress-bar --dump-header - --upload-file "${file}" "https://transfer.sh/")
awk_output=$(awk \
'gsub("\r", "", $0) && tolower($1) ~ /x-url-delete/ \
{
delete_link=$2;
print "Delete command: curl --request DELETE " "\""delete_link"\"";
gsub(".*/", "", delete_link);
delete_token=delete_link;
print "Delete token: " delete_token;
}
END{
print "Download link: " $0;
}' <<< "${curl_output}")
# return the results via "stdout", "awk" does not do this for some reason.
echo -e "${awk_output}\n"
# avoid rate limiting as much as possible; nginx: too many requests.
if (( ${#file_array[@]} > 4 ))
then
sleep 5
fi
done
;;
"n"|"N")
return 1
;;
*)
echo -e "\e[01;31mWrong input: '${upload_files}'.\e[0m" >&2
return 1
esac
}

View File

@@ -1,52 +0,0 @@
# ignore literally everything here if this isn't macOS
if [ ! "$(uname)" = "Darwin" ]; then
exit 0
fi
# Default paths
export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin${PATH+:$PATH}"
# Homebrew
export HOMEBREW_PREFIX="/opt/homebrew"
export HOMEBREW_CELLAR="/opt/homebrew/Cellar"
export HOMEBREW_REPOSITORY="/opt/homebrew"
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}"
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:"
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}"
# Remap macOS core utils to GNU equivalents (from coreutils, findutils, gnu-*, etc.):
# https://gist.github.com/skyzyx/3438280b18e4f7c490db8a2a2ca0b9da?permalink_comment_id=3049694#gistcomment-3049694
for p in "$(brew --prefix)"/opt/*/libexec/gnubin; do export PATH=$p:$PATH; done
# Ensure `man` refers to the new binaries:
for p in "$(brew --prefix)"/opt/*/libexec/gnuman; do export MANPATH=$p:$MANPATH; done
# Go
export GOPATH="$HOME/golang"
export PATH="$GOPATH/bin:$PATH"
# rbenv
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1) --with-readline-dir=$(brew --prefix readline) --with-libyaml-dir=$(brew --prefix libyaml)"
if command -v rbenv 1>/dev/null 2>&1; then
eval "$(rbenv init -)"
fi
# OpenJDK
export PATH="$(brew --prefix)/opt/openjdk/bin:$PATH"
# Metasploit
export PATH="/opt/metasploit-framework/bin:$PATH"
# Rust/Cargo
export PATH="$HOME/.cargo/bin:$PATH"
# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
# volta
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"

View File

@@ -1,10 +0,0 @@
# Set iTerm color scheme to Intel blue when session running via Rosetta2
# https://cutecoder.org/software/detecting-apple-silicon-shell-script/
if [[ "$(uname -m)" == "x86_64" && "$(sysctl -in sysctl.proc_translated)" == "1" ]]; then
ARCH_BG="003862" # Intel-ish blue
else
ARCH_BG="0B0B0B" # boring black
fi
# https://iterm2.com/documentation-escape-codes.html
echo -ne "\033]1337;SetColors=bg=${ARCH_BG}\007"