feat!: refactor base, config, dfm and scripts

This commit is contained in:
2024-07-23 03:43:12 +03:00
parent adecceda7a
commit 1f2ca90ca5
36 changed files with 1543 additions and 897 deletions

View File

@@ -1,20 +1,28 @@
#!/usr/bin/env bash
# Create file containing key mappings for Neovim
# Usage: ./create-nvim-keymaps.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
#
# shellcheck source=shared.sh
source "${DOTFILES}/config/shared.sh"
DEST="$HOME/.dotfiles/docs/nvim-keybindings.md"
main()
{
printf "# nvim keybindings\n";
printf "\n";
printf "\`\`\`txt";
} > "$DEST"
msg "Generating Neovim keybindings documentation"
NVIM_APPNAME="nvim-kickstart" nvim -c "redir! >> $DEST" -c 'silent verbose map' -c 'redir END' -c 'q'
{
printf "# nvim keybindings\n\n"
printf "\`\`\`txt\n"
} > "$DEST"
printf "\n\`\`\`\n\n- Generated on %s\n" "$(date)" >> "$DEST"
NVIM_APPNAME="nvim-kickstart" nvim -c "redir! >> $DEST" -c 'silent verbose map' -c 'redir END' -c 'q'
# Remove lines with "Last set from" from the file
sed -e '/^ Last set from/d' "$DEST" > "$DEST.tmp" && mv "$DEST.tmp" "$DEST"
printf "\n\`\`\`\n\n- Generated on %s\n" "$(date)" >> "$DEST"
# Remove lines with "Last set from" from the file
sed -e '/^ Last set from/d' "$DEST" > "${DEST}.tmp" && mv "${DEST}.tmp" "$DEST"
msg "Neovim keybindings documentation generated at $DEST"
}
main "$@"

View File

