My config using zap the minimal zsh plugin manager.
zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh) --branch release-v1Edit 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 | |
| # 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 | |
| # dotenv Auto Loading from https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv | |
| # Filename of the dotenv file to look for | |
| : ${ZSH_DOTENV_FILE:=.env} | |
| # Path to the file containing allowed paths | |
| : ${ZSH_DOTENV_ALLOWED_LIST:="$HOME/.dotenv-allowed.list"} | |
| : ${ZSH_DOTENV_DISALLOWED_LIST:="$HOME/.dotenv-disallowed.list"} | |
| source_env() { | |
| if [[ ! -f "$ZSH_DOTENV_FILE" ]]; then | |
| return | |
| fi | |
| if [[ "$ZSH_DOTENV_PROMPT" != false ]]; then | |
| local confirmation dirpath="${PWD:A}" | |
| # make sure there is an (dis-)allowed file | |
| touch "${ZSH_DOTENV_ALLOWED_LIST}" | |
| touch "${ZSH_DOTENV_DISALLOWED_LIST}" | |
| # early return if disallowed | |
| if command grep -Fx -q "$dirpath" "$ZSH_DOTENV_DISALLOWED_LIST" &>/dev/null; then | |
| return | |
| fi | |
| # check if current directory's .env file is allowed or ask for confirmation | |
| if ! command grep -Fx -q "$dirpath" "$ZSH_DOTENV_ALLOWED_LIST" &>/dev/null; then | |
| # get cursor column and print new line before prompt if not at line beginning | |
| local column | |
| echo -ne "\e[6n" > /dev/tty | |
| read -t 1 -s -d R column < /dev/tty | |
| column="${column##*\[*;}" | |
| [[ $column -eq 1 ]] || echo | |
| # print same-line prompt and output newline character if necessary | |
| echo -n "dotenv: found '$ZSH_DOTENV_FILE' file. Source it? ([Y]es/[n]o/[a]lways/n[e]ver) " | |
| read -k 1 confirmation | |
| [[ "$confirmation" = $'\n' ]] || echo | |
| # check input | |
| case "$confirmation" in | |
| [nN]) return ;; | |
| [aA]) echo "$dirpath" >> "$ZSH_DOTENV_ALLOWED_LIST" ;; | |
| [eE]) echo "$dirpath" >> "$ZSH_DOTENV_DISALLOWED_LIST"; return ;; | |
| *) ;; # interpret anything else as a yes | |
| esac | |
| fi | |
| fi | |
| # test .env syntax | |
| zsh -fn $ZSH_DOTENV_FILE || { | |
| echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2 | |
| return 1 | |
| } | |
| setopt localoptions allexport | |
| source $ZSH_DOTENV_FILE | |
| } | |
| autoload -U add-zsh-hook | |
| add-zsh-hook chpwd source_env | |
| source_env | |
| # 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____ | |
| # Node Optimizations | |
| export NODE_COMPILE_CACHE=~/.cache/nodejs-compile-cache | |
| # 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 | |
| } | |
| # Replace ls with eza | |
| # ld — lists only directories (no files) | |
| ld='eza -lD' | |
| # lf — lists only files (no directories) | |
| lf='eza -lf --color=always | grep -v /' | |
| # lh — lists only hidden files (no directories) | |
| lh='eza -dl .* --group-directories-first' | |
| # ll — lists everything with directories first | |
| ll='eza -al --group-directories-first' | |
| # ls — lists only files sorted by size | |
| alias ls='eza -alf --color=always --sort=size | grep -v /' | |
| # lt — lists everything sorted by time updated | |
| lt='eza -al --sort=modified' |