chore: shfmt, cleanup

This commit is contained in:
2024-12-28 18:59:09 +02:00
parent eb91a43bbd
commit a8a473a46d
26 changed files with 299 additions and 516 deletions

View File

@@ -1,18 +0,0 @@
#!/usr/bin/env bash
#
# Export oh-my-posh configuration as an image
#
# shellcheck source=shared.sh
source "${DOTFILES}/config/shared.sh"
main()
{
cd "$DOTFILES" || msg_err "Failed to change directory to $DOTFILES"
oh-my-posh config export image \
--config "$OHMYPOSH_CFG" \
--output "$HOME/.dotfiles/.github/screenshots/oh-my-posh.png" \
--author "Ismo Vuorinen"
}
main "$@"

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env bash
#
# Install asdf and plugins I use
#
# It also updates asdf and the plugins, and then reshim asdf.
#
# Usage: ./install-asdf.sh [both|install|update|add_plugins]
# Author: Ismo Vuorinen <https://github.com/ivuorinen>
# License: MIT
msgr warn "The asdf plugins should be installed with dotbot, and 'dfm asdf'."
exit 0

View File

@@ -3,9 +3,6 @@
#
# shellcheck source=shared.sh
echo "This file ($0) has been deprecated in favor of asdf. Please use asdf instead."
exit 0
eval "$HOME/.dotfiles/config/shared.sh"
msg "Starting to install rust/cargo packages"

View File

@@ -2,7 +2,7 @@
# Install PHP Package Manager Composer
#
# shellcheck source="shared.sh"
eval "$HOME/.dotfiles/config/shared.sh"
source "$HOME/.dotfiles/config/shared.sh"
if ! command -v php &> /dev/null; then
msg_err "PHP Not Available, cannot install composer"

View File

@@ -7,24 +7,21 @@ source "$DOTFILES/config/shared.sh"
GIT_REPO="https://github.com/ryanoasis/nerd-fonts.git"
TMP_PATH="$XDG_CACHE_HOME/nerd-fonts"
msg "-- NerdFonts --"
msgr run "Starting to install NerdFonts"
fonts=(
Hack
IntelOneMono
JetBrainsMono
OpenDyslexic
SpaceMono
)
# Function to clone or update the NerdFonts repository
clone_or_update_repo()
{
if [ ! -d "$TMP_PATH" ]; then
git clone --quiet --filter=blob:none --sparse "$GIT_REPO" "$TMP_PATH"
git clone --quiet --filter=blob:none --sparse --depth=1 "$GIT_REPO" "$TMP_PATH"
fi
cd "$TMP_PATH" || msg_err "No such folder $TMP_PATH"
cd "$TMP_PATH" || msgr err "No such folder $TMP_PATH"
}
# Function to add fonts to sparse-checkout
@@ -36,7 +33,7 @@ add_fonts_to_sparse_checkout()
# Skip comments
if [[ ${font:0:1} == "#" ]]; then continue; fi
msg_run "Adding $font to sparse-checkout"
msgr run "Adding $font to sparse-checkout"
git sparse-checkout add "patched-fonts/$font"
echo ""
done
@@ -45,9 +42,9 @@ add_fonts_to_sparse_checkout()
# Function to install NerdFonts
install_fonts()
{
msg "Starting to install NerdFonts..."
msgr run "Starting to install NerdFonts..."
./install.sh -q -s ${fonts[*]}
msg_ok "Done"
msgr run_done "Done"
}
remove_tmp_path()

View File

@@ -1,29 +0,0 @@
#!/usr/bin/env bash
#
# Install fzf
#
echo "This file ($0) has been deprecated in favor of asdf. Please use asdf instead."
exit 0
# shellcheck source=shared.sh
eval "$DOTFILES/config/shared.sh"
FZF_GIT="https://github.com/junegunn/fzf.git"
FZF_PATH="${XDG_CONFIG_HOME}/fzf"
FZF_BUILD="/tmp/fzf"
main()
{
if [ ! -d "$FZF_BUILD" ]; then
git clone --depth 1 "$FZF_GIT" "$FZF_BUILD"
"$FZF_BUILD/install" \
--xdg \
--bin
msg_done "fzf installed"
else
msg_done "fzf ($FZF_PATH/) already installed"
fi
}
main "$@"