@@ -1,11 +1,18 @@
#!/usr/bin/env bash
#
# Export oh-my-posh configuration as an image
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
set -e
source "${DOTFILES}/config/shared.sh"
cd "$DOTFILES" || exit
oh-my-posh config export image \
--config "$OHMYPOSH_CFG" \
--output "$HOME/.dotfiles/.github/screenshots/oh-my-posh.png" \
--author "Ismo Vuorinen"
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,9 +1,7 @@
#!/usr/bin/env bash
#
# Install asdf
source "${XDG_CONFIG_HOME}/shared.sh"
source "${DOTFILES}/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
export ASDF_DIR="${XDG_BIN_HOME}/asdf"
export PATH="${ASDF_DIR}/bin:$PATH"
@@ -11,16 +9,19 @@ export PATH="${ASDF_DIR}/bin:$PATH"
msg "Sourcing asdf in your shell"
. "$ASDF_DIR/asdf.sh"
# Update asdf, and plugins
asdf update
# Function to update asdf and plugins
update_asdf()
{
asdf update
asdf plugin add asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git
asdf install asdf-plugin-manager latest
asdf global asdf-plugin-manager "$(asdf latest asdf-plugin-manager)"
asdf-plugin-manager version
asdf-plugin-manager add-all
asdf plugin add asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git
asdf install asdf-plugin-manager latest
asdf global asdf-plugin-manager "$(asdf latest asdf-plugin-manager)"
asdf-plugin-manager version
asdf-plugin-manager add-all
asdf install
asdf install
}
ASDF_INSTALLABLES=(
"1password-cli:github.com/NeoHsu/asdf-1password-cli.git"
@@ -51,14 +52,25 @@ ASDF_INSTALLABLES=(
"yq:github.com/sudermanjr/asdf-yq.git"
)
msg "Installing asdf plugins, if not already installed"
for item in "${ASDF_INSTALLABLES[@]}"; do
CMD=$(echo "${item}" | awk -F ":" '{print $1}')
URL=$(echo "${item}" | awk -F ":" '{print $2}')
asdf plugin add "${CMD}" "https://${URL}"
asdf install "${CMD}" latest
asdf global "${CMD}" "$(asdf latest "${CMD}")"
done
# Function to install asdf plugins
install_asdf_plugins()
{
msg "Installing asdf plugins, if not already installed"
for item in "${ASDF_INSTALLABLES[@]}"; do
CMD=$(echo "${item}" | awk -F ":" '{print $1}')
URL=$(echo "${item}" | awk -F ":" '{print $2}')
asdf plugin add "${CMD}" "https://${URL}"
asdf install "${CMD}" latest
asdf global "${CMD}" "$(asdf latest "${CMD}")"
done
}
msg "Reshim asdf"
asdf reshim
main()
{
update_asdf
install_asdf_plugins
msg "Reshim asdf"
asdf reshim
}
main "$@"

View File

@@ -2,18 +2,18 @@
# Install cargo/rust packages.
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
eval "$HOME/.dotfiles/config/shared.sh"
msg "Starting to install rust/cargo packages"
source "$CARGO_HOME/env"
# If we have cargo install-update, use it first
x-have cargo-install-update && {
if command -v cargo-install-update &> /dev/null; then
msg_run "Updating cargo packages with cargo install-update"
cargo install-update -a
msg_done "Done with cargo install-update"
}
fi
packages=(
# A cargo subcommand for checking and applying
@@ -42,28 +42,41 @@ packages=(
# Number of jobs to run in parallel, this helps to keep the system responsive
BUILD_JOBS=$(nproc --ignore=2)
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
# Function to install cargo packages
install_packages()
{
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_run "Installing cargo package $pkg"
cargo install --jobs $BUILD_JOBS "$pkg"
echo ""
done
msg_done "Installed cargo packages!"
msg_run "Now doing the next steps for cargo packages"
# use bob to install latest stable nvim
x-have bob && {
bob use stable && x-path-append "$XDG_DATA_HOME/bob/nvim-bin"
msg_run "Installing cargo package $pkg"
cargo install --jobs $BUILD_JOBS "$pkg"
echo ""
done
}
msg_run "Removing cargo cache"
cargo cache --autoclean
msg_done "Done removing cargo cache"
# Function to perform additional steps for installed cargo packages
post_install_steps()
{
msg_run "Now doing the next steps for cargo packages"
# use bob to install latest stable nvim
if command -v bob &> /dev/null; then
bob use stable && x-path-append "$XDG_DATA_HOME/bob/nvim-bin"
fi
msg_run "Removing cargo cache"
cargo cache --autoclean
msg_done "Done removing cargo cache"
}
main()
{
install_packages
msg_done "Installed cargo packages!"
post_install_steps
}
main "$@"

View File

@@ -1,58 +1,83 @@
#!/usr/bin/env bash
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
PBB_REQUIRED_TOOLS=(git cheat)
for t in ${PBB_REQUIRED_TOOLS[@]}; do
! x-have "$t" && echo "(!) $t is missing, can't continue..." && exit 1
done
PBB_GIT="https://github.com/dylanaraps/pure-bash-bible.git"
PBB_SOURCE="source: $PBB_GIT"
PBB_SYNTAX="syntax: bash"
PBB_TAGS="tags: [bash]"
PBB_TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/cheat/pbb"
PBB_TEMP_PREFIX=$(basename "$0")
PBB_TEMP_DIR="$XDG_CACHE_HOME/cheat/pbb"
check_required_tools()
{
for t in "${PBB_REQUIRED_TOOLS[@]}"; do
if ! x-have "$t"; then
echo "(!) $t is missing, can't continue..."
exit 1
fi
done
}
# If there's no .git, clone the folder
if [ ! -d "$PBB_TEMP_DIR/.git" ]; then
msg_run "Starting to clone $PBB_GIT"
git clone --depth 1 --single-branch -q "$PBB_GIT" "$PBB_TEMP_DIR" \
&& msg_yay "Cloned $PBB_GIT"
else
# Update the repo
msg_run "Starting to update $PBB_GIT"
git -C "$PBB_TEMP_DIR" reset --hard origin/master
git -C "$PBB_TEMP_DIR" pull -q \
&& msg_yay "Updated $PBB_GIT"
fi
clone_or_update_repo()
{
if [ ! -d "$PBB_TEMP_DIR/.git" ]; then
msg_run "Starting to clone $PBB_GIT"
git clone --depth 1 --single-branch -q "$PBB_GIT" "$PBB_TEMP_DIR" \
&& msg_yay "Cloned $PBB_GIT"
else
msg_run "Starting to update $PBB_GIT"
git -C "$PBB_TEMP_DIR" reset --hard origin/master
git -C "$PBB_TEMP_DIR" pull -q \
&& msg_yay "Updated $PBB_GIT"
fi
}
PBB_CHAPTERS=$(ls -1v "$PBB_TEMP_DIR"/manuscript/chapter*)
CHEAT_DEST="$(cheat -d | grep pure-bash-bible | head -1 | awk '{print $2}')"
prepare_cheat_dest()
{
local cheat_dest
cheat_dest="$(cheat -d | grep pure-bash-bible | head -1 | awk '{print $2}')"
if [ ! -d "$CHEAT_DEST" ]; then
mkdir -p "$CHEAT_DEST"
fi
for f in ${PBB_CHAPTERS[@]}; do
# get all headers, take the first one, strip the # and return the first word in lowercase
HEADER=$(grep -e '^[#] ' "$f" | head -1 | awk '{print tolower($2)}')
CHEAT_FILE="$CHEAT_DEST/${HEADER}"
replacable "$f" "$CHEAT_FILE"
override=$?
if [ "$override" -ne 1 ]; then
cp "$f" "$CHEAT_FILE" && msg_run "Updated: $CHEAT_FILE"
if [ ! -d "$cheat_dest" ]; then
mkdir -p "$cheat_dest"
fi
LC_ALL=C perl -pi.bak -e 's/\<\!-- CHAPTER END --\>//' "$CHEAT_FILE"
rm "$CHEAT_FILE.bak"
echo "$cheat_dest"
}
# add tags if the file doesn't have them
if [ '---' != "$(head -1 < "$CHEAT_FILE")" ]; then
T="$PBB_SYNTAX\n$PBB_TAGS\n$PBB_SOURCE\n"
echo -e "---\n$T---\n$(cat "$CHEAT_FILE")" > "$CHEAT_FILE"
fi
done
process_chapters()
{
local cheat_dest
cheat_dest=$(prepare_cheat_dest)
mapfile -t PBB_CHAPTERS < <(ls -1v "$PBB_TEMP_DIR"/manuscript/chapter*)
for f in "${PBB_CHAPTERS[@]}"; do
local header cheat_file
header=$(grep -e '^[#] ' "$f" | head -1 | awk '{print tolower($2)}')
cheat_file="$cheat_dest/$header"
if ! replacable "$f" "$cheat_file"; then
cp "$f" "$cheat_file" && msg_run "Updated: $cheat_file"
fi
LC_ALL=C perl -pi.bak -e 's/\<\!-- CHAPTER END --\>//' "$cheat_file"
rm "$cheat_file.bak"
if [ '---' != "$(head -1 < "$cheat_file")" ]; then
local metadata
metadata="$PBB_SYNTAX\n$PBB_TAGS\n$PBB_SOURCE\n"
echo -e "---\n$metadata---\n$(cat "$cheat_file")" > "$cheat_file"
fi
done
}
main()
{
check_required_tools
clone_or_update_repo
process_chapters
}
main "$@"

View File

@@ -2,9 +2,12 @@
# Install PHP Package Manager Composer
#
# shellcheck source="shared.sh"
eval "$HOME/.dotfiles/scripts/shared.sh"
eval "$HOME/.dotfiles/config/shared.sh"
! x-have "php" && msg_err "PHP Not Available, cannot install composer" && exit 0
if ! command -v php &> /dev/null; then
msg_err "PHP Not Available, cannot install composer"
exit 0
fi
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

View File

@@ -2,7 +2,7 @@
# Install NerdFonts
#
# shellcheck source="shared.sh"
eval "$HOME/.dotfiles/scripts/shared.sh"
source "$DOTFILES/config/shared.sh"
GIT_REPO="https://github.com/ryanoasis/nerd-fonts.git"
TMP_PATH="$XDG_CACHE_HOME/nerd-fonts"
@@ -17,28 +17,50 @@ fonts=(
SpaceMono
)
if [ ! -d "$TMP_PATH" ]; then
git clone --filter=blob:none --sparse "$GIT_REPO" "$TMP_PATH"
fi
# 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"
fi
cd "$TMP_PATH" || {
msg_err "No such folder $TMP_PATH"
exit 1
cd "$TMP_PATH" || msg_err "No such folder $TMP_PATH"
}
for ext in "${fonts[@]}"; do
# Trim spaces
ext=${ext// /}
# Skip comments
if [[ ${ext:0:1} == "#" ]]; then continue; fi
# Function to add fonts to sparse-checkout
add_fonts_to_sparse_checkout()
{
for font in "${fonts[@]}"; do
# Trim spaces
font=${font// /}
# Skip comments
if [[ ${font:0:1} == "#" ]]; then continue; fi
msg_run "Adding $ext to sparse-checkout"
git sparse-checkout add "patched-fonts/$ext"
echo ""
done
msg_run "Adding $font to sparse-checkout"
git sparse-checkout add "patched-fonts/$font"
echo ""
done
}
msg "Starting to install NerdFonts..."
# Function to install NerdFonts
install_fonts()
{
msg "Starting to install NerdFonts..."
./install.sh -q -s ${fonts[*]}
msg_ok "Done"
}
./install.sh -s ${fonts[*]}
remove_tmp_path()
{
rm -rf "$TMP_PATH"
}
msg_ok "Done"
main()
{
clone_or_update_repo
add_fonts_to_sparse_checkout
install_fonts
remove_tmp_path
}
main "$@"

View File

@@ -3,17 +3,23 @@
# Install fzf
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/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"
if [ ! -d "$FZF_BUILD" ]; then
git clone --depth 1 "$FZF_GIT" "$FZF_BUILD"
"$FZF_BUILD/install" \
--xdg \
--bin
else
msg_done "fzf ($FZF_PATH/) already installed"
fi
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

@@ -2,13 +2,17 @@
# Install GitHub CLI extensions
#
# shellcheck source="shared.sh"
eval "$HOME/.dotfiles/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg_run "Installing gh (GitHub Client) extensions"
! x-have "gh" \
&& msg_err "gh (GitHub Client) could not be found, please install it first" \
&& exit 0
if ! command -v gh &> /dev/null; then
msg_err "gh (GitHub Client) could not be found, please install it first"
exit 0
fi
extensions=(
# GitHub CLI extension for generating a report on repository dependencies.
@@ -30,15 +34,25 @@ extensions=(
rsese/gh-actions-status
)
for ext in "${extensions[@]}"; do
# Trim spaces
ext=${ext// /}
# Skip comments
if [[ ${ext:0:1} == "#" ]]; then continue; fi
# Function to install GitHub CLI extensions
install_extensions()
{
for ext in "${extensions[@]}"; do
# Trim spaces
ext=${ext// /}
# Skip comments
if [[ ${ext:0:1} == "#" ]]; then continue; fi
msg_nested "Installing $ext"
gh extensions install "$ext"
echo ""
done
msg_nested "Installing $ext"
gh extension install "$ext"
echo ""
done
}
msg_ok "Done"
main()
{
install_extensions
msg_ok "Done"
}
main "$@"

View File

@@ -4,12 +4,14 @@
# NOTE: Experimental, wip
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg_run "Installing git-crypt"
x-have "git-crypt" || {
if ! command -v git-crypt &> /dev/null; then
REPO_URL="https://github.com/AGWA/git-crypt.git"
CHECK_PATH="${XDG_BIN_HOME}/git-crypt"
BUILD_PATH="/tmp/git-crypt"
@@ -23,5 +25,6 @@ x-have "git-crypt" || {
else
msg_done "git-crypt ($CHECK_PATH) already installed"
fi
}
fi
msg_done "Done installing git-crypt"

View File

@@ -2,7 +2,10 @@
# Install Go packages
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
eval "$DOTFILES/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg_run "Installing go packages"
@@ -33,32 +36,50 @@ packages=(
github.com/doron-cohen/antidot@latest
)
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
# Function to install go packages
install_packages()
{
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_nested "Installing go package: $pkg"
go install "$pkg"
echo ""
done
msg_run "Installing completions for selected packages"
x-have git-profile && {
git-profile completion zsh > "$ZSH_CUSTOM_COMPLETION_PATH/_git-profile" \
&& msg_ok "Installed completions for git-profile"
msg_nested "Installing go package: $pkg"
go install "$pkg"
echo ""
done
}
x-have antidot && {
antidot update \
&& msg_ok "Updated antidot database"
# Function to install completions and run actions for selected packages
post_install()
{
msg_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"
fi
if command -v antidot &> /dev/null; then
antidot update \
&& msg_ok "Updated antidot database"
fi
}
echo ""
# Function to clear go cache
clear_go_cache()
{
msg_run "Clearing go cache"
go clean -cache -modcache
}
msg_run "Clearing go cache"
go clean -cache -modcache
main()
{
install_packages
post_install
clear_go_cache
msg_ok "Done"
}
msg_ok "Done"
main "$@"

View File

@@ -3,23 +3,71 @@
# Install neofetch from source
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
source "$DOTFILES/config/shared.sh"
NEOFETCH_VERSION="7.1.0"
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"
x-have "neofetch" || {
# 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" > "$NEOFETCH_TEMP.tar.gz"
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,11 +2,17 @@
# Install npm packages globally.
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
eval "$DOTFILES/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg "Starting to install npm packages"
! x-have "npm" && msg_err "npm could not be found." && exit 0
if ! command -v npm &> /dev/null; then
msg_err "npm could not be found."
exit 0
fi
packages=(
# This is a tool to check if your files consider your .editorconfig rules.
@@ -18,27 +24,48 @@ packages=(
"corepack"
)
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
# Function to install npm packages
install_packages()
{
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
if [[ $(npm ls -g -p "$pkg") != "" ]]; then
msg_run_done "$pkg" "already installed"
else
msg_run "Installing npm package:" "$pkg"
npm install -g --no-fund --no-progress --no-timing "$pkg"
fi
if npm ls -g -p "$pkg" &> /dev/null; then
msg_run_done "$pkg" "already installed"
else
msg_run "Installing npm package:" "$pkg"
npm install -g --no-fund --no-progress --no-timing "$pkg"
fi
echo ""
done
}
echo ""
done
# Function to upgrade all global npm packages
upgrade_global_packages()
{
msg_run "Upgrading all global packages"
npm -g --no-progress --no-timing --no-fund outdated
npm -g --no-timing --no-fund upgrade
}
msg_run "Upgrading all global packages"
npm -g --no-progress --no-timing --no-fund outdated
npm -g --no-timing --no-fund upgrade
# Function to clean npm cache
clean_npm_cache()
{
msg_run "Cleaning up npm cache"
npm cache verify
npm cache clean --force
npm cache verify
}
msg_run "Cleaning up npm cache"
npm cache verify
npm cache clean --force
npm cache verify
main()
{
install_packages
upgrade_global_packages
clean_npm_cache
msg_yay "npm package installations complete"
}
main "$@"

View File

@@ -3,11 +3,18 @@
# Install ntfy
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
set -e
eval "$DOTFILES/config/shared.sh"
x-have "ntfy" && msg "ntfy already installed" && exit 0
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
# Check if ntfy is already installed
if x-have "ntfy"; then
msg "ntfy already installed"
exit 0
fi
# Determine the architecture
case $(dfm check arch) in
Linux)
NTFY_ARCH="linux_$(arch)"
@@ -15,21 +22,36 @@ case $(dfm check arch) in
Darwin)
NTFY_ARCH="macOS_all"
;;
*)
msg_err "Unsupported OS"
;;
esac
NTFY_VERSION=2.2.0
NTFY_VERSION="$(x-gh-get-latest-version binwiederhier/ntfy)"
NTFY_URL="https://github.com/binwiederhier/ntfy"
NTFY_DEST="/tmp/ntfy_${NTFY_VERSION}_${NTFY_ARCH}"
curl -L "$NTFY_URL/releases/download/v${NTFY_VERSION}/${NTFY_DEST}.tar.gz" \
> "${NTFY_DEST}.tar.gz"
tar zxvf "${NTFY_DEST}.tar.gz"
cp -a "${NTFY_DEST}/ntfy" ~/.local/bin/ntfy
mkdir -p ~/.config/ntfy
# Download and extract ntfy
install_ntfy()
{
curl -L "$NTFY_URL/releases/download/v${NTFY_VERSION}/${NTFY_DEST}.tar.gz" -o "${NTFY_DEST}.tar.gz"
tar zxvf "${NTFY_DEST}.tar.gz"
cp -a "${NTFY_DEST}/ntfy" ~/.local/bin/ntfy
mkdir -p ~/.config/ntfy
# copy config only if it does not exist
if [ ! -f "$HOME/.config/ntfy/client.yml" ]; then
cp "${NTFY_DEST}/client/client.yml" ~/.config/ntfy/client.yml
fi
# Copy config only if it does not exist
if [ ! -f "$HOME/.config/ntfy/client.yml" ]; then
cp "${NTFY_DEST}/client/client.yml" ~/.config/ntfy/client.yml
fi
rm -rf "${NTFY_DEST}" "${NTFY_DEST}.tar.gz"
# Clean up
rm -rf "${NTFY_DEST}" "${NTFY_DEST}.tar.gz"
}
main()
{
install_ntfy
msg "ntfy installation complete"
}
main "$@"

View File

@@ -3,14 +3,31 @@
# Install oh-my-bash
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
export OSH="$HOME/.local/share/oh-my-bash"
set -euo pipefail
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"
else
msg_done "oh-my-bash ($OSH) already installed"
fi
# 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

@@ -3,9 +3,31 @@
# Install oh-my-posh
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
curl -s https://ohmyposh.dev/install.sh | bash -s -- -d ~/.local/bin
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
eval "$(oh-my-posh init zsh --config $OHMYPOSH_CFG)"
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,13 +2,17 @@
# Install python/pip packages.
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
msg "Starting to install pip packages"
x-have "python3" || {
msg_err "Could not find python3, something really weird is going on." && exit 1
}
if ! command -v python3 &> /dev/null; then
msg_err "Could not find python3, something really weird is going on."
exit 1
fi
msg_nested "Upgrading pip"
python3 -m pip install --user --upgrade pip
@@ -18,16 +22,20 @@ packages=(
"libtmux"
)
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
# Function to install pip packages
install_packages()
{
for pkg in "${packages[@]}"; do
# Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_nested "Installing pip package: $pkg"
python3 -m pip install --user --upgrade "$pkg"
echo ""
done
msg_nested "Installing pip package: $pkg"
python3 -m pip install --user --upgrade "$pkg"
echo ""
done
}
install_packages
msg_yay "Run pip package installations"

View File

@@ -4,29 +4,40 @@
# Ismo Vuorinen <https://github.com/ivuorinen> 2018
#
[ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
! x-have xcode-select \
&& msg_err "xcode-select could not be found, skipping" \
&& exit 0
# Check if the script is running on macOS
if [ "$(uname)" != "Darwin" ]; then
echo "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"
exit 0
fi
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until `settler` has finished
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2> /dev/null &
# Keep-alive: update existing `sudo` time stamp until the script has finished
keep_alive_sudo()
{
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2> /dev/null &
}
XCODE_TOOLS_PATH=$(xcode-select -p)
XCODE_SWIFT_PATH="$XCODE_TOOLS_PATH/usr/bin/swift"
# Modified from https://unix.stackexchange.com/a/408305
if [ -a "$XCODE_SWIFT_PATH" ]; then
echo "You have swift from xcode-select. Continuing..."
else
# Function to prompt for XCode CLI Tools installation
prompt_xcode_install()
{
XCODE_MESSAGE="$(
osascript -e \
'tell app "System Events" to display dialog "Please click install when Command Line Developer Tools appears"'
@@ -36,11 +47,25 @@ else
xcode-select --install
else
echo "You have cancelled the installation, please rerun the installer."
exit
exit 1
fi
fi
}
until [ -f "$XCODE_SWIFT_PATH" ]; do
echo -n "."
sleep 1
done
# Main function
main()
{
keep_alive_sudo
if [ -x "$XCODE_SWIFT_PATH" ]; then
echo "You have swift from xcode-select. Continuing..."
else
prompt_xcode_install
fi
until [ -f "$XCODE_SWIFT_PATH" ]; do
echo -n "."
sleep 1
done
}
main "$@"

View File

@@ -3,13 +3,29 @@
# Install z
#
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
source "${DOTFILES}/config/shared.sh"
Z_GIT_PATH="https://github.com/rupa/z.git"
Z_BIN_PATH="$XDG_BIN_HOME/z"
if [ ! -d "$Z_BIN_PATH" ]; then
git clone "$Z_GIT_PATH" "$Z_BIN_PATH"
else
msg_done "z ($Z_BIN_PATH/) already installed"
fi
# Function to clone the z repository
clone_z_repo()
{
local git_path=$1
local bin_path=$2
if [ ! -d "$bin_path" ]; then
git clone "$git_path" "$bin_path"
msg "z installed at $bin_path"
else
msg "z ($bin_path/) already installed"
fi
}
# Main function
main()
{
clone_z_repo "$Z_GIT_PATH" "$Z_BIN_PATH"
}
main "$@"

View File

@@ -9,7 +9,7 @@
[ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0
# shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh"
eval "$HOME/.dotfiles/config/shared.sh"
msg_run "Starting to set macOS defaults, these require sudo privileges:"
@@ -63,7 +63,7 @@ defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Disable the Are you sure you want to open this application? dialog
# Disable the "Are you sure you want to open this application?" dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false
# Disable Resume system-wide
@@ -79,10 +79,10 @@ defaults write NSGlobalDomain NSDisableAutomaticTermination -bool true
# in the login window
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
# Disable smart quotes as theyre annoying when typing code
# Disable smart quotes as they're annoying when typing code
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Disable smart dashes as theyre annoying when typing code
# Disable smart dashes as they're annoying when typing code
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
###############################################################################
@@ -94,7 +94,7 @@ msg_nested "Setting SSD-specific tweaks"
# Disable hibernation (speeds up entering sleep mode)
sudo pmset -a hibernatemode 0
# Disable the sudden motion sensor as its not useful for SSDs
# Disable the sudden motion sensor as it's not useful for SSDs
sudo pmset -a sms 0
###############################################################################
@@ -117,7 +117,7 @@ defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Min" 80
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Set language and text formats
# Note: if youre in the US, replace `EUR` with `USD`, `Centimeters` with
# Note: if you're in the US, replace `EUR` with `USD`, `Centimeters` with
# `Inches`, `en_GB` with `en_US`, and `true` with `false`.
defaults write NSGlobalDomain AppleLanguages -array "en"
defaults write NSGlobalDomain AppleLocale -string "en_GB@currency=EUR"
@@ -197,7 +197,7 @@ defaults write com.apple.finder WarnOnEmptyTrash -bool false
# chflags nohidden /Users
# Expand the following File Info panes:
# General, Open with, and Sharing & Permissions
# "General", "Open with", and "Sharing & Permissions"
defaults write com.apple.finder FXInfoPanesExpanded -dict \
General -bool true \
OpenWith -bool true \
@@ -235,17 +235,17 @@ defaults write com.apple.dock tilesize -int 30
defaults write com.apple.dock show-process-indicators -bool true
# Wipe all (default) app icons from the Dock
# This is only really useful when setting up a new Mac, or if you dont use
# This is only really useful when setting up a new Mac, or if you don't use
# the Dock to launch apps.
# defaults write com.apple.dock persistent-apps -array ""
# Disable Dashboard
defaults write com.apple.dashboard mcx-disabled -bool true
# Dont show Dashboard as a Space
# Don't show Dashboard as a Space
defaults write com.apple.dock dashboard-in-overlay -bool true
# Dont automatically rearrange Spaces based on most recent use
# Don't automatically rearrange Spaces based on most recent use
defaults write com.apple.dock mru-spaces -bool false
# Make Dock icons of hidden applications translucent
@@ -257,7 +257,7 @@ defaults write com.apple.dock showhidden -bool true
msg_nested "Settings for Safari & WebKit"
# Enable Safaris debug menu
# Enable Safari's debug menu
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
# Enable the Develop menu and the Web Inspector in Safari
@@ -268,7 +268,7 @@ defaults write com.apple.Safari \
com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled \
-bool true
# Dont display the annoying prompt when quitting iTerm
# Don't display the annoying prompt when quitting iTerm
defaults write com.googlecode.iterm2 PromptOnQuit -bool false
# Use iTerm2 preferences from the .dotfiles folder.
defaults write com.googlecode.iterm2 PrefsCustomFolder \
@@ -315,7 +315,7 @@ defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
msg_nested "Settings for Messages"
# Disable smart quotes as its annoying for messages that contain code
# Disable smart quotes as it's annoying for messages that contain code
defaults write com.apple.messageshelper.MessageController \
SOInputLineSettings \
-dict-add "automaticQuoteSubstitutionEnabled" \
@@ -335,7 +335,7 @@ msg_nested "Restarting applications to apply changes"
for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
"Dock" "Finder" "Mail" "Messages" "Safari" "SizeUp" "SystemUIServer" \
"Terminal" "Transmission" "Twitter" "iCal"; do
"Terminal" "Transmission" "iCal"; do
killall "${app}" > /dev/null 2>&1
done

View File

@@ -6,164 +6,14 @@
# Helper env variables. Use like this: VERBOSE=1 ./script.sh
: "${VERBOSE:=0}"
# Modified from https://stackoverflow.com/a/28776166
(
[[ -n $ZSH_VERSION && $ZSH_EVAL_CONTEXT =~ :file$ ]] \
|| [[ -n $BASH_VERSION ]] && (return 0 2> /dev/null)
) && sourced=1 || sourced=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
[ -z "$SHARED_SCRIPTS_SOURCED" ] && {
eval "$HOME/.dotfiles/config/shared.sh"
source "${DOTFILES}/config/shared.sh"
msgr done "(!) shared.sh not sourced"
DOTFILES_CURRENT_SHELL=$(ps -p $$ -oargs=)
export DOTFILES_CURRENT_SHELL
# Other variables
export OHMYPOSH_CFG="$HOME/.dotfiles/config/omp/own.toml"
# Remove directory from the PATH variable
# usage: path_remove ~/.local/bin
function path_remove
{
x-path-remove "$1"
}
# Append directory to the PATH
# usage: path_append ~/.local/bin
function path_append
{
x-path-remove "$1"
x-path-prepend "$1"
}
# Prepend directory to the PATH
# usage: path_prepend ~/.local/bin
function path_prepend
{
x-path-remove "$1"
x-path-prepend "$1"
}
# Run command silently
# Usage: silent uptime
silent()
{
"$@" >&/dev/null
}
# Check if a file contains non-ascii characters
nonascii()
{
LC_ALL=C grep -n '[^[:print:][:space:]]' "${@}"
}
source "$DOTFILES/local/bin/msgr"
# -- Menu builder -- #
function menu_section()
{
LINE=$(printf '%-18s [ %-15s ]\n' "$1" "$2")
echo -e " $(__log_marker) $LINE"
}
function menu_item()
{
LINE=$(printf '%-15s %-30s\n' "$1" "$2")
echo -e "$(__log_indent)$(__log_marker) $LINE"
}
# https://stackoverflow.com/a/85932
function fn_exists()
{
declare -f -F "$1" > /dev/null
return $?
}
# Takes a bash array ("cow:moo", "dinosaur:roar") and loops
# through the keys to build menu section listing.
function menu_usage_header()
{
MENU_CMD="$1"
shift
MENU_ARRAY=("$@")
KEYS=""
for item in "${MENU_ARRAY[@]}"; do
CMD=$(echo "${item}" | awk -F ":" '{print $1}')
KEYS+="${CMD} | "
done
# "???" removes 3 last characters, being " | " from the end
menu_section "$MENU_CMD" "${KEYS%???}"
}
# Takes the usage command "$0 dotfiles" and a
# bash array ("cow:moo" "dinosaur:roar") and loops
# through in building a menu for dfm command usage listing.
function menu_usage()
{
MENU_CMD="$1"
shift
MENU_ARRAY=("$@")
msg "$MENU_CMD"
for item in "${MENU_ARRAY[@]}"; do
CMD=$(echo "${item}" | awk -F ":" '{print $1}')
DESC=$(echo "${item}" | awk -F ":" '{print $2}')
menu_item "$CMD" "$DESC"
done
}
# Creates a random string
rnd()
{
echo $RANDOM | md5sum | head -c 20
}
# return sha256sum for file
# $1 - filename (string)
function get_sha256sum()
{
sha256sum "$1" | head -c 64
}
# Replaceable file
#
# $1 - filename (string)
# $2 - filename (string)
#
# Returns 1 when replaceable, 0 when not replaceable.
function replacable()
{
FILE1="$1"
FILE2="$2"
[[ ! -r "$FILE1" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "File 1 ($FILE1) does not exist"
return 0
}
[[ ! -r "$FILE2" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "File 2 ($FILE2) does not exist, replaceable"
return 1
}
FILE1_HASH=$(get_sha256sum "$FILE1")
FILE2_HASH=$(get_sha256sum "$FILE2")
[[ $FILE1_HASH = "" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "Could not get hash for file 1 ($FILE1)"
return 0
}
[[ $FILE2_HASH = "" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_err "Could not get hash for file 2 ($FILE2), replaceable"
return 1
}
[[ "$FILE1_HASH" == "$FILE2_HASH" ]] && {
[[ $VERBOSE -eq 1 ]] && msg_ok "Files match, not replaceable: $FILE1"
return 0
}
[[ $VERBOSE -eq 1 ]] && msg_warn "Files do not match ($FILE1_HASH != $FILE2_HASH), replaceable"
return 1
# Set variable that checks if the shared.sh script has been sourced only once
# shellcheck disable=SC2034
export SHARED_SCRIPTS_SOURCED=1
}