Skip to content

Commit

Permalink
Major 2024 Update. Switching to zsh and VS Code. Added a lot of error…
Browse files Browse the repository at this point in the history
… checks and took out a lot of hard-coded references so that these are more portable.
  • Loading branch information
CoreyMSchafer committed Feb 26, 2024
1 parent f7a1634 commit 46a469e
Show file tree
Hide file tree
Showing 26 changed files with 864 additions and 364 deletions.
22 changes: 11 additions & 11 deletions .aliases
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ alias cyt='cd ~/Google\ Drive/YouTube/Scripts/'
alias oyt='open ~/Google\ Drive/YouTube/Scripts/'

# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
colorflag="--color"
if ls --color >/dev/null 2>&1; then # GNU `ls`
colorflag="--color"
else # OS X `ls`
colorflag="-G"
colorflag="-G"
fi

# List all files colorized in long format, including dot files
alias la="ls -lahF ${colorflag}"

# Always use color output for `ls`
alias ls="command ls ${colorflag}"
export LS_COLORS='no=00:fi=00:di=04;35:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
export LSCOLORS='Dxexcxdxcxegedabagacad'
# For detailed colors on Mac, run 'man ls' and see the LSCOLORS section

export LSCOLORS='Dxexcxdxcxegedabagacad'
export LS_COLORS='no=00:fi=00:di=04;35:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'

# Always enable colored `grep` output
# Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage.
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

# Enable aliases to be sudo’ed
alias sudo='sudo '

# Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
# Get OS X Software Updates
alias update_system='sudo softwareupdate -i -a'

# Update/upgrade Homebrew and their installed packages
alias update_brew='brew update; brew upgrade; brew upgrade --cask; brew cleanup'

# Show/hide hidden files in Finder
# As of macOS Sierra (10.12) and later, you can simply press Cmd + Shift + . (period) while in Finder to toggle the visibility of hidden files.
alias show="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
alias hide="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"

Expand All @@ -52,4 +52,4 @@ alias clean='rm -rf ~/.Trash/*; rm -rf ~/Downloads/*'

# Virtual Environments
alias wipe_env='rm -rf ~/tutorial; python3 -m venv ~/tutorial'
alias tut_env='source ~/tutorial/bin/activate; source ~/.bash_prompt'
alias tut_env='source ~/tutorial/bin/activate'
16 changes: 4 additions & 12 deletions .bash_profile
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# Simplified dotfile for video recordings

# Load dotfiles:
for file in ~/.{bash_prompt,aliases,private}; do
[ -r "$file" ] && [ -f "$file" ] && source "$file";
done;
unset file;

#Git auto-complete
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
# Load .bashrc if available
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

# Setting PATH for Python 3.7
# PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
# export PATH
# export PATH
64 changes: 2 additions & 62 deletions .bash_prompt
Original file line number Diff line number Diff line change
@@ -1,67 +1,7 @@
# Define the prompt_git function for git repository status
prompt_git() {
local git_status=''
local branchName=''

# Check if the current directory is in a Git repository.
if git rev-parse --is-inside-work-tree &>/dev/null; then
# Get the status summary.
local gitSummary=$(git status --porcelain)
source "${HOME}/dotfiles/.shared_prompt"

# Check for uncommitted changes in the index, unstaged changes, untracked files, and stashed files.
[[ -n $(echo "$gitSummary" | grep '^M') ]] && git_status+='+'
[[ -n $(echo "$gitSummary" | grep '^ M') ]] && git_status+='!'
[[ -n $(echo "$gitSummary" | grep '^\?\?') ]] && git_status+='?'
[[ $(git rev-parse --verify refs/stash &>/dev/null; echo "${?}") == '0' ]] && git_status+='$'

# Get the short symbolic ref or the short SHA for the latest commit.
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null || echo '(unknown)')"

[ -n "${git_status}" ] && git_status=" [${git_status}]"

printf "%b on %b%s%s" "${white}" "${blue}" "${branchName}" "${git_status}"
else
return
fi
}

