Skip to content

Instantly share code, notes, and snippets.

@breiter
Created October 28, 2024 15:20
Show Gist options
  • Save breiter/2fdadc26ed9fd958e23fb0a8ad1356ed to your computer and use it in GitHub Desktop.
Save breiter/2fdadc26ed9fd958e23fb0a8ad1356ed to your computer and use it in GitHub Desktop.
macos zsh config with macports
#!/usr/bin/env zsh
# shellcheck shell=zsh
# globally manipulate paths wiht /etc/paths and /etc/paths.d
# globally manipulate manpath with /etc/manpath and /etc/manpaths.d
# set linux-style command-line with GNU utils
# ********************************************************************************************
# sudo port install bash bash-completion coreutils findutils grep gnutar gawk gsed gwhich wget
# ********************************************************************************************
# then add /opt/local/bin/libexec/gnubin to front of $PATH
# and add add /opt/local/bin/libexec/gnubin/man to manpath
# rust
export RUSTUP_HOME="$HOME/.rustup"
export CARGO_HOME="$HOME/.cargo"
export PATH="$CARGO_HOME/bin:$PATH"
export RUST_BACKTRACE=1
# go
# check for go path set in /etc/paths.d
#export PATH=$PATH:/usr/local/go/bin
export GOPATH="$HOME/go"
export PATH="$PATH:$GOPATH/bin"
# dotnet core global tools
# check for /etc/paths.d/dotnet and /etc/paths.d/dotnet-cli-tools
export PATH="$PATH:$HOME/.dotnet/tools"
# disable dotnet sdk telemetry
# https://learn.microsoft.com/en-us/dotnet/core/tools/telemetry#how-to-opt-out
export DOTNET_CLI_TELEMETRY_OPTOUT=true
# Azure CLI
export PATH="$PATH:$HOME/bin"
#flags to hint build systems to find things in macports
if [[ -d /opt/local ]]; then
export CFLAGS="$CFLAGS -I/opt/local/include"
export CXXFLAGS="$CXXFLAGS -I/opt/local/include"
export LDFLAGS="$LDFLAGS -L/opt/local/lib"
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
fi
# MacPorts Installer addition on 2016-09-22_at_13:35:36: adding an appropriate PATH variable for use with MacPorts.
if [[ $PATH != */opt/local/bin:/opt/local/sbin* ]]; then
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
fi
# Finished adapting your PATH environment variable for use with MacPorts.
if [[ "$MANPATH" == "" ]]; then
export MANPATH="/usr/share/man"
fi
# MacPorts man pages
if [[ $MANPATH != */opt/local/share/man* ]] && [[ $(manpath) != */opt/local/share/man* ]]; then
export MANPATH="/opt/local/share/man:$MANPATH"
fi
# Override BSD utilities with GNU versions
if [[ $PATH != */opt/local/libexec/gnubin* ]]; then
export PATH="/opt/local/libexec/gnubin:$PATH"
fi
if [[ $MANPATH != */opt/local/libexec/gnubin/man* ]] && [[ $(manpath) != */opt/local/libexec/gnubin/man* ]]; then
export MANPATH="/opt/local/libexec/gnubin/man:$MANPATH"
fi
if [ -f /opt/local/libexec/gnubin/which ]; then
which ()
{
(alias; declare -f) | /opt/local/libexec/gnubin/which \
--tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
fi
if [ -f /opt/local/bin/uuid ]; then
alias uuid="uuid -v 4"
fi
#eval $(/usr/libexec/path_helper -s)
# MacPorts Installer addition on 2020-12-18_at_08:06:04: adding an appropriate DISPLAY variable for use with MacPorts.
export DISPLAY=:0
# Finished adapting your DISPLAY environment variable for use with MacPorts.
. "$HOME/.cargo/env"
# Added by OrbStack: command-line tools and integration
# Comment this line if you don't want it to be added again.
# source ~/.orbstack/shell/init.bash 2>/dev/null || :
#!/usr/bin/env zsh
# shellcheck shell=zsh
# zsh-completions; fpath must be set before compinit
[[ -d /opt/local/share/zsh/site-functions/ ]] &&
fpath=(/opt/local/share/zsh/site-functions/ $fpath)
# load zsh plugins
autoload -Uz compinit promptinit colors bashcompinit
compinit #completions system and built-in completions
promptinit #prompt theme system
colors #named ANSI escape sequences for colors
bashcompinit #bash completion support (required for az)
#default prompt theme
prompt default # hostname%
# set prompt
# minimalist prompt:
# '%' traditional for zsh + current git branch
setopt PROMPT_SUBST
# precmd() is executed beore the prompt
function precmd {
# removes the text that ssh puts into the terminal title
printf '\033]0;\007'
}
PROMPT="%% "
# prompt git branch on left
#if [ -f /opt/local/share/git/git-prompt.sh ]; then
# . /opt/local/share/git/git-prompt.sh
# PS1='%{$fg[cyan]%}$(__git_ps1 "[%s] ")%{$reset_color%}%% '
#fi
# prompt git branch on right
if [ -f /opt/local/share/git/git-prompt.sh ]; then
. /opt/local/share/git/git-prompt.sh
RPROMPT='%{$fg_bold[cyan]%}$(__git_ps1 "[%s]")%{$reset_color%}'
fi
# Completions and suggestions
# zsh autosuggestions
[[ -f /opt/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]] &&
source /opt/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# fish-like hisotry search
if [ -f /opt/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh ]; then
source /opt/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
fi
# fish-like syntax highlighting
[[ -f /opt/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]] &&
source /opt/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# enable command-line completion for aws
[[ -f /opt/local/share/zsh/site-functions/aws_zsh_completer.sh ]] &&
source /opt/local/share/zsh/site-functions/aws_zsh_completer.sh
# zsh parameter completion for the dotnet CLI
_dotnet_zsh_complete()
{
local completions=("$(dotnet complete "$words")")
# If the completion list is empty, just continue with filename selection
if [ -z "$completions" ]
then
_arguments '*::arguments: _normal'
return
fi
# This is not a variable assignment, don't remove spaces!
_values = "${(ps:\n:)completions}"
}
compdef _dotnet_zsh_complete dotnet
#enable command-line completion for az cli
if [ -f "$HOME"/lib/azure-cli/az.completion ]; then
#requires bash autocompletion: bashcompinit
. "$HOME"/lib/azure-cli/az.completion
fi
# orbstack completions
if (( $+commands[orbctl] )); then
eval "$(orbctl completion zsh)"
compdef _orb orbctl
compdef _orb orb
fi
# ZSH history config
# share history across multiple zsh sessions
setopt SHARE_HISTORY
# append to history
setopt APPEND_HISTORY
# adds commands as they are typed, not at shell exit
setopt INC_APPEND_HISTORY
# expire duplicates first
setopt HIST_EXPIRE_DUPS_FIRST
# do not store duplications
setopt HIST_IGNORE_DUPS
#ignore duplicates when searching
setopt HIST_FIND_NO_DUPS
# removes blank lines from history
setopt HIST_REDUCE_BLANKS
# enable filename expansion for arguments of the form ‘anything=expression’
setopt magicequalsubst
#colorful
export CLICOLOR=1
# The color designators are as follows:
#
# a black
# b red
# c green
# d brown
# e blue
# f magenta
# g cyan
# h light grey
# A bold black, usually shows up as dark grey
# B bold red
# C bold green
# D bold brown, usually shows up as yellow
# E bold blue
# F bold magenta
# G bold cyan
# H bold light grey; looks like bright white
# x default foreground or background
#
# Note that the above are standard ANSI colors. The actual display may differ depending on the color capabilities of the terminal in use.
#
# The order of the attributes are as follows:
#
# 1. directory
# 2. symbolic link
# 3. socket
# 4. pipe
# 5. executable
# 6. block special
# 7. character special
# 8. executable with setuid bit set
# 9. executable with setgid bit set
# 10. directory writable to others, with sticky bit
# 11. directory writable to others, without sticky bit
if [[ $(which ls) = *gnubin* ]]; then
# GNU ls colors
eval "$(dircolors -b)"
alias ls='ls --color=auto --quoting-style=literal'
else
#BSD ls colors
#default colors
#export LSCOLORS=exfxcxdxbxegedabagacad
export LSCOLORS=xxfxcxdxbxegedabagacad
fi
if [[ $(which grep) = *gnubin* ]]; then
alias grep='grep --color=auto'
alias egrep='grep -E'
export GREP_COLORS='mt=0;36' # regular;foreground-cyan
else
export GREP_OPTIONS='--color=auto'
fi
#BSD grep
export GREP_COLOR='0;36'
#GNU grep
export GREP_COLORS='mt=0;36' # regular;foreground-cyan
export MINICOM='--color on'
export EDITOR=vim
export PAGER="less -R"
if [[ $PATH != *gnubin* ]]; then
#alias GNU coreutil hash utilties to openssl if coreutils are not installed
alias sha1sum="openssl dgst -sha1"
alias sha256sum="openssl dgst -sha256"
alias sha384sum="openssl dgst -sha384"
alias sha512sum="openssl dgst -sha512"
alias md5sum="md5"
fi
# alises for BSD hash utilties
alias sha1="openssl dgst -sha1"
alias sha256="openssl dgst -sha256"
alias sha384="openssl dgst -sha384"
alias sha512="openssl dgst -sha512"
alias rmd160="openssl dgst -rmd160"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment