Skip to content

Commit

Permalink
Made changes for moving to zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyMSchafer committed Feb 21, 2024
1 parent e421764 commit f7a1634
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 129 deletions.
10 changes: 6 additions & 4 deletions .aliases
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ 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='Gxfxcxdxbxegedabagacad'
export LSCOLORS='Dxexcxdxcxegedabagacad'
# For detailed colors on Mac, run 'man ls' and see the LSCOLORS section


# Always enable colored `grep` output
Expand Down Expand Up @@ -49,5 +49,7 @@ alias reg_mode='defaults write com.apple.dock autohide -bool false && killall Do
defaults write com.apple.menuextra.clock IsAnalog -bool false && killall SystemUIServer;'

alias clean='rm -rf ~/.Trash/*; rm -rf ~/Downloads/*'
alias wipe_env='rm -rf ~/tutorial_env; python3 -m venv ~/tutorial_env'
alias tut_env='source ~/tutorial_env/bin/activate'

# Virtual Environments
alias wipe_env='rm -rf ~/tutorial; python3 -m venv ~/tutorial'
alias tut_env='source ~/tutorial/bin/activate; source ~/.bash_prompt'
155 changes: 59 additions & 96 deletions .bash_prompt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,114 +1,77 @@
# Shell prompt based on the Solarized Dark theme.
# Screenshot: http://i.imgur.com/EkEtphC.png
# Heavily inspired by @necolas’s prompt: https://github.com/necolas/dotfiles
# iTerm → Profiles → Text → use 13pt Monaco with 1.1 vertical spacing.

if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM='gnome-256color';
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM='xterm-256color';
fi;

# Define the prompt_git function for git repository status
prompt_git() {
local s='';
local branchName='';

# Check if the current directory is in a Git repository.
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then

# check if the current directory is in .git before running git checks
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then

# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null;

# Check for uncommitted changes in the index.
if ! $(git diff --quiet --ignore-submodules --cached); then
s+='+';
fi;
local git_status=''
local branchName=''

# Check for unstaged changes.
if ! $(git diff-files --quiet --ignore-submodules --); then
s+='!';
fi;
# 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 untracked files.
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
s+='?';
fi;
# 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+='$'

# Check for stashed files.
if $(git rev-parse --verify refs/stash &>/dev/null); then
s+='$';
fi;
# 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)')"

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

# Get the short symbolic ref.
# If HEAD isn’t a symbolic ref, get the short SHA for the latest commit
# Otherwise, just give up.
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
git rev-parse --short HEAD 2> /dev/null || \
echo '(unknown)')";

[ -n "${s}" ] && s=" [${s}]";
printf "%b on %b%s%s" "${white}" "${blue}" "${branchName}" "${git_status}"
else
return
fi
}

echo -e "${1}${branchName}${2}${s}";
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;
return
fi
}

if tput setaf 1 &> /dev/null; then
tput sgr0; # reset colors
bold=$(tput bold);
reset=$(tput sgr0);
# Solarized colors, taken from http://git.io/solarized-colors.
black=$(tput setaf 0);
blue=$(tput setaf 153);
green=$(tput setaf 71);
orange=$(tput setaf 166);
red=$(tput setaf 167);
white=$(tput setaf 15);
yellow=$(tput setaf 228);
else
bold='';
reset="\e[0m";
black="\e[1;30m";
blue="\e[1;34m";
green="\e[1;32m";
orange="\e[1;33m";
red="\e[1;31m";
white="\e[1;37m";
yellow="\e[1;33m";
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}";
userStyle="${red}"
else
userStyle="${orange}";
fi;
userStyle="${orange}"
fi

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

# Set the terminal title to the current working directory.
PS1="\[\033]0;\w\007\]";
PS1+="\[${bold}\]\n"; # newline
PS1+="\[${userStyle}\]\u"; # username
PS1+="\[${white}\] at ";
PS1+="\[${hostStyle}\]\h"; # host
PS1+="\[${white}\] in ";
PS1+="\[${green}\]\W"; # working directory
PS1+="\$(prompt_git \"\[${white}\] on \[${blue}\]\" \"\[${blue}\]\")"; # Git repository details
PS1+="\n";
PS1+="\[${white}\]\$ \[${reset}\]"; # `$` (and reset color)
export PS1;

PS2="\[${yellow}\]→ \[${reset}\]";
export PS2;
hostStyle="${yellow}"
fi

PS1="\$(prompt_pyenv)" # virtual environment
PS1+="\[${bold}\]\n" # newline
PS1+="\[${userStyle}\]\u" # username
PS1+="\[${white}\] at "
PS1+="\[${hostStyle}\]\h" # host
PS1+="\[${white}\] in "
PS1+="\[${green}\]\W" # working directory
PS1+="\$(prompt_git)" # Git repository details
PS1+="\n"
PS1+="\[${white}\]\$ \[${reset}\]" # `$` (and reset color)
export PS1

PS2="\[${yellow}\]→ \[${reset}\]"
export PS2
Empty file modified .bash_server_prompt
100755 → 100644
Empty file.
Empty file modified .bashrc
100755 → 100644
Empty file.
Empty file modified .gitignore
100755 → 100644
Empty file.
Empty file added .zprofile
Empty file.
Empty file added .zprompt
Empty file.
82 changes: 82 additions & 0 deletions .zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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
Empty file modified LICENSE-MIT.txt
100755 → 100644
Empty file.
44 changes: 27 additions & 17 deletions brew.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/usr/bin/env zsh

# Check if Homebrew is installed
if ! command -v brew &> /dev/null
Expand All @@ -15,25 +15,35 @@ brew upgrade

# Install Brew Packages
brew install python
brew install bash
brew install zsh
brew install tree

# Install MacOS Applications
brew install --cask google-chrome
brew install --cask firefox
brew install --cask brave-browser
brew install --cask sublime-text
brew install --cask virtualbox
brew install --cask sourcetree
brew install --cask spotify
brew install --cask discord
brew install --cask google-drive
brew install --cask skype
brew install --cask gimp
brew install --cask vlc
brew install --cask rectangle
brew install --cask visual-studio-code
brew install --cask postman
# Set the Homebrew zsh as default shell
echo "$(brew --prefix)/bin/zsh" | sudo tee -a /etc/shells >/dev/null
chsh -s "$(brew --prefix)/bin/zsh"

# Define an array of applications to install using Homebrew Cask.
apps=(
"google-chrome"
"firefox"
"brave-browser"
"sublime-text"
"visual-studio-code"
"virtualbox"
"spotify"
"discord"
"google-drive"
"gimp"
"vlc"
"rectangle"
"postman"
)

# Loop over the array to install each application.
for app in "${apps[@]}"; do
brew install --cask "$app"
done

# Install Source Code Pro Font
brew tap homebrew/cask-fonts
Expand Down
24 changes: 12 additions & 12 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#!/bin/zsh
#!/usr/bin/env zsh
############################
# This script creates symlinks from the home directory to any desired dotfiles in ${homedir}/dotfiles
# And also installs Homebrew Packages
# And sets Sublime preferences
############################

if [ "$#" -eq 0 ]; then
homedir=$HOME
homedir=$HOME
else
homedir=$1
homedir=$1
fi

# dotfiles directory
dotfiledir=${homedir}/dotfiles
dotfiledir="${homedir}/dotfiles"

# list of files/folders to symlink in ${homedir}
files="bash_profile bashrc bash_prompt aliases private zshrc zprofile zprompt"
files=(bash_profile bashrc bash_prompt aliases private zshrc zprofile zprompt)

# change to the dotfiles directory
echo "Changing to the ${dotfiledir} directory"
cd ${dotfiledir}
cd "${dotfiledir}" || exit
echo "...done"

# create symlinks (will overwrite old dotfiles)
for file in ${files}; do
echo "Creating symlink to $file in home directory."
ln -sf ${dotfiledir}/.${file} ${homedir}/.${file}
for file in "${files[@]}"; do
echo "Creating symlink to $file in home directory."
ln -sf "${dotfiledir}/.${file}" "${homedir}/.${file}"
done

# Download Git Auto-Completion
curl "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" > ${homedir}/.git-completion.bash
curl "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" > "${homedir}/.git-completion.bash"

# Run the Homebrew Script
./brew.sh
# ./brew.sh

# Run the Sublime Script
./sublime.sh
# ./sublime.sh
2 changes: 2 additions & 0 deletions sublime.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env zsh

# Create Sublime Text directories as they don't exist until Sublime is opened
mkdir -p ~/Library/Application\ Support/Sublime\ Text\ 3/Installed\ Packages/Package\
mkdir -p ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/
Expand Down

0 comments on commit f7a1634

Please sign in to comment.