Skip to content

Commit

Permalink
working initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmetalfanx committed Jan 31, 2023
1 parent e398346 commit 2446372
Showing 1 changed file with 108 additions and 89 deletions.
197 changes: 108 additions & 89 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
#!/bin/bash
clear

zshConfigDir="/home/${USER}/.config/zsh"
zshConfigFile="/home/${USER}/.zshrc"
################################################################################
# General Tasks


function intialTasks
{
# Basic Variables
zshConfigDir="/home/${USER}/.config/zsh"
zshConfigFile="/home/${USER}/.zshrc"

# create a .zshrc file if one doesn't exist already
[ ! -f "${zshConfigFile}" ] && touch "${zshConfigFile}"
}

function backupZSHRC() {
echo -e "Backing up existing zshrc"
cp "${zshConfigFile}" "${zshConfigFile}.backup"

}
backupZSHRC

function clearZSHRC() {
/dev/null > ${zshConfigFile}
return
}
clearZSHRC


# End of Genral Tasks
################################################################################

#########################################################################################
################################################################################
# Plugin Related Code

# Plugin related


# TODO: backup existing zshrc file if it exists

# zsh-users is fine
# ohmyzsh has plugins in a sub-folder ... that may be an issue

function userPrompt() {
read -p "Press Any Key to continue"
Expand All @@ -37,67 +40,73 @@ function downloadZshusersPlugin() {
pluginName=${1}

localZshUsersDir="${zshConfigDir}/${pluginName}"

for currentPlugin in "${@}"
do
do
localZshUsersDir="${zshConfigDir}/${currentPlugin}"


# https://github.com/zsh-users/zsh-autosuggestions
# zsh-users
gitPluginURL="https://github.com/${repoName}/${currentPlugin}"


[ -d "${localZshUsersDir}" ] && rm -rf "${localZshUsersDir}"

echo -e "Downloading ${currentPlugin} to ${zshConfigDir}"
[ ! -d "${localZshUsersDir}" ] && git clone -q "${gitPluginURL}" "${zshConfigDir}/${currentPlugin}"
done

setupPlugins "${@}"
git clone -q "${gitPluginURL}" "${localZshUsersDir}"

userPrompt

setupPlugins "${currentPlugin}"

gitPluginURL=""

done


}

function downloadOhMyZSHPlugin() {
# here "repoName" is set already
# here "repoName" is set already
ohmyzshRepo="https://github.com/ohmyzsh/ohmyzsh.git"
localOhMyZshDir="assets/ohmyzsh"

[ ! -d ${localOhMyZshDir} ] && git clone -q "${ohmyzshRepo}" "${localOhMyZshDir}"

ohmyzshPluginsDir="${localOhMyZshDir}/plugins/"

for currentPlugin in "${@}"
do
do
currentPluginLocalDir="${ohmyzshPluginsDir}${currentPlugin}"

[ -d "${currentPluginLocalDir}" ] && echo -e "Copying ${currentPluginLocalDir} to ${zshConfigDir}"
cp -r "${currentPluginLocalDir}" "${zshConfigDir}"

# for debugging
#ls -al ${zshConfigDir}
done


done

setupPlugins "${@}"
}


# setup .zshrc file
# setup .zshrc file
function setupPlugins() {

echo -e "Setting up plugins in .zshrc file"

for currentPlugin in "${@}"
do
do
currentPluginScriptFile="${zshConfigDir}/${currentPlugin}/${currentPlugin}.plugin.zsh"
echo -e "${currentPluginScriptFile}\v"

echo -e "setting up ${currentPlugin} in zsh config file "
echo -e "source ${currentPluginScriptFile}" >> ${zshConfigFile}
sleep 2
done
echo -e "Setting up ${currentPlugin} in zsh config file"
echo -e "source ${currentPluginScriptFile}" >> "${zshConfigFile}"
sleep 1
done

}


##################################################################################3
# functions that use the functions above

function ohmyzshPlugins() {
function ohmyzshPlugins() {
# - DirHistory: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dirhistory
# - sudo: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/sudo

Expand All @@ -109,88 +118,98 @@ function ohmyzshPlugins() {
function zshUserPlugins() {
## [zsh-users](https://github.com/zsh-users)

# Sources
# Sources
# zsh-autosuggestion: https://github.com/zsh-users/zsh-autosuggestions
# zsh-history-substring-search: https://github.com/zsh-users/zsh-history-substring-search
# zsh-syntax-highlighting: https://github.com/zsh-users/zsh-syntax-highlighting

repoName="zsh-users"

downloadZshusersPlugin "zsh-autosuggestions" "zsh-history-substring-search" "zsh-syntax-highlighting"

}

ohmyzshPlugins
zshUserPlugins

# Plugin related
#####################################################################

##################################################################################################
# End of Plugin related code
################################################################################

################################################################################
# Other various setup functions

# Set up zsh history
# Set up zsh history file in cache location
function createHistoryLocation() {
cacheDir="/home/${USER}/.cache/.zsh/"
zshHistoryFile="${cacheDir}/history"

echo -e "Creating History file to use"

[ ! -d "${cacheDir}" ] && mkdir "${cacheDir}"

touch "${zshHistoryFile}"
# look for cache dir and create it if it doesn't exist, along with the history file and crate that if it doesn't exist
[ ! -d "${cacheDir}" ] && mkdir "${cacheDir}" && [ ! -f "${zshHistoryFile}" ] && touch "${zshHistoryFile}"

# History in cache directory:
echo -e "# History file\nHISTFILE=~/.cache/zsh/history" > "${zshConfigFile}"
echo -e "# History file\nHISTFILE=~/.cache/zsh/history" >> "${zshConfigFile}"

}


# Setip Prompt/Theme
function setupPrompt() {

# NOTE TO SELF: remember to use \" for the lines below when echoing out
echo -e "Setting up Prompt UI (Inspired by Fish/Oh-My-Fish's BobTheFish theme"
echo -e "\n#Prompt UI\n#PROMPT=\"%K{#333333}%M@%B %F{yellow}%1~ #%f %b%k\"\nPROMPT=\"%K{#333333}%M@%B %F{green}%1~ #%f %b%k\"\n" >> ${zshConfigFile}
echo -e "\n#Prompt UI\n#PROMPT=\"%K{#333333}%M@%B %F{yellow}%1~ #%f %b%k\"\nPROMPT=\"%K{#333333}%M@%B %F{green}%1~ #%f %b%k\"\n" >> "${zshConfigFile}"

}
setupPrompt


#################################################
# Alias related
# Alias related
function setupBasicAliases() {

# general aliases adding color
alias ls="ls --color=auto --group-directories-first"
alias grep="grep --color=auto"
echo -en '
# general aliases adding color
alias ls="ls --color=auto --group-directories-first"
alias grep="grep --color=auto"
alias pkill="sudo pkill -9"
alias mkdir="mkdir -pv"
# custom aliases
alias a="sudo apt"
alias hc="history --delete"
alias SS="sudeo systemctl"
alias process="ps aux | grep"
alias ytd="yt-dlp"
# double check this when comcast is back
alias ytda="yt-dlp -x --audio-format mp3 --audio-quality 192kb "
' >> "${zshConfigFile}"
}

function setupGitAliases() {

alias pkill="sudo pkill -9"
alias mkdir="mkdir -pv"
echo -en '
# git aliases
alias gck="git checkout"
alias gc="git commit"
# probably not needed
alias gcm="git commit -m"
alias gbD="git branch -D"
# "git add and clear"
alias gac="git add . -- && clear"
# custom aliases
alias a="sudo apt"
alias hc="history --delete"
alias SS="sudeo systemctl"
alias process="ps aux | grep"
alias ytd="yt-dlp"
# double check this when comcast is back
alias ytda="yt-dlp -x --audio-format mp3 --audio-quality 192kb "
' >> "${zshConfigFile}"
}

function setupGitAliases() {
# git aliases
alias gck="git checkout"
alias gc="git commit"
# probably not needed
alias gcm="git commit -m"
alias gbD="git branch -D"
# "git add and clear"
alias gac="git add . -- && clear"

# i dont want to mess up git repos but could i combine aliases?
# example - gacm="gac && gcm" ' ... so then i'd type ' gacm "foobar message" '
}


source ~/.zshrc
## run functions
intialTasks
backupZSHRC
#clearZSHRC

ohmyzshPlugins
zshUserPlugins

createHistoryLocation
setupPrompt
setupBasicAliases
setupGitAliases

0 comments on commit 2446372

Please sign in to comment.