prompt_pyenv() {
if [ -n "${VIRTUAL_ENV_PROMPT:-}" ] && [ -n "${_OLD_VIRTUAL_PS1:-}" ]; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
printf "\n%bVENV: %s\n" "${steel_blue}" "${VIRTUAL_ENV_PROMPT}"
else
return
fi
}

# Using tput for colors and formatting.
tput sgr0 # reset colors
bold=$(tput bold)
reset=$(tput sgr0)
blue=$(tput setaf 153)
steel_blue=$(tput setaf 67)
green=$(tput setaf 71)
orange=$(tput setaf 166)
red=$(tput setaf 167)
white=$(tput setaf 15)
yellow=$(tput setaf 228)

# Highlight the user name when logged in as root.
if [[ "${USER}" == "root" ]]; then
userStyle="${red}"
else
userStyle="${orange}"
fi

# Highlight the hostname when connected via SSH.
if [[ "${SSH_TTY}" ]]; then
hostStyle="${bold}${red}"
else
hostStyle="${yellow}"
fi

PS1="\$(prompt_pyenv)" # virtual environment
PS1="\$(prompt_venv)" # virtual environment
PS1+="\[${bold}\]\n" # newline
PS1+="\[${userStyle}\]\u" # username
PS1+="\[${white}\] at "
Expand Down
10 changes: 7 additions & 3 deletions .bashrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# If not running interactively, don't do anything
[[ $- == *i* ]] || return
# If not running interactively, exit script
[[ $- != *i* ]] && return

[ -n "$PS1" ] && source ~/.bash_profile;
# Load dotfiles:
for file in ~/.{bash_prompt,aliases,private}; do
[ -r "$file" ] && [ -f "$file" ] && source "$file";
done;
unset file;
64 changes: 64 additions & 0 deletions .shared_prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Define the prompt_git function for git repository status
prompt_git() {
local git_status=''
local branchName=''

# Check if the current directory is in a Git repository.
if git rev-parse --is-inside-work-tree &>/dev/null; then
# Get the status summary.
local gitSummary=$(git status --porcelain)

# Check for uncommitted changes in the index, unstaged changes, untracked files, and stashed files.
[[ -n $(echo "$gitSummary" | grep '^M') ]] && git_status+='+'
[[ -n $(echo "$gitSummary" | grep '^ M') ]] && git_status+='!'
[[ -n $(echo "$gitSummary" | grep '^\?\?') ]] && git_status+='?'
[[ $(
git rev-parse --verify refs/stash &>/dev/null
echo "${?}"
) == '0' ]] && git_status+='$'

# Get the short symbolic ref or the short SHA for the latest commit.
branchName="$(git symbolic-ref --quiet --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo '(unknown)')"

[ -n "${git_status}" ] && git_status=" [${git_status}]"

printf "%b on %b%s%s" "${white}" "${blue}" "${branchName}" "${git_status}"
else
return
fi
}

export VIRTUAL_ENV_DISABLE_PROMPT=1
prompt_venv() {
if [[ -n "$VIRTUAL_ENV" ]]; then
# Extract the last directory name in the $VIRTUAL_ENV path
venv_name=$(basename "$VIRTUAL_ENV")
printf "\n%b(%s)\n" "${steel_blue}" "${venv_name}"
fi
}

# Using tput for colors and formatting.
tput sgr0 # reset colors
bold=$(tput bold)
reset=$(tput sgr0)
blue=$(tput setaf 153)
steel_blue=$(tput setaf 67)
green=$(tput setaf 71)
orange=$(tput setaf 166)
red=$(tput setaf 167)
white=$(tput setaf 15)
yellow=$(tput setaf 228)

# Highlight the user name when logged in as root.
if [[ "${USER}" == "root" ]]; then
userStyle="${red}"
else
userStyle="${orange}"
fi

