Skip to content

Instantly share code, notes, and snippets.

@nakwa
Last active December 9, 2025 15:50
Show Gist options
  • Select an option

  • Save nakwa/09069ceba8d8ce59b2ced38d064c1563 to your computer and use it in GitHub Desktop.

Select an option

Save nakwa/09069ceba8d8ce59b2ced38d064c1563 to your computer and use it in GitHub Desktop.
.profile stuff
# Source order:
# .zshenv → [.zprofile if login] → [.zshrc if interactive] → [.zlogin if login] → [.zlogout sometimes].
# ----------------------------------------------------- #
# INIT #
# ----------------------------------------------------- #
autoload -U add-zsh-hook
ulimit -n 10240
# ----------------------------------------------------- #
# PATH #
# ----------------------------------------------------- #
export PATH="$PATH:$HOME/.local/bin"
export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH"
# ----------------------------------------------------- #
# Locales #
# ----------------------------------------------------- #
export LC_ALL=en_US.UTF-8
# ----------------------------------------------------- #
# NVM #
# ----------------------------------------------------- #
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
load-nvmrc() {
if test -f ".nvmrc"; then
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
fi
}
# autoload -U add-zsh-hook
add-zsh-hook chpwd load-nvmrc
load-nvmrc
# ----------------------------------------------------- #
# Env #
# ----------------------------------------------------- #
export GIT_PS1_SHOWDIRTYSTATE=1
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export VISUAL=emacs
export EDITOR="$VISUAL"
export GUI_EDITOR="sublime"
export EMAIL="[email protected]"
export GIT_COMMITTER_NAME="Name"
export GIT_AUTHOR_NAME="Name"
# Fixes error on building python 3.7
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true
# ----------------------------------------------------- #
# Prompt #
# ----------------------------------------------------- #
parse_git_branch() {
branch="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"
if [ -n "$branch" ]; then
echo "(%{$fg[red]%}$branch%{$reset_color%})"
fi
}
PROMPT="%{$fg_bold[green]%}%n%{$reset_color%}:%{$fg_bold[blue]%}%~%{$reset_color%}\$(parse_git_branch)%(?:%{$fg[white]%}$%{$reset_color%}:%{$fg[grey]%}$%{$reset_color%}) "
# ----------------------------------------------------- #
# Core aliases #
# ----------------------------------------------------- #
alias gls='gls --color=auto --group-directories-first --time-style="+%Y-%m-%d %H:%M"'
alias ll='gls -alFh'
alias la='gls -alFh'
alias l='gls -lFh'
alias cd..='cd ..'
alias emacs='emacs -nw'
alias profile="$GUI_EDITOR ~/.profile"
alias devenv="$GUI_EDITOR ~/.dev.env"
alias edit="$GUI_EDITOR . -a"
alias ide="$GUI_EDITOR -a ."
alias reload=". ~/.profile && . ~/.dev.env && reset"
alias desk="cd ~/Desktop"
alias envs="cd ~/Projects/bernstein/.env"
# ----------------------------------------------------- #
# Functions #
# ----------------------------------------------------- #
who_use_this_port(){
lsof -n -i4TCP:$1 | grep LISTEN
}
kill_process() {
ps -ax -o pid= -o ucomm= | awk -v proc="$1" '$2 == proc {print $1}' | xargs -r kill -9
}
find_pidof() {
ps -ax -o pid= -o ucomm= | awk -v proc="$1" '$2 == proc {print $1}' | xargs
}
uncompress_archive() {
tar -xvf $1
}
clean_logs() {
sudo find . -name '*.log' -type f -delete -print
}
clean_tree() {
find . -name '.DS_Store*' -type f -delete -print
find . -name '*~' -type f -delete -print
find . -name '#*#' -type f -delete -print
find . -name 'desktop.ini' -type f -delete -print
find . -name 'Thumbs.db' -type f -delete -print
}
find_file() {
find . -iname "*$1*" -type d -print | sed 's/^/"/;s/$/"/' | xargs -L1 stat -l -t '%FT %T'
find . -iname "*$1*" -type f -print | sed 's/^/"/;s/$/"/' | xargs -L1 stat -l -t '%FT %T'
}
find_in_file() {
grep -rnwl '.' -e "$1" 2>/dev/null
}
add_ssh_to_remote() {
cat ~/.ssh/id_rsa.pub | ssh $@ "(echo 'no' | ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa || true); cat >> ~/.ssh/authorized_keys"
}
git_commit_all() {
BRANCH="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"
COMMIT_MSG=${1:-"Autocommit - $(date) on $BRANCH"}
git add --all
git commit -m $COMMIT_MSG
}
rename_files() {
capture=$(echo $1)
replace=$(echo $2)
if [ -z "$capture" ] || [ -z "$replace" ]; then
echo "Missing parameter: rename \$capture \$replace"
else
find . -type d -name "*$capture*" | while read file ; do
newfile="$(echo ${file} |sed -e "s/$capture/$replace/")" ;
if [ "$newfile" != "$file" ]; then
echo "mv ${file}" "${newfile} "
mv "${file}" "${newfile}" ;
fi
done
find . -type f -name "*$capture*" | while read file ; do
newfile="$(echo ${file} |sed -e "s/$capture/$replace/")" ;
if [ "$newfile" != "$file" ]; then
echo "mv ${file}" "${newfile} "
mv "${file}" "${newfile}" ;
fi
done
fi
}
if [ -f /usr/local/bin/trash ]; then alias rm="/usr/local/bin/trash"; fi
alias searchall=find_in_file
alias search=find_file
alias whouses=who_use_this_port
alias pkill=kill_process
alias pidof=find_pidof
alias clean=clean_tree
alias cleanlogs=clean_logs
alias untar=uncompress_archive
alias enable-ssh=add_ssh_to_remote
alias rmf=rm_force
alias gca=git_commit_all
alias gpo="git push origin HEAD"
alias rename="rename_files"
# ----------------------------------------------------- #
# Shortcuts #
# ----------------------------------------------------- #
# Shortcuts here
# ----------------------------------------------------- #
# Clean up #
# ----------------------------------------------------- #
rm "$HOME/.rdbg_history" &> /dev/null
rm "$HOME/.zsh_history" &> /dev/null
rm "$HOME/.irb-history" &> /dev/null
rm "$HOME/.lesshst" &> /dev/null
rm "$HOME/.zcompdump" &> /dev/null
# ----------------------------------------------------- #
# Dynamically set #
# ----------------------------------------------------- #
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment