Skip to content

Commit

Permalink
feat: add clean cache dir command
Browse files Browse the repository at this point in the history
  • Loading branch information
gamemaker1 committed Jun 18, 2021
1 parent c239d4c commit e7f6e0c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion source/yeet
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ search_regex="\-s"
remove_regex="\-Rs*"
# yeet -B <path to package dir> - Build an AUR package
build_regex="\-B"
# yeet -C - Clear build directory
clean_regex="\-C"
# yeet -D/F/Q/T [options] - Run pacman -D/F/Q/T
pacman_regex="\-[DFQT].*"
# yeet <package search terms> - Search for a package and install it
Expand Down Expand Up @@ -291,6 +293,11 @@ if [[ "$1" =~ $option_regex ]] || [[ -z "$1" ]]; then
operation="build"
# Shift the params so the second one is the first, the third is the second and so on
shift
elif [[ "$1" =~ $clean_regex ]]; then
# Clear cache dir
operation="clean"
# Shift the params so the second one is the first, the third is the second and so on
shift
elif [[ "$1" =~ $pacman_regex ]]; then
# If the first option is -D/F/Q/T and the like (e.g., -Dkk, -Fy, -Ql, -Tv), then let pacman handle it
operation="pacman"
Expand All @@ -315,7 +322,8 @@ function help {
printw "\e[0;34mInstall the specified package(s) \e[1;33m yeet -S <package name>"
printw "\e[0;34mRemove the specified package(s) \e[1;33m yeet -R <package name>"
printw "\e[0;34mBuild an AUR package \e[1;33m yeet -B <path to package dir>"
printw "\e[0;34mRun pacman -D \e[1;33m yeet -D [options]"
printw "\e[0;34mClear cache directory \e[1;33m yeet -C"
printw "\e[0;34mRun pacman -D \e[1;33m yeet -D [options]"
printw "\e[0;34mRun pacman -F \e[1;33m yeet -F [options]"
printw "\e[0;34mRun pacman -Q \e[1;33m yeet -Q [options]"
printw "\e[0;34mRun pacman -T \e[1;33m yeet -T [options]"
Expand Down Expand Up @@ -537,6 +545,19 @@ function build_packages {
printw "==> Package built; but not installed. Run \`yeet -B $1\` again if you want to install the package."
fi
}
# Clear the build dir
function clean {
printb "==> Clearing cache directory ($CACHE_DIR)"
# Ask the user if they want to clear the build directory
read -p $'\e[1;33m ==> Are you sure you want to clear the cache directory?\e[0m [\e[1;32my\e[0m/\e[1;31mN\e[0m] ' -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
printb "\n==> Removing cache directory..."
rm -rf "$CACHE_DIR"
printg "==> Deleted cache directory!"
else
printr "==> Aborted by user!"
fi
}
# Search for a package and install it
function searchinstall_packages {
# Search for packages
Expand All @@ -562,6 +583,7 @@ case "$operation" in
"updateinstall") updateinstall_packages $*;;
"remove") remove_packages $*;;
"build") build_packages $*;;
"clean") clean $*;;
"pacman") require_root $PACMAN_BIN $*;;
"searchinstall") searchinstall_packages $*;;
esac
Expand Down

0 comments on commit e7f6e0c

Please sign in to comment.