# Highlight the hostname when connected via SSH.
if [[ "${SSH_TTY}" ]]; then
hostStyle="${bold}${red}"
else
hostStyle="${yellow}"
fi
17 changes: 17 additions & 0 deletions .zprompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

source "${HOME}/dotfiles/.shared_prompt"

PS1="\$(prompt_venv)" # virtual environment
PS1+="%{${bold}%}"$'\n' # newline
PS1+="%{${userStyle}%}%n" # username
PS1+="%{${white}%} at "
PS1+="%{${hostStyle}%}%m" # host
PS1+="%{${white}%} in "
PS1+="%{${green}%}%c" # working directory
PS1+="\$(prompt_git)" # Git repository details
PS1+=$'\n'
PS1+="%{${white}%}\$ %{${reset}%}" # `$` (and reset color)
export PS1

PS2="%{${yellow}%}→ %{${reset}%}"
export PS2
83 changes: 5 additions & 78 deletions .zshrc
Original file line number Diff line number Diff line change
@@ -1,82 +1,9 @@
# Define the prompt_git function for git repository status
prompt_git() {
local git_status=''
local branchName=''

# Check if the current directory is in a Git repository.
if git rev-parse --is-inside-work-tree &>/dev/null; then
# Get the status summary.
local gitSummary=$(git status --porcelain)

# Check for uncommitted changes in the index, unstaged changes, untracked files, and stashed files.
[[ -n $(echo "$gitSummary" | grep '^M') ]] && git_status+='+'
[[ -n $(echo "$gitSummary" | grep '^ M') ]] && git_status+='!'
[[ -n $(echo "$gitSummary" | grep '^\?\?') ]] && git_status+='?'
[[ $(git rev-parse --verify refs/stash &>/dev/null; echo "${?}") == '0' ]] && git_status+='$'

# Get the short symbolic ref or the short SHA for the latest commit.
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null || echo '(unknown)')"

[ -n "${git_status}" ] && git_status=" [${git_status}]"

printf "%b on %b%s%s" "${white}" "${blue}" "${branchName}" "${git_status}"

else
return
fi
}

prompt_pyenv() {
if [ -n "${VIRTUAL_ENV_PROMPT:-}" ] && [ -n "${_OLD_VIRTUAL_PS1:-}" ]; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
printf "\n%bVENV: %s\n" "${steel_blue}" "${VIRTUAL_ENV_PROMPT}"
else
return
fi
}

# Initialize color variables using tput. This should work similarly in Zsh.
autoload -Uz colors && colors
tput sgr0; # reset colors
bold=$(tput bold)
reset=$(tput sgr0)
blue=$(tput setaf 153)
steel_blue=$(tput setaf 67)
green=$(tput setaf 71)
orange=$(tput setaf 166)
red=$(tput setaf 167)
white=$(tput setaf 15)
yellow=$(tput setaf 228)

# Highlight the user name when logged in as root.
if [[ "${USER}" == "root" ]]; then
userStyle="${red}"
else
userStyle="${orange}"
fi

# Highlight the hostname when connected via SSH.
if [[ "${SSH_TTY}" ]]; then
hostStyle="${bold}${red}"
else
hostStyle="${yellow}"
fi

setopt PROMPT_SUBST

# Properly using variables and command substitution in Zsh PROMPT
PS1="\$(prompt_pyenv)"
PS1+="%{${bold}%}"$'\n'
PS1+="%{${userStyle}%}%n"
PS1+="%{${white}%} at "
PS1+="%{${hostStyle}%}%m"
PS1+="%{${white}%} in "
PS1+="%{${green}%}%c"
PS1+="\$(prompt_git)"
PS1+=$'\n'
PS1+="%{${white}%}\$ %{${reset}%}"
export PS1

PS2="%{${yellow}%}→ %{${reset}%}"
export PS2
# Load dotfiles:
for file in ~/.{zprompt,aliases,private}; do
[ -r "$file" ] && [ -f "$file" ] && source "$file";
done;
unset file;
Loading

0 comments on commit 46a469e

Please sign in to comment.