View File

@@ -7,10 +7,10 @@ source "${DOTFILES}/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg_run "Installing gh (GitHub Client) extensions"
msgr run "Installing gh (GitHub Client) extensions"
if ! command -v gh &> /dev/null; then
msg_err "gh (GitHub Client) could not be found, please install it first"
msgr err "gh (GitHub Client) could not be found, please install it first"
exit 0
fi
@@ -43,7 +43,7 @@ install_extensions()
# Skip comments
if [[ ${ext:0:1} == "#" ]]; then continue; fi
msg_nested "Installing $ext"
msgr nested "Installing $ext"
gh extension install "$ext"
echo ""
done
@@ -52,7 +52,7 @@ install_extensions()
main()
{
install_extensions
msg_ok "Done"
msgr run_done "Done"
}
main "$@"

View File

@@ -9,7 +9,7 @@ source "${DOTFILES}/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg_run "Installing git-crypt"
msgr run "Installing git-crypt"
if ! command -v git-crypt &> /dev/null; then
REPO_URL="https://github.com/AGWA/git-crypt.git"
@@ -23,8 +23,8 @@ if ! command -v git-crypt &> /dev/null; then
cd "$BUILD_PATH" || msg_err "$BUILD_PATH not found"
make && make install PREFIX="$HOME/.local"
else
msg_done "git-crypt ($CHECK_PATH) already installed"
msgr run_done "git-crypt ($CHECK_PATH) already installed"
fi
fi
msg_done "Done installing git-crypt"
msgr run_done "Done installing git-crypt"

View File

@@ -2,18 +2,14 @@
# Install Go packages
#
# shellcheck source=shared.sh
echo "This file ($0) has been deprecated in favor of asdf. Please use asdf instead."
exit 0
eval "$DOTFILES/config/shared.sh"
source "$DOTFILES/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg_run "Installing go packages"
msgr run "Installing go packages"
! x-have "go" && msg "go hasn't been installed yet." && exit 0
! x-have "go" && msgr err "go hasn't been installed yet." && exit 0
packages=(
# A shell parser, formatter, and interpreter with bash support; includes shfmt
@@ -49,7 +45,7 @@ install_packages()
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_nested "Installing go package: $pkg"
msgr nested "Installing go package: $pkg"
go install "$pkg"
echo ""
done
@@ -58,23 +54,23 @@ install_packages()
# Function to install completions and run actions for selected packages
post_install()
{
msg_run "Installing completions for selected packages"
msgr run "Installing completions for selected packages"
if command -v git-profile &> /dev/null; then
git-profile completion zsh > "$ZSH_CUSTOM_COMPLETION_PATH/_git-profile" \
&& msg_ok "Installed completions for git-profile"
&& msgr run_done "Installed completions for git-profile"
fi
if command -v antidot &> /dev/null; then
antidot update \
&& msg_ok "Updated antidot database"
&& msgr run_done "Updated antidot database"
fi
}
# Function to clear go cache
clear_go_cache()
{
msg_run "Clearing go cache"
msgr run "Clearing go cache"
go clean -cache -modcache
}
@@ -83,7 +79,7 @@ main()
install_packages
post_install
clear_go_cache
msg_ok "Done"
msgr run_done "Done"
}
main "$@"

View File

