Expand comments, make arguments verbose, consolidate

On this kick of making sure my dotfiles are an easy to follow living
document, so I'm removing any shorthand, writing better comments, and
added bonus, I consolidated some of the redundant OS checks.
This commit is contained in:
Josh Sherman 2024-06-24 13:06:09 -05:00
parent 5efa8e898e
commit 3b1a3404d6
No known key found for this signature in database
GPG key ID: 55B058A80530EF22
2 changed files with 44 additions and 44 deletions

View file

@ -1,25 +1,31 @@
# Starts with a clean slate
unalias -a unalias -a
# Safety first # Prompt when doing something destructive
alias cp='cp -i' alias cp='cp --interactive'
alias mv='mv -i' alias mv='mv --interactive'
alias rm='rm -i' alias rm='rm --interactive'
# Colorize output, make ls human readable and classify... # Colorize output, make ls human-readable and add classification indicators
if [[ `uname` == Darwin ]]; then if [[ `uname` == Darwin ]]; then
# macOS
alias dircolors='gdircolors' alias dircolors='gdircolors'
alias ls='gls --color=auto -hF' alias ls='gls --color=auto --human-readable --classify'
else
alias ls='ls --color=auto -hF'
# ...and standardize to macOS naming on Linux # Force uuidgen to use lowercase letters like Linux
alias uuidgen='uuidgen | tr A-F a-f'
else
# Linux
alias ls='ls --color=auto --human-readable --classify'
# Use the same open command as macOS
alias open='xdg-open' alias open='xdg-open'
fi fi
# Run ls after cd # Run ls immediately after cd
function cd { builtin cd "$@" && ls } function cd { builtin cd "$@" && ls }
# Colorize cat with bat # Use bat instead of cat for syntax highlighting
if command -v apt-get &> /dev/null; then if command -v apt-get &> /dev/null; then
# Debian # Debian
alias cat='batcat' alias cat='batcat'
@ -28,18 +34,24 @@ else
alias cat='bat' alias cat='bat'
fi fi
# Disk utility aliases # Make disk utility human-readable
alias df='df -h' alias df='df --human-readable'
alias du='du -h' alias du='du --human-readable'
# Colorize output and some exclusions # Colorize grep output and add some exclusions
alias grep="grep --color=auto --exclude-dir={.git,artwork,node_modules,vendor}" alias grep="grep --color=auto --exclude-dir={.git,artwork,node_modules,vendor}"
# Git functions # Use HTTPie in place of the old libwww-perl commands
alias GET='http'
alias POST='http POST'
alias HEAD='http HEAD'
# Get the git branch name for the current directory (used in the prompt)
git_current_branch() { git_current_branch() {
(command git symbolic-ref -q HEAD || command git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null (command git symbolic-ref -q HEAD || command git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
} }
# Get the default branch name for the current directory (usually master or main)
git_default_branch() { git_default_branch() {
(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') 2> /dev/null (git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') 2> /dev/null
} }
@ -72,13 +84,3 @@ alias grb='git rebase'
alias grbm='git rebase $(git_default_branch)' alias grbm='git rebase $(git_default_branch)'
alias grm='git rm' alias grm='git rm'
alias gst='git status' alias gst='git status'
# HTTPie aliases
alias GET='http'
alias POST='http POST'
alias HEAD='http HEAD'
# Universally unique identifier (UUID) generator
if [[ `uname` == Darwin ]]; then
alias uuidgen='uuidgen | tr A-F a-f'
fi

View file

@ -9,21 +9,37 @@ source $HOME/.aliases
eval `dircolors $HOME/.dircolors` eval `dircolors $HOME/.dircolors`
# Load up and configure fzf, nvm, and zsh plugins
if [[ `uname` == Darwin ]]; then if [[ `uname` == Darwin ]]; then
# macOS # macOS
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
source /opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh source /opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
elif command -v apt &> /dev/null; then elif command -v apt &> /dev/null; then
# Debian # Debian
source /usr/share/doc/fzf/examples/completion.zsh source /usr/share/doc/fzf/examples/completion.zsh
source /usr/share/doc/fzf/examples/key-bindings.zsh source /usr/share/doc/fzf/examples/key-bindings.zsh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
source /usr/share/zsh-history-substring-search/zsh-history-substring-search.zsh source /usr/share/zsh-history-substring-search/zsh-history-substring-search.zsh
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
elif command -v pacman &> /dev/null; then elif command -v pacman &> /dev/null; then
# Arch # Arch
source /usr/share/fzf/completion.zsh source /usr/share/fzf/completion.zsh
source /usr/share/fzf/key-bindings.zsh source /usr/share/fzf/key-bindings.zsh
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
source /usr/share/nvm/nvm.sh
source /usr/share/nvm/bash_completion
source /usr/share/nvm/install-nvm-exec
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi fi
@ -79,23 +95,6 @@ PS1='
%F{blue}%~$(git_prompt) %F{blue}%~$(git_prompt)
%F{244}%# %F{reset}' %F{244}%# %F{reset}'
if [[ `uname` == Darwin ]]; then
# macOS
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
elif command -v apt &> /dev/null; then
# Debian
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
elif command -v pacman &> /dev/null; then
# Arch
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
source /usr/share/nvm/nvm.sh
source /usr/share/nvm/bash_completion
source /usr/share/nvm/install-nvm-exec
fi
# Automatically use Node.js version specified in .nvmrc # Automatically use Node.js version specified in .nvmrc
autoload -U add-zsh-hook autoload -U add-zsh-hook
@ -117,5 +116,4 @@ load-nvmrc() {
} }
add-zsh-hook chpwd load-nvmrc add-zsh-hook chpwd load-nvmrc
load-nvmrc load-nvmrc