Skip to content

Commit

Permalink
Release 2.8.3
Browse files Browse the repository at this point in the history
refactor(insteall): Removing code related to custom .zshrc
refactor: Removing more code related to custom .zshrc and older versions of zshbop
fix: Changed zshbop_clean to alert versus a simple message so the action is logged
feat: Added multiple git commands and zipc to create a zip archive
  • Loading branch information
jordantrizz committed May 23, 2023
1 parent b97ed6e commit 7eef735
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 134 deletions.
20 changes: 19 additions & 1 deletion cmds/cmds-file.zsh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -- file
_debug " -- Loading ${(%):-%N}"
help_files[cron]="Commands working with files in Linux" # Help file description
help_files[file]="Commands working with files in Linux" # Help file description
typeset -gA help_file # Init help array.

# -- Compare two directories
help_files[compare-dirs]="Compare two directories"
function compare-dirs () {
local DIR1=$1
local DIR2=$2
Expand All @@ -15,5 +17,21 @@ function compare-dirs () {
diff -rq "$DIR1" "$DIR2"
}

# -- zipc
help_files[zipc]="Zip a directory"
function zipc () {
local DIR=$1
local ZIPNAME=$2

if [[ ! -d "$DIR" ]]; then
echo "Usage: zipc <dir> <zipname>"
return 1
fi

if [[ ! -n "$ZIPNAME" ]]; then
echo "Usage: zipc <dir> <zipname>"
return 1
fi

zip -r "$ZIPNAME" "$DIR"
}
73 changes: 72 additions & 1 deletion cmds/cmds-git.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help_files[git]='Git related commands'
typeset -gA help_git

# - gc
help_git[gcp]='Git commit + push'
help_git[gc]='Git commit + push'
gc () {
_cexists glint
if [[ $? == "0" ]]; then
Expand Down Expand Up @@ -123,5 +123,76 @@ function gcab {
fi
}

# -- gbd - Git branch delete
help_git[gbd]="Delete local and remote branch"
function gbd {
if [[ $# -ne 1 ]]; then
echo "Usage: git-delete-branch branch"
return 1
fi

_loading "Deleting branch $1"
git branch -D $1
git push origin --delete $1
}

# -- gbl
help_git[gbl]="Git branch list"
function gbl {
_loading "Listing local branches"
git branch
echo ""
_loading "Listing remote branches"
git branch -a
}

# -- gtp - Git tag push
help_git[gtp]="Git tag push"
function gtp {
_loading "Pushing tags to origin"
git push origin --tags
}

# -- gpab - Git pull all branches
help_git[gpab]="Git pull all branches"
function gpab {
_loading "Pulling all branches"
git fetch --all
for branch in $(git branch -a | grep -v HEAD); do
git branch --track ${branch##*/} $branch
done
git pull --all
}

# -- gpuab - Git push all branches
help_git[gpuab]="Git push all branches"
function gpuab {
_loading "Pushing all branches"
git push --all -u
}

# -- gpm - Git patch multiple
help_git[gpm]="Git patch multiple"
function gpm {
if [[ $# -ne 1 ]]; then
echo "Usage: git-patch-multiple commit"
return 1
fi

_loading "Creating patch for commit $1 and outputting to multi_commit.patch"
git format-patch -1 $1 --stdout > multi_commit.patch
_loading "Creating patch for commit $1 and outputting to multi_commit.patch"
git format-patch -1 $1 --stdout > multi_commit.patch
}

# -- gpa - Git patch apply
help_git[gpa]="Git patch apply"
function gpa {
if [[ $# -ne 1 ]]; then
echo "Usage: git-patch-apply patch"
return 1
fi

_loading "Applying patch $1"
git apply $1
}
41 changes: 26 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
VERSION="0.0.3"
SKIPDEP="0"
HELP="0"
# TODO - Add install to zshbop.zsh
REQUIRED_SOFTWARE=('jq' 'curl' 'zsh' 'git' 'md5sum' 'sudo' 'screen' 'git' 'joe' 'dnsutils'
'net-tools' 'dmidecode' 'virtwhat' 'wget' 'unzip' 'zip' 'python3' 'python3-pip'
'net-tools' 'dmidecode' 'virt-what' 'wget' 'unzip' 'zip' 'python3' 'python3-pip'
'bc' 'whois' 'telnet' 'lynx' 'traceroute' 'mtr' 'mosh' 'tree' 'ncdu' 'fpart'
'jq')
# -- Colors
Expand Down Expand Up @@ -193,21 +194,31 @@ clone_repository() {
}

# -- setup_home
setup_home() {
if ! [ -f $HOME/.zshrc ]; then
if [[ $1 == "git" ]]; then
SETUP_PATH="$HOME/git"
echo "- Install path - $SETUP_PATH"
else
SETUP_PATH="$HOME"
echo "- Install path - $SETUP_PATH"
fi
clone_repository "$SETUP_PATH/zshbop"
cp $SETUP_PATH/zshbop/.zshrc $HOME/.zshrc
_success "- ZSH in-place at $SETUP_PATH, type zsh to start your shell\n"
setup_home() {
# -- Setup Home
if [[ $1 == "git" ]]; then
SETUP_PATH="$HOME/git"
else
_error "- There's already a .zshrc in-place, remove it and re-run\n"
exit 1
SETUP_PATH="$HOME"
fi

# -- Clone Repository
echo "- Install path - $SETUP_PATH"
clone_repository "$SETUP_PATH/zshbop"

# -- Setup .zshrc
if ! [ -f $HOME/.zshrc ]; then
echo "source $SETUP_PATH/zshbop/zshbop.zsh" >> $HOME/.zshrc
_success "- ZSH in-place at $SETUP_PATH, type zsh to start your shell\n"
else
_error "- There's already a .zshrc in-place, exiting.\n"
echo "You can add the following to your .zshrc file:"
echo ""
echo "source $SETUP_PATH/zshbop/zshbop.zsh"
echo ""
echo "Then type zsh to start your shell"
echo ""
exit 1
fi
}

Expand Down
130 changes: 30 additions & 100 deletions lib/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -254,80 +254,6 @@ zshbop_previous-version-check () {
fi
}

# -----------------------
# -- zshbop_migrate-check
# -----------------------
help_zshbop[migrate-check]='Check if running old zshbop.'
zshbop_migrate-check () {
_debug_all
_log "Checking for legacy zshbop"
FOUND="0"
for ZBPATH_MIGRATE in "${ZSHBOP_MIGRATE_PATHS[@]}"; do
if [ -d "$ZBPATH_MIGRATE" ]; then
_error "Detected old zshbop under $ZBPATH_MIGRATE, run 'zshbop migrate'";
FOUND="1"
fi
done
if [[ "$FOUND" == "0" ]]; then
_dlog "Don't need to migrate legacy zshbop"
fi

_log "-- Checking for github modules"
if [ -d "$ZSHBOP_ROOT/ultimate-linux-tool-box" ]; then
_debug "Found old ultimate-linux-tool-box"
_warning "Found ultimate-linux-tool-box run 'zshbop migrate'"
else
_log "Didn't find ultimate-linux-tool-box"
fi

if [ -d "$ZSHBOP_ROOT/ultimate-wordpress-tools" ]; then
_debug "Found old ultimate-wordpress-tools"
_warning "Found ultimate-wordpress-tools run 'zshbop migrate'"
else
_log "Didn't find ultimate-wordpress-tools"
fi

}
# --------------------
# -- zshbop_migrate ()
# --------------------
help_zshbop[migrate]='Migrate old zshbop to new zshbop'
zshbop_migrate () {
_debug_all
_debug " -- Migrate old zshbop to legacy zshbop"
FOUND="0"
for ZBPATH_MIGRATE in "${ZSHBOP_MIGRATE_PATHS[@]}"; do
if [ -d "$ZBPATH_MIGRATE" ]; then
_success "Found legacy zshbop...migrating"
echo " -- Moving $ZBPATH_MIGRATE to ${ZBPATH_MIGRATE}bop"
sudo mv $ZBPATH_MIGRATE ${ZBPATH_MIGRATE}bop
echo " -- Copying ${ZBPATH_MIGRATE}bop/.zshrc to your $HOME/.zshrc"
cp ${ZBPATH_MIGRATE}bop/.zshrc $HOME/.zshrc
FOUND="1"
fi
done
if [[ "$FOUND" == "0" ]]; then
_debug " -- Don't need to migrate legacy zshbop"
fi

_debug "-- Checking for github modules"
if [ -d "$ZSHBOP_ROOT/ultimate-linux-tool-box" ]; then
_debug "Found old ultimate-linux-tool-box"
_warning "Found ultimate-linux-tool-box, removing folder"
rm -r $ZSHBOP_ROOT/ultimate-linux-tool-box
else
_debug "Didn't find ultimate-linux-tool-box"
fi

if [ -d "$ZSHBOP_ROOT/ultimate-wordpress-tools" ]; then
_debug "Found old ultimate-wordpress-tools"
_warning "Found ultimate-wordpress-tools, removing folder."
rm -r $ZSHBOP_ROOT/ultimate-wordpress-tools
else
_debug "Didn't find ultimate-wordpress-tools"
fi
}

# --------------------
# -- zshbop_version ()
# --------------------
Expand All @@ -338,32 +264,7 @@ zshbop_version () {

help_zshbop[commit]='Get commit information'
zshbop_commit () {
echo "zshbop Commit: ${fg[black]}${bg[cyan]}${ZSHBOP_BRANCH}${reset_color}${fg[green]}/$ZSHBOP_COMMIT${RSC} | Install .zshrc MD5: $fg[green]$ZSHBOP_HOME_MD5${RSC}"
}

# --------------------------
# -- zshbop_version_check ()
# --------------------------
help_zshbop[version-check]='Check zshbop version'
zshbop_version-check () {
# -- check .zshrc
_loading "zshbop Version Check"
zshbop_version
echo "-- Latest zshbop .zshrc: $fg[green]$ZSHBOP_LATEST_MD5${RSC}"
echo "-- \$ZSHBOP/.zshrc: $fg[green]$ZSHBOP_INSTALL_MD5${RSC}"
echo "-- \$HOME/.zshrc MD5: $fg[green]$ZSHBOP_HOME_MD5${RSC}"

_loading2 "Checking if $HOME/.zshrc is the same as $ZSHBOP/.zshrc"
if [[ $ZSHBOP_HOME_MD5 == $ZSHBOP_INSTALL_MD5 ]]; then
_success " \$HOME/.zshrc and \$ZSHBOP/.zshrc are the same."
else
_error " \$HOME/.zshrc and \$ZSHBOP/.zshrc are the different."
fi

# -- checking branch git commit versus current commit
_loading "Checking for branch updates"
echo "-- Current Commit : $fg[green]"

echo "zshbop Commit: ${fg[black]}${bg[cyan]}${ZSHBOP_BRANCH}${reset_color}${fg[green]}/$ZSHBOP_COMMIT${RSC}"
}

# ------------------
Expand Down Expand Up @@ -633,6 +534,35 @@ fucntion zshbop_install-env () {
_log "${funcstack[1]}:stop"
}

# -- zshbop_cleanup
help_zshbop[cleanup]='Cleanup old things'
function zshbop_cleanup () {
_log "${funcstack[1]}:start"
# -- older .zshrc
OLD_ZSHRC_MD5SUM=(
"09fcdc31ca648bb15f7bb7ff90d0539a"
"256bb9511533e9697f639821ba63adb9"
"46c094ff2b56af2af23c5b848d46f997"
)
ZSHRC_MD5SUM="$(md5sum $HOME/.zshrc | awk {' print $1'})"
_loading "ZSH Cleanup"
_log "Checking for old .zshrc against $ZSHRC_MD5SUM"
if [[ -f $HOME/.zshrc ]]; then
_log "Found $HOME/.zshrc md5sum:$ZSHRC_MD5SUM"
for i in $OLD_ZSHRC_MD5SUM; do
_log "CUR:$ZSHRC_MD5SUM vs OLD:$i"
if [[ $i == $ZSHRC_MD5SUM ]]; then
_alert "md5sum matched - Removing old .zshrc"
rm $HOME/.zshrc
echo "source $ZSHBOP_ROOT/zshbop.zsh" > $HOME/.zshrc
else
_log "md5sum did not match"
fi
done
else
_log "No .zshrc found"
fi
}

# ==============================================
# ==============================================
Expand Down
6 changes: 0 additions & 6 deletions lib/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,6 @@ init_motd () {
# -- OS specific motd
_loading3 "Operating System - ${MACHINE_OS} - ${MACHINE_OS_FLAVOUR}"

# -- check for old instances
_debug "Old Instance Check"
zshbop_migrate-check
zshbop_previous-version-check
echo ""

# -- system details
_loading "System details"
sysfetch | _pipe_separate 2 | sed 's/^/ /'
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.2
2.8.3
12 changes: 2 additions & 10 deletions zshbop.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ export ZSHBOP_RELOAD="0"
export ZSHBOP_BRANCH=$(git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT rev-parse --abbrev-ref HEAD) # -- current branch
export ZSHBOP_COMMIT=$(git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT rev-parse HEAD) # -- current commit
export ZSHBOP_REPO="jordantrizz/zshbop" # -- Github repository
export ZSHBOP_MIGRATE_PATHS=("/usr/local/sbin/zsh" "$HOME/zsh" "$HOME/git/zsh") # -- Previous zsbop paths

# -- zshbop md5sum
export ZSHBOP_LATEST_MD5="595a039cd4fc6cd51cc1baf71a3d6b9c" # -- the md5 of .zshrc
export ZSHBOP_HOME_MD5=$(md5sum $HOME/.zshrc | awk {' print $1 '}) # -- Current .zshrc MD5 in $HOME
export ZSHBOP_INSTALL_MD5=$(md5sum $ZSHBOP_ROOT/.zshrc | awk {' print $1 '}) # -- Current .zshrc MD5 in $ZSHBOPROOT

# -- Associative Arrays
typeset -gA help_custom # -- Set help_custom for custom help files
Expand Down Expand Up @@ -106,7 +100,6 @@ setopt share_history # share command history data
# ---- Debugging and Logging
###########################################################


# --------------------------------
# -- Logging
# --------------------------------
Expand Down Expand Up @@ -193,9 +186,8 @@ if [[ -f $HOME/.zshbop.config ]]; then
source $HOME/.zshbop.config
fi

# -- Check for old versions
zshbop_previous-version-check
zshbop_migrate
# -- Check for old bits
zshbop_cleanup

###########################################################
###########################################################
Expand Down

0 comments on commit 7eef735

Please sign in to comment.