Skip to content

Instantly share code, notes, and snippets.

@danielnegri
Last active February 2, 2026 22:55
Show Gist options
  • Select an option

  • Save danielnegri/6f2e255d2a3d24780a4d4a010aaf6003 to your computer and use it in GitHub Desktop.

Select an option

Save danielnegri/6f2e255d2a3d24780a4d4a010aaf6003 to your computer and use it in GitHub Desktop.
#!/bin/bash
export BASH_SILENCE_DEPRECATION_WARNING=1
# Set colors
export CLICOLORS=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
# Set alias
alias cp="cp -i"
alias curl="/opt/homebrew/opt/curl/bin/curl"
alias dco="docker compose"
alias diff="git diff"
alias egrep="egrep --color=auto"
alias grep="grep --color=auto"
alias here="cd -P ."
alias kube="kubectl"
alias ls="ls -liahG"
alias mv="mv -i"
alias vim="nvim"
# alias pods="kube get pods"
alias propertree=$HOME/Developer/github.com/corpnewt/ProperTree/ProperTree.command
alias proxy="ssh -D 3312 -C2qTnN dns.danielnegri.com"
alias randomhex="hexdump -n 16 -e '4/4 \"%08X\" 1 \"\n\"' /dev/urandom"
alias randomoct="od -A n -t d -N 4 /dev/urandom |tr -d ' '"
alias week="date +%V"
# untar
alias untar='tar xvf'
# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'
# IP addresses
alias pubip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="sudo ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'"
alias ips="sudo ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
# Flush Directory Service cache
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
# View HTTP traffic
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
# Canonical hex dump; some systems have this symlinked
command -v hd > /dev/null || alias hd="hexdump -C"
# OS X has no `md5sum`, so use `md5` as a fallback
command -v md5sum > /dev/null || alias md5sum="md5"
# OS X has no `sha1sum`, so use `shasum` as a fallback
command -v sha1sum > /dev/null || alias sha1sum="shasum"
# Trim new lines and copy to clipboard
alias trd="tr -d '\n' | pbcopy"
# URL-encode strings
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
# Merge PDF files
# Usage: `mergepdf -o output.pdf input{1,2,3}.pdf`
alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py'
# Intuitive map function
# For example, to list all directories that contain a certain file:
# find . -name .gitattributes | map dirname
alias map="xargs -n1"
# One of @janmoesen’s ProTip™s
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
# shellcheck disable=SC2139,SC2140
alias "$method"="lwp-request -m \"$method\""
done
# Kill all the tabs in Chrome to free up memory
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
alias screensaver="open -a /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.ap"
alias camera-fix="sudo killall VDCAssistant"
alias docker-cleanup-containers="docker ps -aq | xargs docker rm"
alias docker-cleanup-images="docker images -qf dangling=true | xargs docker rmi"
# alias docker-cleanup="docker rm $(docker ps -aq) && docker rmi $(docker images -q -f dangling=true)"
alias font-smoothing-disabled="defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO"
source $HOME/.bash_prompt
# Case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob
# Append to the Bash history file, rather than overwriting it
shopt -s histappend
# Autocorrect typos in path names when using `cd`
shopt -s cdspell
# Enable some Bash 4 features when possible:
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux`
# * Recursive globbing, e.g. `echo **/*.txt`
for option in autocd globstar; do
shopt -s "$option" 2> /dev/null
done
# Add tab completion for SSH hostnames based on ~/.ssh/config
# ignoring wildcards
[[ -e "$HOME/.ssh/config" ]] && complete -o "default" \
-o "nospace" \
-W "$(grep "^Host" ~/.ssh/config | \
grep -v "[?*]" | cut -d " " -f2 | \
tr ' ' '\n')" scp sftp ssh
# Setup Golang
# GOVERSION=$(brew list go | head -n 1 | cut -d '/' -f 6)
# GOVERSION=$(brew info go | head -n 1 | awk {'print$3'})
# export GOROOT=$(brew --prefix)/Cellar/go/$GOVERSION/libexec
# export GOROOT=/usr/local/Cellar/go/1.13.4/libexec
export GOPATH=$HOME/Developer/go
export PATH=$PATH:$GOPATH/bin
export GOSUMDB=off
# Java
#export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home"
export JAVA_HOME="/opt/homebrew/opt/openjdk"
# Git bash completion
if [ -f "$HOME/.git-completion.bash" ]; then source "$HOME/.git-completion.bash"; fi
# Setup RVM
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
# . "$(brew --prefix nvm)/nvm.sh"
# Node
# export NODE_ENV=dev
export NPM_AUTH_TOKEN="d3e83202-1988-42cc-bb5a-04890f0977b5"
# Auto-complete
function _makefile_targets {
local curr_arg;
local targets;
# Find makefile targets available in the current directory
targets=''
if [[ -e "$(pwd)/Makefile" ]]; then
targets=$( \
grep -oE '^[a-zA-Z0-9_-]+:' Makefile \
| sed 's/://' \
| tr '\n' ' ' \
)
fi
# Filter targets based on user input to the bash completion
curr_arg=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "${targets[@]}" -- $curr_arg ) );
}
complete -F _makefile_targets make
# Report current working directory of a process by port
function pwdx {
# lsof -a -p $1 -d cwd -n | tail -1 | awk '{print $NF}'
lsof -a -p $1 -d cwd -n
}
portpwdx () {
pid=$(lsof -i :$1 | tail -1 | perl -pe 's/[^\s]+\s+([^\s]+)\s.*/$1/')
if [[ ! -z $pid ]]
then
# echo $pid
pwdx $pid
return 0
else
echo "No process listening to port $1"
return -1
fi
}
function notify {
osascript -e "display notification \"$1 is ready!\""
}
# Tokens
# export HOMEBREW_GITHUB_API_TOKEN=2039f3fd21aa7f33bbd218bd6897bb48c2c84830
eval "$(/opt/homebrew/bin/brew shellenv)"
if which oathtool >/dev/null 2>&1; then
export DEVELOPMENT=true
#mfa stuff move this later
__mfakey () {
key=$(oathtool -b --totp $(pass 2fa/"$@"))
echo $key
if [[ "$OSTYPE" = linux* ]]; then
echo "$key" | xsel -ib
fi
if [[ "$OSTYPE" = darwin* ]]; then
echo $key | pbcopy
fi
}
alias mfakey=__mfakey
# generate pw alias
alias passgen='pwgen -Bsy 28 1 | tr -d "\n" | pbcopy | pbpaste'
fi
# Kubernetes
kubetoken() {
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d ' '
}
# Google Cloud SDK.
if [ -f '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc' ]; then source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc'; fi
if [ -f '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc' ]; then source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc'; fi
# Python
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Rust
[[ -s "$HOME/.cargo/env" ]] && alias rust-update="rustup toolchain install nightly && rustup override set nightly"
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
. "$HOME/.cargo/env"
# Setting PATH for Python 3.12
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:${PATH}"
export PATH
# Sublime Text
export PATH="$PATH:/Applications/Sublime Text.app/Contents/SharedSupport/bin"
# Local
export PATH="$PATH:$HOME/.local/bin"
# Added by LM Studio CLI (lms)
export PATH="$PATH:/Users/daniel/.lmstudio/bin"
# End of LM Studio CLI section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment