chore(shell): make everything bit faster

This commit is contained in:
2023-09-27 10:38:10 +03:00
parent 6f854ddbfd
commit a87b33b8c2
18 changed files with 159 additions and 109 deletions

View File

@@ -2,6 +2,7 @@
# Install cargo/rust packages.
#
# shellcheck source=shared.sh
DOTFILES_SHARED_LOADED=""
source "$HOME/.dotfiles/scripts/shared.sh"
! have cargo && {

View File

@@ -1,9 +1,10 @@
#!/usr/bin/env bash
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
# shellcheck source=shared.sh
DOTFILES_SHARED_LOADED=""
source "$HOME/.dotfiles/scripts/shared.sh"
PBB_REQUIRED_TOOLS=(basename git mkdir cheat ls grep head awk cp echo rm)
PBB_REQUIRED_TOOLS=(git cheat)
for t in ${PBB_REQUIRED_TOOLS[@]}; do
! have "$t" && echo "(!) $t is missing, can't continue..." && exit 1
done

View File

@@ -1,9 +1,10 @@
#!/usr/bin/env bash
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
# shellcheck source=shared.sh
DOTFILES_SHARED_LOADED=""
source "$HOME/.dotfiles/scripts/shared.sh"
TLDR_REQUIRED_TOOLS=(basename git mkdir cheat ls grep head awk cp echo rm)
TLDR_REQUIRED_TOOLS=(git cheat)
for t in ${TLDR_REQUIRED_TOOLS[@]}; do
! have "$t" && echo "(!) $t is missing, can't continue..." && exit 1
done

View File

@@ -4,6 +4,8 @@
# shellcheck source="shared.sh"
source "$HOME/.dotfiles/scripts/shared.sh"
msg_run "Installing gh (GitHub Client) extensions"
! have gh \
&& msg_err "gh (GitHub Client) could not be found, please install it first" \
&& exit 0
@@ -28,15 +30,13 @@ extensions=(
rsese/gh-actions-status
)
msg "Starting to install GitHub CLI extensions..."
for ext in "${extensions[@]}"; do
# Trim spaces
ext=${ext// /}
# Skip comments
if [[ ${ext:0:1} == "#" ]]; then continue; fi
msg_run "Installing $ext"
msg_nested "Installing $ext"
gh extensions install "$ext"
echo ""
done

View File

@@ -6,7 +6,7 @@
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
msg "Installing git-crypt"
msg_run "Installing git-crypt"
! have git-crypt && {

View File

@@ -4,6 +4,8 @@
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
msg_run "Installing go packages"
! have go && msg "go hasn't been installed yet." && exit 0
packages=(
@@ -33,16 +35,17 @@ for pkg in "${packages[@]}"; do
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_run "Installing go package:" "$pkg"
msg_nested "Installing go package: $pkg"
go install "$pkg"
echo ""
done
msg "Installing completions for selected packages"
msg_run "Installing completions for selected packages"
have git-profile && {
git-profile completion zsh > "$ZSH_CUSTOM_COMPLETION_PATH/_git-profile" \
&& msg_yay "Installed completions for git-profile"
&& msg_ok "Installed completions for git-profile"
}
echo ""
msg_ok "Done"

View File

@@ -8,6 +8,11 @@
[ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
msg_run "Starting to set macOS defaults, these require sudo privileges:"
# Ask for the administrator password upfront
sudo -v
@@ -19,6 +24,8 @@ while true; do
kill -0 "$$" || exit
done 2> /dev/null &
msg_nested "Change user shell to zsh if it is available and not the current"
# Change user shell to zsh if not that already.
if hash zsh 2> /dev/null; then
[[ "$SHELL" != $(which zsh) ]] && chsh -s "$(which zsh)"
@@ -28,6 +35,8 @@ fi
# General UI/UX #
###############################################################################
msg_nested "Setting General UI/UX settings"
# Disable the sound effects on boot
sudo nvram SystemAudioVolume=" "
@@ -80,6 +89,8 @@ defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# SSD-specific tweaks #
###############################################################################
msg_nested "Setting SSD-specific tweaks"
# Disable hibernation (speeds up entering sleep mode)
sudo pmset -a hibernatemode 0
@@ -90,6 +101,8 @@ sudo pmset -a sms 0
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
msg_nested "Settings for Trackpad, mouse, keyboard, Bluetooth accessories, and input"
# Increase sound quality for Bluetooth headphones/headsets
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Max (editable)" 80
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" 80
@@ -124,6 +137,8 @@ defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# Screen #
###############################################################################
msg_nested "Settings for Screen"
# Require password immediately after sleep or screen saver begins
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
@@ -132,6 +147,8 @@ defaults write com.apple.screensaver askForPasswordDelay -int 0
# Finder #
###############################################################################
msg_nested "Settings for Finder"
# Set Desktop as the default location for new Finder windows
# For other paths, use `PfLo` and `file:///full/path/here/`
defaults write com.apple.finder NewWindowTarget -string "PfDe"
@@ -190,6 +207,8 @@ defaults write com.apple.finder FXInfoPanesExpanded -dict \
# Screenshots #
###############################################################################
msg_nested "Settings for Screenshots"
# Set default screenshot location
mkdir -p "$HOME/Documents/Screenshots"
defaults write com.apple.screencapture "location" -string "$HOME/Documents/Screenshots"
@@ -204,6 +223,8 @@ defaults write com.apple.screencapture "name" -string "screenshot"
# Dock, Dashboard, and hot corners #
###############################################################################
msg_nested "Settings for Dock, Dashboard, and hot corners"
# Prevent applications from bouncing in Dock
defaults write com.apple.dock no-bouncing -bool true
@@ -234,6 +255,8 @@ defaults write com.apple.dock showhidden -bool true
# Safari & WebKit #
###############################################################################
msg_nested "Settings for Safari & WebKit"
# Enable Safaris debug menu
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
@@ -258,6 +281,8 @@ defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
# Activity Monitor #
###############################################################################
msg_nested "Settings for ActivityMonitor"
# Show the main window when launching Activity Monitor
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
@@ -275,6 +300,8 @@ defaults write com.apple.ActivityMonitor SortDirection -int 0
# Address Book, Dashboard, iCal, TextEdit, and Disk Utility #
###############################################################################
msg_nested "Settings for Address Book, Dashboard, iCal, TextEdit, and Disk Utility"
# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
@@ -286,6 +313,8 @@ defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
# Messages #
###############################################################################
msg_nested "Settings for Messages"
# Disable smart quotes as its annoying for messages that contain code
defaults write com.apple.messageshelper.MessageController \
SOInputLineSettings \
@@ -298,6 +327,8 @@ defaults write com.apple.messageshelper.MessageController \
-dict-add "continuousSpellCheckingEnabled" \
-bool false
msg_nested "Restarting applications to apply changes"
###############################################################################
# Kill affected applications #
###############################################################################
@@ -307,4 +338,5 @@ for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
"Terminal" "Transmission" "Twitter" "iCal"; do
killall "${app}" > /dev/null 2>&1
done
echo "Done. Note that some of these changes require a logout/restart to take effect."
msg_yay "Done. Note that some of these changes require a logout/restart to take effect."

View File

@@ -6,6 +6,10 @@
# Helper env variables. Use like this: VERBOSE=1 ./script.sh
: "${VERBOSE:=0}"
# If this file has already been loaded, no need to reload it.
[ "$DOTFILES_SHARED_LOADED" = "yes" ] && return
export DOTFILES_SHARED_LOADED="yes"
# -- Colors -- #
CLR_RED="\033[1;31m"
CLR_YELLOW="\033[1;33m"
@@ -201,7 +205,7 @@ function menu_usage()
if command -v bkt >&/dev/null; then
bkt()
{
command bkt "$@"
command bkt --cache-dir="$XDG_CACHE_HOME/bkt" "$@"
}
else
# If bkt isn't installed skip its arguments and just execute directly.
@@ -213,7 +217,16 @@ else
}
fi
# shorthand for checking if the system has the bin in path.
# shorthand for checking if the system has the bin in path,
# this version does not use caching
# usage: have_command php && php -v
function have_command
{
command -v "$1" >&/dev/null
}
# shorthand for checking if the system has the bin in path,
# this version uses caching
# usage: have php && php -v
function have
{
@@ -357,3 +370,9 @@ ask()
fi
done
}
# Check if a file contains non-ascii characters
nonascii()
{
LC_ALL=C grep -n '[^[:print:][:space:]]' "${@}"
}