My config using zap the minimal zsh plugin manager.
zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh) --branch release-v1
Edit the conffig files:
# login shells
code ~/.zprofile
# interactive shells
code ~/.zshrc
eval "$(/opt/homebrew/bin/brew shellenv)" |
# Created by Zap installer | |
[ -f "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" ] && source "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" | |
plug "zsh-users/zsh-autosuggestions" | |
plug "zap-zsh/supercharge" | |
plug "zap-zsh/zap-prompt" | |
plug "zsh-users/zsh-syntax-highlighting" | |
plug "wintermi/zsh-brew" | |
# plug "grigorii-zander/zsh-npm-scripts-autocomplete" | |
plug "lukechilds/zsh-better-npm-completion" | |
plug "zthxxx/zsh-history-enquirer" # Just press ^R (Ctrl + R) to enjoy enhanced history search! | |
# Option Arrow Key Bindings to match Bash if you are 👴🏼 | |
# https://stackoverflow.com/questions/12382499/looking-for-altleftarrowkey-solution-in-zsh | |
bindkey -e | |
bindkey "\e\e[C" forward-word | |
bindkey "\e\e[D" backward-word | |
# npm Autocomplete | |
autoload -Uz compinit | |
compinit | |
source ~/.zsh-better-npm-completion/zsh-better-npm-completion.plugin.zsh | |
# NVM Setup | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm | |
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion | |
# Load NVM Automatically | |
autoload -U add-zsh-hook | |
load-nvmrc() { | |
local node_version="$(nvm version)" | |
local nvmrc_path="$(nvm_find_nvmrc)" | |
if [ -n "$nvmrc_path" ]; then | |
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") | |
if [ "$nvmrc_node_version" = "N/A" ]; then | |
nvm install | |
elif [ "$nvmrc_node_version" != "$node_version" ]; then | |
nvm use | |
fi | |
elif [ "$node_version" != "$(nvm version default)" ]; then | |
# echo "Reverting to nvm default version" | |
nvm use default | |
fi | |
} | |
add-zsh-hook chpwd load-nvmrc | |
load-nvmrc | |
# Load pyenv automatically by appending the following to ~/.zprofile (for login shells) and ~/.zshrc (for interactive shells) : | |
export PYENV_ROOT="$HOME/.pyenv" | |
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" | |
eval "$(pyenv init -)" | |
# ngrok Autocomplete | |
if command -v ngrok &>/dev/null; then | |
eval "$(ngrok completion)" | |
fi | |
# AWS Setup | |
# https://us-east-1.console.aws.amazon.com/iamv2/home?region=us-east-1#/security_credentials/access-key-wizard | |
export AWS_REGION=us-west-2 | |
export AWS_DEFAULT_REGION=us-west-2 | |
export AWS_ACCESS_KEY_ID=___ | |
export AWS_SECRET_ACCESS_KEY=___ | |
# Homebrew | |
export HOMEBREW_GITHUB_API_TOKEN=ghp_ | |
export HOMEBREW_DEVELOPER=true | |
# GitHub ENV Setup | |
export GITHUB_TOKEN=ghp____ | |
# Kill the Docker Desktop app and the VM (excluding vmnetd as it is a service) | |
function kill_docker() { | |
ps ax|grep -i docker|egrep -iv 'grep|com.docker.vmnetd'|awk '{print $1}'|xargs kill | |
} | |
# Change to the Front Folder open in Finder | |
function ff { | |
osascript -e 'tell application "Finder"'\ | |
-e 'if (0 < (count Finder windows)) then'\ | |
-e 'set finderpath to get target of the front window as alias'\ | |
-e 'else'\ | |
-e 'set finderpath to get desktop as alias'\ | |
-e 'end if'\ | |
-e 'get POSIX path of finderpath'\ | |
-e 'end tell';};\ | |
function cdff { cd "`ff $@`" || exit; }; | |
# Print out the machines sleep history | |
function sleephistory { | |
pmset -g log|grep -e " Sleep " -e " Wake " | |
} | |
# Quickly Extract an Archive with a standard command | |
# find . -name "*.7z" -exec 7za x {} \; | |
function xtract { | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xvf $1 ;; | |
*.tbz2) tar xvjf $1 ;; | |
*.tgz) tar xvzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "Unable to extract '$1'" ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
# Convert PNGs to WEBP images | |
function convert_to_webp { | |
for file in *.png | |
do | |
filename=$(basename "$file" .mkv) | |
echo "Processing $filename ..."; | |
# ffmpeg -i "$file" -lossless 1 "$filename.webp" | |
ffmpeg -i "$file" "$filename.webp" | |
done | |
} | |
# Convert MKV video containers to MP4 | |
function mkv_to_mp4 { | |
for video in *.mkv | |
do | |
filename=$(basename "$video" .mkv) | |
echo "Processing $filename ..."; | |
SublerCLI -source "${filename}.mkv" -dest "${filename}.mp4" | |
mp4box -unhint "${filename}.mp4" | |
mp4box -hint "${filename}.mp4" | |
done | |
} | |
# Split a FLAC file with a CUE file | |
function split_flac { | |
cat $1 | shnsplit -o flac -t "%n %t" $2; | |
# cuetag *.cue split-track*.flac; | |
} | |
# Convert a folder of FLAC files to MP3s | |
function flac_to_mp3 { | |
for a in *.flac; do | |
OUTF=${a%.flac}.mp3 | |
ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g` | |
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g` | |
ALBUM=`metaflac "$a" --show-tag=ALBUM | sed s/.*=//g` | |
GENRE=`metaflac "$a" --show-tag=GENRE | sed s/.*=//g` | |
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g` | |
DATE=`metaflac "$a" --show-tag=DATE | sed s/.*=//g` | |
flac -c -d "$a" | lame --noreplaygain -V0 \ | |
--add-id3v2 --pad-id3v2 --ignore-tag-errors --tt "$TITLE" --tn "${TRACKNUMBER:-0}" \ | |
--ta "$ARTIST" --tl "$ALBUM" --ty "$DATE" --tg "${GENRE:-12}" \ | |
- "$OUTF" | |
RESULT=$? | |
if [ "$1" ] && [ "$1" = "-d" ] && [ $RESULT -eq 0 ]; then | |
rm "$a" | |
fi | |
done | |
} | |
# Checksum SHA256 | |
function sha256 { | |
shasum -a 256 "$@"; | |
} | |
# Checksum CRC32 | |
function crc32 { | |
cksum -o3 "$@" | ruby -e 'STDIN.each{|a|a=a.split;printf "%08X\t%s\n",a[0],a[2..-1].join(" ")}'; | |
} | |
# Flush the DNS for every OS version | |
function flush_dns { | |
# http://support.apple.com/kb/ht5343 | |
# sw_vers -productVersion | |
sudo dscacheutil -flushcache; # OSX 10.6 | |
sudo killall -HUP mDNSResponder; # OSX 10.7, 10.8 | |
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder; # OSX 10.9 | |
sudo discoveryutil mdnsflushcache; # OSX 10.10? | |
sudo discoveryutil udnsflushcaches; # OSX 10.10? | |
sudo killall -u _mdnsresponder; # OSX 10.10 | |
# ipconfig /flushdns; # Windows | |
# /etc/init.d/named restart; # Linux | |
# /etc/init.d/sssd restart; # Linux | |
# /etc/init.d/nscd restart; nscd --invalidate hosts; # Linux | |
} | |
# Clone a website with WGET | |
function clone_site { | |
# --restrict-file-names=windows \ | |
# --domains $1 \ | |
wget \ | |
--no-clobber \ | |
--recursive \ | |
--page-requisites \ | |
--html-extension \ | |
--convert-links \ | |
-e robots=off \ | |
--wait 1 \ | |
--keep-session-cookies \ | |
--save-cookies cookies.txt \ | |
--no-parent \ | |
$1 | |
} | |
# Find high ASCII values in a folder of files | |
function find_non_ascii { | |
# ack "[\x80-\xFF]" data/ | |
pcregrep --color='auto' --recursive --line-number "[\x80-\xFF]" $1 | |
} | |
# Fix directory permissions | |
function fix_permissions { | |
sudo chmod o-w /usr/local | |
} |