Skip to content

Instantly share code, notes, and snippets.

@prmichaelsen
Created April 21, 2026 16:34
Show Gist options
  • Select an option

  • Save prmichaelsen/3563183423b4f2a9f22e08b17789571f to your computer and use it in GitHub Desktop.

Select an option

Save prmichaelsen/3563183423b4f2a9f22e08b17789571f to your computer and use it in GitHub Desktop.
.zshrc, abspath util, prompt rice
set -o vi
autoload -Uz compinit
compinit
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm use 20
# Prompt
MAGENTA="%F{magenta}"
CYAN="%F{cyan}"
RESET="%f"
set_my_prompt() {
local current_dir='$(basename "$PWD")'
if [[ "$PWD" == "$HOME"* ]]; then
current_dir="~${PWD#$HOME}"
fi
local custom_date='%D{%Y-%m-%d %H:%M:%S}'
# Update PS1 with the color definitions
PS1="${MAGENTA}${custom_date} ${CYAN}${current_dir}${RESET}
"
}
set_my_prompt
precmd_functions+=(set_my_prompt)
# Call the function to set the initial prompt
set_my_prompt
# Update the prompt for each new command execution
precmd_functions+=(set_my_prompt)
# abspath script alias and completion
alias abspath="$HOME/workplace/scripts/abspath"
source "$HOME/workplace/scripts/abspath-completion.zsh"
checkpoint() {
# Stage all changes in the current directory
git add .
if [ $# -eq 0 ]; then
# If no arguments are provided, stash with a default message.
# 'git stash' is an alias for 'git stash push'.
git stash && git stash apply
else
# If an argument is provided, use it as the stash message.
git stash push -m "$1" && git stash apply
fi
}
# get - Git wrapper that blocks 'clone' unless in ~/workplace subdirectory
get() {
# Check if the command is 'clone'
if [[ "$1" == "clone" ]]; then
# Check if current directory is a subdirectory of ~/workplace
if [[ "$PWD" != "$HOME/workplace"* ]]; then
echo "Error: git clone is only allowed in ~/workplace subdirectories"
echo "Current directory: $PWD"
return 1
fi
fi
# Pass through all commands to git
git "$@"
}
#compdef abspath
# Completion script for abspath command
# This enables file path autocompletion
_abspath() {
_files
}
compdef _abspath abspath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment