Add brew shortcuts to .zshrc

A simple port of the "p" package manager, using brew, for macOS.
This commit is contained in:
2024-03-09 15:23:46 +00:00
parent af462076d7
commit 0c315770c5
2 changed files with 75 additions and 4 deletions

View File

@@ -8,6 +8,59 @@ fi
# Open VSCode from the terminal # Open VSCode from the terminal
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;} code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
# Shortcuts for brew and macOS update
p () {
if ! command -v brew &> /dev/null; then
echo "Brew not found. Installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') > ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
case $1 in
install|i)
shift
brew install $*
;;
remove|uninstall|delete|r|d)
shift
brew uninstall $*
;;
update|u)
brew update
;;
list|l)
brew list
;;
macOSupdate|m)
echo "Updating MacOS..."
echo "THE DEVICE WILL RESTART IF NECESSARY."
sudo softwareupdate -iaR
;;
*)
echo "Usage: p {install(i)|remove(r/d)|update(u)|list(l)|macOSupdate(m)} <package>"
;;
esac
}
# Shortcuts to extract files
extract () {
if [[ -z $* ]]; then
echo "No files provided for extraction."
return 1
fi
for file in "$@"; do
case "${file##*.}" in
(zip) unzip "$file" ;;
(tar.gz|tgz|gzip) tar -xzf "$file" ;;
(tar.bz2|tbz2) tar -xf "$file" ;;
(bz2) bunzip2 "$file" ;;
(*) echo "Unsupported file format: $file" ;;
esac
done
}
export ZSH="$HOME/.oh-my-zsh" export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k" ZSH_THEME="powerlevel10k/powerlevel10k"
zstyle ':omz:update' mode auto # update automatically without asking zstyle ':omz:update' mode auto # update automatically without asking
@@ -39,10 +92,6 @@ if [[ -n $SSH_CONNECTION ]]; then
# Compilation flags # Compilation flags
# export ARCHFLAGS="-arch x86_64" # export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
# #
# Example aliases # Example aliases
# alias zshconfig="mate ~/.zshrc" # alias zshconfig="mate ~/.zshrc"

22
MacOS/scripts/moveAppsToBrew.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# List all installed apps
all_apps=(/Applications/*)
# Loop through each app
for app in "${all_apps[@]}"; do
# Extract the app name without the extension (if any)
app_name="${app##*/}"
app_name="${app_name%.*}" # Removes everything after the last dot
# Check if the app name exists in a brew cask
brew search $app_name &> /dev/null
if [ $? -eq 0 ]; then
echo "Found $app_name in Homebrew. Installing..."
brew install --cask --force "$app_name"
else
echo "$app_name not found in Homebrew."
fi
done
echo "All checks completed."