@@ -1,73 +0,0 @@
#!/usr/bin/env bash
#
# Install neofetch from source
#
# shellcheck source=shared.sh
source "$DOTFILES/config/shared.sh"
if ! declare -f msg > /dev/null; then
# Function to print messages if VERBOSE is enabled
# $1 - message (string)
msg()
{
[ "$VERBOSE" -eq 1 ] && echo "$1"
return 0
}
fi
if ! declare -f msg_err > /dev/null; then
# Function to print error messages and exit
# $1 - error message (string)
msg_err()
{
echo "(!) ERROR: $1" >&2
exit 1
}
fi
if ! declare -f msg_done > /dev/null; then
# Function to print done message
# $1 - message (string)
msg_done()
{
echo "$1"
return 0
}
fi
NEOFETCH_VERSION="$(x-gh-get-latest-version dylanaraps/neofetch)"
NEOFETCH_REPO="https://github.com/dylanaraps/neofetch"
NEOFETCH_URL="${NEOFETCH_REPO}/archive/refs/tags/${NEOFETCH_VERSION}.tar.gz"
NEOFETCH_TEMP="/tmp/neofetch"
NEOFETCH_INSTALL_PREFIX="$HOME/.local"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
# Function to install neofetch from source
install_neofetch()
{
LC_ALL=C
mkdir -p "$NEOFETCH_TEMP" "$NEOFETCH_INSTALL_PREFIX"
curl -L "$NEOFETCH_URL" -o "$NEOFETCH_TEMP.tar.gz"
tar zxvf "$NEOFETCH_TEMP.tar.gz" --directory="$NEOFETCH_TEMP"
cd "$NEOFETCH_TEMP/neofetch-$NEOFETCH_VERSION" \
&& make PREFIX="${NEOFETCH_INSTALL_PREFIX}" install \
&& rm -rf "$NEOFETCH_TEMP*" \
&& msg_yay "neofetch installed!"
}
main()
{
if ! command -v neofetch &> /dev/null; then
install_neofetch
elif [ "$NEOFETCH_VERSION" != "$(neofetch --version | awk '{print $2}')" ]; then
install_neofetch
else
msg_done "neofetch v.${NEOFETCH_VERSION} already installed"
fi
}
main "$@"

View File

@@ -2,8 +2,7 @@
# Install npm packages globally.
#
# shellcheck source=shared.sh
eval "$DOTFILES/config/shared.sh"
source "$DOTFILES/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"

View File

@@ -3,14 +3,14 @@
# Install ntfy
#
# shellcheck source=shared.sh
eval "$DOTFILES/config/shared.sh"
source "$DOTFILES/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
# Check if ntfy is already installed
if x-have "ntfy"; then
msg "ntfy already installed"
msgr done "ntfy already installed"
exit 0
fi
@@ -23,7 +23,7 @@ case $(dfm check arch) in
NTFY_ARCH="macOS_all"
;;
*)
msg_err "Unsupported OS"
msgr err "Unsupported OS"
;;
esac
@@ -51,7 +51,7 @@ install_ntfy()
main()
{
install_ntfy
msg "ntfy installation complete"
msgr done "ntfy installation complete"
}
main "$@"

View File

@@ -1,33 +0,0 @@
#!/usr/bin/env bash
#
# Install oh-my-bash
#
# shellcheck source=shared.sh
source "${DOTFILES}/config/shared.sh"
set -euo pipefail
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
OSH="$HOME/.local/share/oh-my-bash"
# Function to install oh-my-bash
install_oh_my_bash()
{
if [ ! -d "$OSH" ]; then
[ -f "$HOME/.bashrc" ] && mv "$HOME/.bashrc" "$HOME/.bashrc.temp"
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)" --unattended
[ -f "$HOME/.bashrc.temp" ] && mv "$HOME/.bashrc.temp" "$HOME/.bashrc"
msg "oh-my-bash installed to $OSH"
else
msg_done "oh-my-bash ($OSH) already installed"
fi
}
main()
{
install_oh_my_bash
}
main "$@"

View File

