Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI Auto-update toggle #55

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for i in "${files[@]}"; do
touch "$md_dir/$i"
chmod +rwx "$md_dir/$i"
else
sys.log.warn "File $i already exists. Would you like to overwrite it? [ y / n ]"
sys.log.warn "File $i already exists. Would you like to overwrite it? [ y / n (default) ]"
read -r overwrite_file
if [ "$overwrite_file" = "y" ]; then
rm "$md_dir/$i"
Expand All @@ -59,7 +59,7 @@ for i in "${files[@]}"; do
read -r gitorg
{ echo "default=$gitorg"; } >> "$md_dir/$i"
elif [ "$i" = "dir-aliases.txt" ]; then
sys.log.h1 "Would you like to include the default directory aliases? [ y / n ]"
sys.log.h1 "Would you like to include the default directory aliases? [ y / n (default) ]"
read -r keep_default_diraliases
if [ "$keep_default_diraliases" = "y" ]; then
{ echo "docs=~/Documents"; echo "down=~/Downloads"; } >> "$md_dir/$i"
Expand All @@ -68,6 +68,22 @@ for i in "${files[@]}"; do
sys.log.info "Run configs flushed"
elif [ "$i" = ".env" ]; then
sys.log.info "Environment variables flushed"
echo ""
sys.log.h1 "Would you like the WYX-CLI to auto-update? [ y / n (default) ]"
read -r wyx_auto_update
if [ "$wyx_auto_update" = "y" ]; then
{ echo "WYX_GIT_AUTO_UPDATE=true"; } >> "$md_dir/$i"
else
{ echo "WYX_GIT_AUTO_UPDATE=false"; } >> "$md_dir/$i"
fi
echo ""
sys.log.h1 "Would you like to enable WYX-CLI smart commit? [ y / n (default) ]"
read -r wyx_smart_commit
if [ "$wyx_smart_commit" = "y" ]; then
{ echo "USE_SMART_COMMIT=true"; } >> "$md_dir/$i"
else
{ echo "USE_SMART_COMMIT=false"; } >> "$md_dir/$i"
fi
elif [ "$i" = "todo.txt" ]; then
sys.log.info "TODO flushed"
{ echo "TODO:"; echo ""; } >> "$md_dir/$i"
Expand Down Expand Up @@ -113,7 +129,7 @@ if [ "$dir_file" = "" ]; then
echo "The default directory aliases setup are as follows:"
echo "1) docs = ~/Documents"
echo "2) down = ~/Downloads"
sys.log.h1 "Would you like to include these? [ y / n ]"
sys.log.h1 "Would you like to include these? [ y / n (default) ]"
read -r keep_default_diraliases
if [ "$keep_default_diraliases" = "y" ]; then
{ echo "docs=~/Documents"; echo "down=~/Downloads"; } >> $md_dir/dir-aliases.txt
Expand All @@ -128,7 +144,7 @@ sys.log.info "Okay we should be good to go!"
envfile=$(sys.shell.envfile)
wyx_alias=$(cat "$envfile" | grep -c "alias wyx")
if [ "$wyx_alias" != "" ]; then
sys.log.warn "It looks like you already have a wyx alias setup. Would you like to overwrite it? [ y / n ]"
sys.log.warn "It looks like you already have a wyx alias setup. Would you like to overwrite it? [ y / n (default) ]"
read -r overwrite_alias
if [ "$overwrite_alias" = "y" ]; then
echo "${ORANGE}Please edit the $envfile file manually to remove your old alias${RESET}"
Expand All @@ -143,7 +159,7 @@ completionfile="$HOME/.bash_completion"
if [ -f "$completionfile" ]; then
completion_search=$(cat "$completionfile" | grep -c "$(pwd)/completion.sh")
if [ "$completion_search" != "" ]; then
sys.log.warn "It looks like you already have wyx completion setup. Would you like to overwrite it? [ y / n ]"
sys.log.warn "It looks like you already have wyx completion setup. Would you like to overwrite it? [ y / n (default) ]"
read -r overwrite_completion
if [ "$overwrite_completion" = "y" ]; then
echo "${ORANGE}Please edit the $HOME/.bashrc file manually to remove your old completion${RESET}"
Expand All @@ -154,7 +170,7 @@ if [ -f "$completionfile" ]; then
fi
else
sys.log.warn "It looks like you don't have a $HOME/.bash_completion file (allowing you to use the wyx command with tab-completion)."
sys.log.warn "Would you like to create one? [ y / n ]"
sys.log.warn "Would you like to create one? [ y / n (default) ]"
read -r create_completion
if [ "$create_completion" = "y" ]; then
touch "$HOME/.bash_completion"
Expand Down
2 changes: 1 addition & 1 deletion src/data/arg_scripts.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ issues,issues,"View Your Repository Issues On GitHub",true,,urls
prs,prs,"View Your Repository PRs On GitHub",true,,urls
notifs,notifs,"View Your GitHub Notifications",true,,urls
commits,commits,"View Your Branch Git Commits",true,,git
lastcommit,lastcommit,"View Your Last Commit & Copy It's ID",true,,git
lastcommit,lastcommit,"View Your Last Commit & Copy It's SHA",true,,git
nb,nb,"Checkout-Add-Commit-Push A New Git Branch",true,"<branch-name?>",git
pr,pr,"Open A Pull Request From Your Current Git Branch on GitHub",true,,git
bpr,bpr,"Checkout-Add-Commit-Push A New Git Branch & Open A PR For It On GitHub",true,"<branch-name?>",git
Expand Down
26 changes: 11 additions & 15 deletions wyx-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,30 @@ sys sys
source $WYX_DIR/src/classes/lib/lib.h
lib lib

branch=""
if git rev-parse --git-dir > /dev/null 2>&1; then
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
fi
remote=$(git config --get remote.origin.url | sed 's/.*\/\([^ ]*\/[^.]*\).*/\1/')
repo_url=${remote#"[email protected]:"}
repo_url=${repo_url%".git"}

wyx_git_branch=""

# AUTO UPDATE CLI

pull() {
if [ "$1" != "$branch" ]; then
git checkout "$1"
if [ "$1" != "$wyx_git_branch" ]; then
git checkout "$1" || return 1
fi
git pull origin "$1"
git pull origin "$1" || return 1
}

wyx_update() {
if ! grep -q "WYX_GIT_AUTO_UPDATE=true" "${WYX_DATA_DIR}/.env" ; then
sys.log.warn "Auto update disabled" && echo ""
return 1
fi
sys.log.info "Checking for updates..."

current_dir=$(pwd)
cd "$WYX_DIR" || return 1
repo_branch=""
if git rev-parse --git-dir > /dev/null 2>&1; then
repo_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
wyx_git_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
fi
if [ "$repo_branch" != "master" ]; then
if [ "$wyx_git_branch" != "master" ]; then
sys.log.warn "Not on master branch, skipping update" && echo ""
cd "$current_dir" || return 1
return 1
Expand All @@ -59,7 +55,7 @@ wyx_update() {
sys.log.info "Up-to-date"
elif [ "$LOCAL" = "$BASE" ]; then
sys.log.info "Updating..."
pull "$branch"
pull "$wyx_git_branch"
elif [ "$REMOTE" = "$BASE" ]; then
echo "Need to push"
else
Expand Down