@@ -1,33 +0,0 @@
#!/usr/bin/env zsh
#
# Install oh-my-posh
#
# shellcheck source=shared.sh
source "${DOTFILES}/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg "Starting to install oh-my-posh"
# Install oh-my-posh
install_oh_my_posh()
{
curl -s https://ohmyposh.dev/install.sh | bash -s -- -d ~/.local/bin
msg "oh-my-posh installed to ~/.local/bin"
}
# Initialize oh-my-posh
init_oh_my_posh()
{
eval "$(oh-my-posh init zsh --config $OHMYPOSH_CFG)"
msg "oh-my-posh initialized with config $OHMYPOSH_CFG"
}
main()
{
install_oh_my_posh
init_oh_my_posh
}
main "$@"

View File

@@ -2,20 +2,19 @@
# Install python/pip packages.
#
# shellcheck source=shared.sh
source "${DOTFILES}/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg "Starting to install pip packages"
msgr run "Starting to install pip packages"
if ! command -v python3 &> /dev/null; then
msg_err "Could not find python3, something really weird is going on."
msgr err "Could not find python3, something really weird is going on."
exit 1
fi
msg_nested "Upgrading pip"
msgr nested "Upgrading pip"
python3 -m pip install --user --upgrade pip
packages=(
@@ -32,11 +31,11 @@ install_packages()
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_nested "Installing pip package: $pkg"
msgr nested "Installing pip package: $pkg"
python3 -m pip install --user --upgrade "$pkg"
echo ""
done
}
install_packages
msg_yay "Run pip package installations"
msgr run_done "Run pip package installations"

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#
# Install XCode CLI Tools with osascript magic.
# Ismo Vuorinen <https://github.com/ivuorinen> 2018
#
@@ -9,13 +8,13 @@ VERBOSE="${VERBOSE:-0}"
# Check if the script is running on macOS
if [ "$(uname)" != "Darwin" ]; then
echo "Not a macOS system"
msgr warn "Not a macOS system"
exit 0
fi
# Check if xcode-select is available
if ! command -v xcode-select &> /dev/null; then
msg_err "xcode-select could not be found, skipping"
msgr err "xcode-select could not be found, skipping"
exit 0
fi
@@ -46,7 +45,7 @@ prompt_xcode_install()
if [ "$XCODE_MESSAGE" = "button returned:OK" ]; then
xcode-select --install
else
echo "You have cancelled the installation, please rerun the installer."
msgr warn "You have cancelled the installation, please rerun the installer."
exit 1
fi
}
@@ -57,7 +56,7 @@ main()
keep_alive_sudo
if [ -x "$XCODE_SWIFT_PATH" ]; then
echo "You have swift from xcode-select. Continuing..."
msgr run "You have swift from xcode-select. Continuing..."
else
prompt_xcode_install
fi

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#
# Install z
#
# shellcheck source=shared.sh
@@ -16,9 +15,9 @@ clone_z_repo()
if [ ! -d "$bin_path" ]; then
git clone "$git_path" "$bin_path"
msg "z installed at $bin_path"
msgr run_done "z installed at $bin_path"
else
msg "z ($bin_path/) already installed"
msgr ok "z ($bin_path/) already installed"
fi
}

View File

@@ -1,17 +1,15 @@
#!/usr/bin/env bash
#
# set-macos-defaults.sh - Sets macOS Defaults that I like
# Sets macOS Defaults that I like
#
# This script contains large portions from following scripts:
# - https://github.com/freekmurze/dotfiles/blob/main/macos/set-defaults.sh
#
[ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/config/shared.sh"
source "$HOME/.dotfiles/config/shared.sh"
msg_run "Starting to set macOS defaults, these require sudo privileges:"
msgr run "Starting to set macOS defaults, these require sudo privileges:"
# Ask for the administrator password upfront
sudo -v
@@ -24,7 +22,7 @@ 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"
msgr 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
@@ -35,7 +33,7 @@ fi
# General UI/UX #
###############################################################################
msg_nested "Setting General UI/UX settings"
msgr nested "Setting General UI/UX settings"
# Disable the sound effects on boot
sudo nvram SystemAudioVolume=" "
@@ -89,7 +87,7 @@ defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# SSD-specific tweaks #
###############################################################################
msg_nested "Setting SSD-specific tweaks"
msgr nested "Setting SSD-specific tweaks"
# Disable hibernation (speeds up entering sleep mode)
sudo pmset -a hibernatemode 0
@@ -101,7 +99,7 @@ sudo pmset -a sms 0
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
msg_nested "Settings for Trackpad, mouse, keyboard, Bluetooth accessories, and input"
msgr 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
@@ -137,7 +135,7 @@ launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2> /dev/nul
# Screen #
###############################################################################
msg_nested "Settings for Screen"
msgr nested "Settings for Screen"
# Require password immediately after sleep or screen saver begins
defaults write com.apple.screensaver askForPassword -int 1
@@ -147,7 +145,7 @@ defaults write com.apple.screensaver askForPasswordDelay -int 0
# Finder #
###############################################################################
msg_nested "Settings for Finder"
msgr nested "Settings for Finder"
# Set Desktop as the default location for new Finder windows
# For other paths, use `PfLo` and `file:///full/path/here/`
@@ -207,7 +205,7 @@ defaults write com.apple.finder FXInfoPanesExpanded -dict \
# Screenshots #
###############################################################################
msg_nested "Settings for Screenshots"
msgr nested "Settings for Screenshots"
# Set default screenshot location
mkdir -p "$HOME/Documents/Screenshots"
@@ -223,7 +221,7 @@ defaults write com.apple.screencapture "name" -string "screenshot"
# Dock, Dashboard, and hot corners #
###############################################################################
msg_nested "Settings for Dock, Dashboard, and hot corners"
msgr nested "Settings for Dock, Dashboard, and hot corners"
# Prevent applications from bouncing in Dock
defaults write com.apple.dock no-bouncing -bool true
@@ -255,7 +253,7 @@ defaults write com.apple.dock showhidden -bool true
# Safari & WebKit #
###############################################################################
msg_nested "Settings for Safari & WebKit"
msgr nested "Settings for Safari & WebKit"
# Enable Safari's debug menu
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
@@ -281,7 +279,7 @@ defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
# Activity Monitor #
###############################################################################
msg_nested "Settings for ActivityMonitor"
msgr nested "Settings for ActivityMonitor"
# Show the main window when launching Activity Monitor
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
@@ -300,7 +298,7 @@ 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"
msgr 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
@@ -313,7 +311,7 @@ defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
# Messages #
###############################################################################
msg_nested "Settings for Messages"
msgr nested "Settings for Messages"
# Disable smart quotes as it's annoying for messages that contain code
defaults write com.apple.messageshelper.MessageController \
@@ -327,7 +325,7 @@ defaults write com.apple.messageshelper.MessageController \
-dict-add "continuousSpellCheckingEnabled" \
-bool false
msg_nested "Restarting applications to apply changes"
msgr nested "Restarting applications to apply changes"
###############################################################################
# Kill affected applications #

View File

@@ -1,19 +1,19 @@
#!/usr/bin/env bash
#
# Shared bash functions and helpers
# that can be sourced to other scripts.
# Shared bash functions and helpers.
# Helper env variables. Use like this: VERBOSE=1 ./script.sh
: "${VERBOSE:=0}"
# Set variable that checks if the shared.sh script has been sourced only once
# If the script has been sourced more than once, the script not be sourced again
# Set variable that checks if the shared.sh script has been
# sourced only once If the script has been sourced more than once,
# the script not be sourced again.
[ -z "$SHARED_SCRIPTS_SOURCED" ] && {
source "${DOTFILES}/config/shared.sh"
msgr warn "(!) shared.sh not sourced"
# Set variable that checks if the shared.sh script has been sourced only once
# Set variable that checks if the shared.sh script has been
# sourced only once.
# shellcheck disable=SC2034
export SHARED_SCRIPTS_SOURCED=1
}