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,9 +1,11 @@
# this is my bashrc config. there are many like it, but this one is mine. # this is my bashrc config. there are many like it, but this one is mine.
# shellcheck shell=bash # shellcheck shell=bash
source "$HOME/.dotfiles/config/shared.sh" export DOTFILES="$HOME/.dotfiles"
export PATH="$HOME/.local/bin:$DOTFILES/local/bin:$PATH"
export SHARED_SCRIPTS_SOURCED=0
x-load-configs source "$DOTFILES/config/shared.sh"
# shellcheck source=../config/fzf/fzf.bash # shellcheck source=../config/fzf/fzf.bash
[ -f "${DOTFILES}/config/fzf/fzf.bash" ] && [ -f "${DOTFILES}/config/fzf/fzf.bash" ] &&

View File

@@ -1,19 +1,8 @@
# shellcheck shell=bash # shellcheck shell=bash
# vim: filetype=zsh # vim: filetype=zsh
export PATH="$HOME/.local/bin:$HOME/.dotfiles/local/bin:$HOME/.local/go/bin:$PATH"
export DOTFILES="$HOME/.dotfiles" export DOTFILES="$HOME/.dotfiles"
export PATH="$HOME/.local/bin:$DOTFILES/local/bin:$PATH"
export SHARED_SCRIPTS_SOURCED=0
# Explicitly set XDG folders source "$DOTFILES/config/shared.sh"
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"
# custom variables
export XDG_BIN_HOME="$HOME/.local/bin"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_RUNTIME_DIR="$HOME/.local/run"
eval "$DOTFILES/config/shared.sh"

View File

@@ -1,87 +1,122 @@
# this is my zsh config. there are many like it, but this one is mine. # this is my zsh config. there are many like it, but this one is mine.
# shellcheck shell=bash # shellcheck shell=bash
eval "$HOME/.dotfiles/config/shared.sh" # export VERBOSE=1
# export DEBUG=1
x-path-prepend "/usr/local/bin"
x-path-prepend "/opt/homebrew/bin"
x-path-prepend "$HOME/.local/share/cargo/bin"
x-path-prepend "$HOME/.local/share/bob/nvim-bin"
x-path-prepend "$HOME/.local/bin"
x-path-prepend "$DOTFILES/local/bin"
x-load-configs x-load-configs
export PATH="$XDG_BIN_HOME:$DOTFILES/local/bin:$HOME/.local/go/bin:$XDG_DATA_HOME/bob/nvim-bin:$XDG_DATA_HOME/cargo/bin:/opt/homebrew/bin:/usr/local/bin:$PATH" eval "$(oh-my-posh init zsh --config "$DOTFILES/config/omp/own.toml")"
x-have oh-my-posh && { # Load asdf
eval "$(oh-my-posh init zsh --config "$DOTFILES/config/omp/own.toml")" export ASDF_DIR="$XDG_BIN_HOME/asdf"
} if [[ -d $ASDF_DIR ]]; then
[[ -d $ASDF_DIR/bin ]] && x-path-prepend "$ASDF_DIR/bin"
export COMPLETION_WAITING_DOTS=true [[ -d $ASDF_DIR/shims ]] && x-path-prepend "$ASDF_DIR/shims"
[[ -d $ASDF_DIR/completions ]] && fpath=("$ASDF_DIR/completions" $fpath)
if type brew &> /dev/null; then [[ -d $ASDF_DIR/plugins ]] && fpath=("$ASDF_DIR/plugins" $fpath)
eval "$(brew shellenv)" source "$ASDF_DIR/asdf.sh"
FPATH="$HOMEBREW_PREFIX/share/zsh/site-functions:${FPATH}"
fi fi
export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion" # Function to load antigen if available
x-dc "$ZSH_CUSTOM_COMPLETION_PATH" load_antigen()
{
local antigen_zsh_path="$XDG_BIN_HOME/antigen.zsh"
# shellcheck source=../../.local/bin/antigen.zsh
if [[ -f "$antigen_zsh_path" ]]; then
source "$antigen_zsh_path"
# Add completion scripts to zsh path antigen use oh-my-zsh
FPATH="$ZSH_CUSTOM_COMPLETION_PATH:$FPATH"
# Try to load antigen, if present export ZSH_TMUX_AUTOSTART=true
ANTIGEN_ZSH_PATH="$XDG_BIN_HOME/antigen.zsh" export ZSH_TMUX_CONFIG="$DOTFILES/config/tmux/tmux.conf"
# shellcheck source=../../.local/bin/antigen.zsh export ZSH_TMUX_UNICODE=true
[[ -f "$ANTIGEN_ZSH_PATH" ]] && source "$ANTIGEN_ZSH_PATH" export ZSH_TMUX_AUTOQUIT=false
export ZSH_TMUX_DEFAULT_SESSION_NAME=main
# antigen is present # z, the zsh version
antigen use oh-my-zsh export ZSHZ_DATA="$XDG_STATE_HOME/z"
antigen bundle z
export ZSH_TMUX_AUTOSTART=true # these should be always available
export ZSH_TMUX_CONFIG="$DOTFILES/config/tmux/tmux.conf" antigen bundle brew
export ZSH_TMUX_UNICODE=true antigen bundle tmux
export ZSH_TMUX_AUTOQUIT=false antigen bundle colored-man-pages
export ZSH_TMUX_DEFAULT_SESSION_NAME=main antigen bundle ssh-agent
antigen bundle jreese/zsh-titles
antigen bundle zsh-users/zsh-completions
# z, the zsh version x-have python && antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
export ZSHZ_DATA="$XDG_STATE_HOME/z"
antigen bundle z
# these should be always available # this needs to be the last item
antigen bundle tmux antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle colored-man-pages antigen apply
antigen bundle ssh-agent fi
antigen bundle jreese/zsh-titles
antigen bundle zsh-users/zsh-completions
x-have python && antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
# this needs to be the last item
antigen bundle zsh-users/zsh-syntax-highlighting
antigen apply
# shellcheck source=../config/fzf/fzf.zsh
[ -f "${DOTFILES}/config/fzf/fzf.zsh" ] \
&& source "${DOTFILES}/config/fzf/fzf.zsh"
x-have pyenv && {
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
} }
# Run only if tmux is active # Function to source FZF configuration
[[ -n "$TMUX" ]] && { source_fzf_config()
# Autoupdate tmux window name {
TMUX_WINDOW_NAME_PLUGIN="$DOTFILES/config/tmux/plugins/tmux-window-name/scripts/rename_session_windows.py" local fzf_config="${DOTFILES}/config/fzf/fzf.zsh"
[ -f "$TMUX_WINDOW_NAME_PLUGIN" ] && { if [[ -f "$fzf_config" ]]; then
tmux_window_name() # shellcheck source=config/fzf/fzf.zsh
{ source "$fzf_config"
($TMUX_WINDOW_NAME_PLUGIN &) fi
}
add-zsh-hook chpwd tmux_window_name
tmux_window_name
}
} }
x-have antidot && { # Function to initialize pyenv if available
eval "$(antidot init)" initialize_pyenv()
{
if x-have pyenv; then
[[ -d $PYENV_ROOT/bin ]] && x-path-append "$PYENV_ROOT/bin"
[[ -d $PYENV_ROOT/shims ]] && x-path-append "$PYENV_ROOT/shims"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
} }
# Function to set up tmux window name plugin if tmux is active
setup_tmux_window_name_plugin()
{
if [[ -n "$TMUX" ]]; then
local tmux_window_name_plugin="$DOTFILES/config/tmux/plugins/tmux-window-name/scripts/rename_session_windows.py"
if [[ -f "$tmux_window_name_plugin" ]]; then
tmux_window_name()
{
($tmux_window_name_plugin &)
}
add-zsh-hook chpwd tmux_window_name
tmux_window_name
fi
fi
}
# Function to initialize antidot if available
initialize_antidot()
{
if x-have antidot; then
eval "$(antidot init)"
fi
}
main()
{
load_antigen
source_fzf_config
initialize_pyenv
setup_tmux_window_name_plugin
initialize_antidot
}
main "$@"
# Herd checks for a few environment variables to inject PHP binaries and configurations. # Herd checks for a few environment variables to inject PHP binaries and configurations.
# Herd injected PHP binary. # Herd injected PHP binary.
# export PATH="/Users/ivuorinen/Library/Application\ Support/Herd/bin/":$PATH # export PATH="/Users/ivuorinen/Library/Application\ Support/Herd/bin/":$PATH

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck source="../scripts/shared.sh"
# shellcheck disable=1091,2139
# Color the grep output # Color the grep output
alias grep="grep --color" alias grep="grep --color"
@@ -32,7 +30,6 @@ alias l="ls -a"
# Prevent common typos # Prevent common typos
alias cd..="cd .." alias cd..="cd .."
alias sl="ls" alias sl="ls"
alias ls-="ls -$1"
# List only directories # List only directories
alias lsd="ls -lF | grep '^d'" alias lsd="ls -lF | grep '^d'"
@@ -115,63 +112,3 @@ if [[ $(uname) == 'Darwin' ]]; then
# Using herd for php now, so this is not needed anymore # Using herd for php now, so this is not needed anymore
# x-set-php-aliases # x-set-php-aliases
fi fi
# Alacritty preexec hook to update dynamic title
preexec()
{
print -Pn "\e]0;$1%~\a"
}
# Update dotfiles
dfu()
{
(
cd "$DOTFILES" && git pull --ff-only && ./install -q
)
}
# Weather in Tampere, or other city
weather()
{
# https://github.com/chubin/wttr.in#usage
local city="${1:-Tampere}"
curl "http://wttr.in/${city// /+}?2nFQM&lang=fi"
}
# Docker
ssh_docker()
{
docker exec -it "$@" bash
}
# Rector project to php version 8.2 by default.
rector()
{
local php="${1:-82}"
docker run -v "$(pwd)":/project rector/rector:latest process \
"/project/$1" \
--set "php${php}" \
--autoload-file /project/vendor/autoload.php
}
# Commit everything
commit()
{
commitMessage="$*"
if [ "$commitMessage" = "" ]; then
commitMessage="Automated commit"
fi
git add .
eval "git commit -a -m '${commitMessage}'"
}
scheduler()
{
while :; do
php artisan schedule:run
echo "Sleeping 60 seconds..."
sleep 60
done
}

View File

@@ -2,14 +2,35 @@
# shellcheck shell=bash # shellcheck shell=bash
# vim: filetype=zsh # vim: filetype=zsh
# Set XDG directories if not already set
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
[ -z "$XDG_CONFIG_HOME" ] && export $XDG_CONFIG_HOME="$HOME/.config"
[ -z "$XDG_DATA_HOME" ] && export $XDG_DATA_HOME="$HOME/.local/share"
[ -z "$XDG_CACHE_HOME" ] && export $XDG_CACHE_HOME="$HOME/.cache"
[ -z "$XDG_STATE_HOME" ] && export $XDG_STATE_HOME="$HOME/.local/state"
[ -z "$XDG_BIN_HOME" ] && export $XDG_BIN_HOME="$HOME/.local/bin"
# if DOTFILES is not set, set it to the default location
[ -z "$DOTFILES" ] && export DOTFILES="$HOME/.dotfiles"
if ! command -v msg &> /dev/null; then
# Function to print messages if VERBOSE is enabled
# $1 - message (string)
msg()
{
[[ "$VERBOSE" -eq 1 ]] && echo "-> $1"
return 0
}
fi
# Cache commands using bkt if installed # Cache commands using bkt if installed
if command -v bkt >&/dev/null; then if command -v bkt &> /dev/null; then
bkt() bkt()
{ {
command bkt --cache-dir="$XDG_CACHE_HOME/bkt" "$@" command bkt --cache-dir="$XDG_CACHE_HOME/bkt" "$@"
} }
else else
# If bkt isn't installed skip its arguments and just execute directly. # If bkt isn't installed, skip its arguments and just execute directly.
# Optionally write a msg to stderr suggesting users install bkt. # Optionally write a msg to stderr suggesting users install bkt.
bkt() bkt()
{ {
@@ -18,48 +39,54 @@ else
} }
fi 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 # this version does not use caching.
# usage: have_command php && php -v # Usage: have_command php && php -v
have_command() have_command()
{ {
command -v "$1" >&/dev/null [ -z "$1" ] && {
} echo "Usage: have_command <command>"
return 1
# shorthand for checking if the system has the bin in path,
# this version uses caching
# usage: have php && php -v
have()
{
bkt -- which "$1" >&/dev/null
}
# function to run dark-notify and change alacritty theme
# it uses flock to prevent running multiple instances
# install flock with `brew install flock` on macOS
function darknotify_alacritty
{
have flock && [[ -f /tmp/dark-notify-alacritty.lock ]] && return
have dark-notify && {
# true is used to prevent the command show it was backgrounded
true \
&& flock /tmp/dark-notify-alacritty.lock dark-notify -c "$HOME/.dotfiles/local/bin/x-change-alacritty-theme" &
} }
return 0 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
have()
{
bkt -- which "$1" &> /dev/null
}
# Function to run dark-notify and change alacritty theme
# It uses flock to prevent running multiple instances.
# Install flock with `brew install flock` on macOS.
darknotify_alacritty()
{
x-have flock && [[ -f /tmp/dark-notify-alacritty.lock ]] && return
x-have dark-notify && {
# subprocess is used to prevent the command from showing it was backgrounded
(
flock /tmp/dark-notify-alacritty.lock dark-notify \
-c "$HOME/.dotfiles/local/bin/x-change-alacritty-theme" &
) &> /dev/null
}
} }
darknotify_alacritty darknotify_alacritty
# Function to list installed Homebrew packages using bkt caching
brew_installed() brew_installed()
{ {
bkt -- brew list bkt -- brew list
} }
# shorthand for checking if brew package is installed # Shorthand for checking if a Homebrew package is installed
# usage: have_brew php && php -v # Usage: have_brew php && php -v
have_brew() have_brew()
{ {
! x-have brew && return 125 ! have brew && return 125
if bkt -- brew list "$1" &> /dev/null; then if bkt -- brew list "$1" &> /dev/null; then
return 0 return 0
@@ -68,9 +95,369 @@ have_brew()
fi fi
} }
if [[ -f "$DOTFILES/config/exports-secret" ]]; then # Alacritty preexec hook to update dynamic title
source "$DOTFILES/config/exports-secret" preexec()
fi {
print -Pn "\e]0;$1%~\a"
}
source "$DOTFILES/config/exports-shell" # Update dotfiles
source "$DOTFILES/config/exports-apps" dfu()
{
(
cd "$DOTFILES" && git pull --ff-only && ./install -q
)
}
# Weather in Tampere, or other city
weather()
{
# https://github.com/chubin/wttr.in#usage
local city="${1:-Tampere}"
curl "http://wttr.in/${city// /+}?2nFQM&lang=fi"
}
# Docker
ssh_docker()
{
docker exec -it "$@" bash
}
# Rector project to php version 8.2 by default.
rector()
{
local php="${1:-82}"
docker run -v "$(pwd)":/project rector/rector:latest process \
"/project/$1" \
--set "php${php}" \
--autoload-file /project/vendor/autoload.php
}
# Commit everything
commit()
{
local commitMessage="$*"
if [ -z "$commitMessage" ]; then
commitMessage="Automated commit"
fi
git add .
git commit -a -m "$commitMessage"
}
scheduler()
{
while :; do
php artisan schedule:run
echo "Sleeping 60 seconds..."
sleep 60
done
}
# 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:]]' "${@}"
}
# Remove non-ascii characters from string
# Usage: strip_nonascii "string"
strip_nonascii()
{
echo "$1" | LC_ALL=C sed 's/[^[:print:][:space:]]//g'
}
# Slugify a string
# Usage: slugify "string"
slugify()
{
echo "$1" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
}
# https://stackoverflow.com/a/85932
fn_exists()
{
declare -f -F "$1" > /dev/null
return $?
}
# Creates a random string
rnd()
{
echo $RANDOM | md5sum | head -c 20
}
# return sha256sum for file
# $1 - filename (string)
get_sha256sum()
{
sha256sum "$1" | head -c 64
}
# Replaceable file
#
# $1 - filename (string)
# $2 - filename (string)
#
# Returns 1 when replaceable, 0 when not replaceable.
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
}
export COMPLETION_WAITING_DOTS=true
# Bash completion file location
export BASH_COMPLETION_USER_FILE="${XDG_CONFIG_HOME}/bash-completion/bash_completion"
# History env variables
export HIST_STAMPS="yyyy-mm-dd"
# Larger bash history (allow 32³ entries; default is 500)
export HISTSIZE=32768
export HISTFILESIZE=$HISTSIZE
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
export HISTCONTROL=ignoreboth
# Make some commands not show up in history
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"
# And include the parameter for ZSH
export HISTORY_IGNORE="(ls|cd|cd -|pwd|exit|date|* --help)"
# Less history location
export LESSHISTFILE="$XDG_STATE_HOME"/less/history
# Highlight section titles in manual pages
# export LESS_TERMCAP_md="$ORANGE"
# zsh autoloaded terminfo
export TERMINFO="${XDG_DATA_HOME}/terminfo"
export TERMINFO_DIRS="${XDG_DATA_HOME}/terminfo":/usr/share/terminfo
# Don't clear the screen after quitting a manual page
export MANPAGER="less -X"
# Always enable colored `grep` output
export GREP_OPTIONS="--color=auto"
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
hash shopt 2> /dev/null && shopt -s checkwinsize
# Antigen configuration
# https://github.com/zsh-users/antigen/wiki/Configuration
msg "Setting up Antigen configuration"
export ADOTDIR="$XDG_DATA_HOME/antigen"
export ANTIGEN_CACHE="$XDG_CACHE_HOME/antigen"
export ANTIGEN_SYSTEM_RECEIPT_F=".local/share/antigen/antigen_system_lastupdate"
export ANTIGEN_PLUGIN_RECEIPT_F=".local/share/antigen/antigen_plugin_lastupdate"
# Ansible configuration
# https://docs.ansible.com/ansible/latest/reference_appendices/config.html
msg "Setting up Ansible configuration"
export ANSIBLE_HOME="$XDG_CONFIG_HOME/ansible"
export ANSIBLE_CONFIG="$XDG_CONFIG_HOME/ansible.cfg"
export ANSIBLE_GALAXY_CACHE_DIR="$XDG_CACHE_HOME/ansible/galaxy_cache"
x-dc "$ANSIBLE_HOME"
x-dc "$ANSIBLE_GALAXY_CACHE_DIR"
# asdf
# https://github.com/asdf-vm/asdf
msg "Setting up asdf configuration"
export ASDF_DIR="${XDG_BIN_HOME}/asdf"
export ASDF_CONFIG_FILE="${XDG_CONFIG_HOME}/asdf/asdfrc"
export ASDF_DATA_DIR="${ASDF_DIR}"
# This seems wrong, but `asdf info` and `versions.bash` differ on path resolution.
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=".config/asdf/tool-versions"
export ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME="${XDG_CONFIG_HOME}/asdf/plugin-versions"
export ASDF_LOG_FILE="${XDG_CACHE_HOME}/asdf/asdf.log"
export ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY="latest_available"
export ASDF_NPM_DEFAULT_PACKAGES_FILE="${XDG_CONFIG_HOME}/asdf/npm-packages"
export ASDF_GOLANG_MOD_VERSION_ENABLED=true
export ASDF_GOLANG_DEFAULT_PACKAGES_FILE="${XDG_CONFIG_HOME}/asdf/golang-packages"
export ASDF_CRATE_DEFAULT_PACKAGES_FILE="${XDG_CONFIG_HOME}/asdf/cargo-packages"
export PATH="${ASDF_DIR}/bin:${PATH}"
# bob manages nvim versions
msg "Setting up bob configuration"
x-path-prepend "$XDG_DATA_HOME/bob/nvim-bin"
# bkt (shell command caching tool) configuration
msg "Setting up bkt configuration"
export BKT_TTL=1m
# brew, https://docs.brew.sh/Manpage
msg "Setting up Homebrew configuration"
export HOMEBREW_NO_ANALYTICS=true
export HOMEBREW_NO_ENV_HINTS=true
export HOMEBREW_BUNDLE_MAS_SKIP=true
export HOMEBREW_BUNDLE_FILE="$XDG_CONFIG_HOME/homebrew/Brewfile"
x-have brew && {
eval "$(brew shellenv)"
}
# composer, https://getcomposer.org/
msg "Setting up Composer configuration"
export COMPOSER_HOME="$XDG_STATE_HOME/composer"
export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin"
export PATH="$COMPOSER_BIN:$PATH"
# docker, https://docs.docker.com/engine/reference/commandline/cli/
msg "Setting up Docker configuration"
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
x-dc "$DOCKER_CONFIG"
# Docker: Disable snyk ad
export DOCKER_SCAN_SUGGEST=false
# ffmpeg
# https://ffmpeg.org/ffmpeg.html
msg "Setting up FFmpeg configuration"
export FFMPEG_DATADIR="$XDG_CONFIG_HOME/ffmpeg"
x-have ffmpeg && x-dc "$FFMPEG_DATADIR"
# GnuPG
# https://gnupg.org/documentation/manuals/gnupg/Invoking-GPG.html
msg "Setting up GnuPG configuration"
export GNUPGHOME="$XDG_DATA_HOME/gnupg"
# Go
# https://golang.org/doc/code.html
msg "Setting up Go configuration"
export GOPATH="$XDG_DATA_HOME/go"
export GOBIN="$XDG_BIN_HOME"
# Herd, herd.laravel.com
# Herd injected PHP binary.
msg "Setting up Herd configuration"
export PATH="$HOME/Library/Application\ Support/Herd/bin/":$PATH
x-have herd && {
# Herd injected PHP 8.3 configuration.
export HERD_PHP_83_INI_SCAN_DIR="$HOME/Library/Application\ Support/Herd/config/php/83/"
# Herd injected PHP 7.4 configuration.
export HERD_PHP_74_INI_SCAN_DIR="$HOME/Library/Application\ Support/Herd/config/php/74/"
}
# nb, https://xwmx.github.io/nb/
msg "Setting up nb configuration"
export NBRC_PATH="$XDG_CONFIG_HOME/nbrc"
export NB_DIR="$XDG_STATE_HOME/nb"
# NPM: Add npm packages to path
msg "Setting up NPM configuration"
x-have node && {
NVM_NODE_BIN_DIR="$(dirname "$(which node)")"
export PATH="$NVM_NODE_BIN_DIR:$PATH"
}
# oh-my-posh (omp) configuration
msg "Setting up oh-my-posh configuration"
export OHMYPOSH_CFG="$DOTFILES/config/omp/own.toml"
# op (1Password cli) is present
msg "Setting up 1Password CLI configuration"
export OP_CACHE="$XDG_STATE_HOME/1password"
# Python
#
# pyenv, python environments
msg "Setting up Python configuration"
export WORKON_HOME="$XDG_DATA_HOME/virtualenvs"
export PYENV_ROOT="$XDG_STATE_HOME/pyenv"
export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
x-have pyenv && {
eval "$(pyenv init -)"
}
# Ruby
#
# including: bundler, rbenv
msg "Setting up Ruby configuration"
export GEM_HOME="${XDG_DATA_HOME}"/gem
export GEM_SPEC_CACHE="${XDG_CACHE_HOME}"/gem
export BUNDLE_USER_CONFIG="$XDG_CONFIG_HOME"/bundle
export BUNDLE_USER_CACHE="$XDG_CACHE_HOME"/bundle
export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle
export RBENV_ROOT="$XDG_STATE_HOME/rbenv"
x-dc "$RBENV_ROOT"
x-have gem && export PATH="${GEM_HOME}/bin:$PATH"
# Rust / cargo
msg "Setting up Rust/Cargo configuration"
export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
export CARGO_HOME="$XDG_DATA_HOME/cargo"
export PATH="$CARGO_HOME/bin:$PATH"
# screen
# https://www.gnu.org/software/screen/manual/screen.html
msg "Setting up screen configuration"
export SCREENRC="$XDG_CONFIG_HOME/misc/screenrc"
# sonarlint
# https://www.sonarlint.org/
msg "Setting up Sonarlint configuration"
export SONARLINT_USER_HOME="$XDG_DATA_HOME/sonarlint"
# terraform
# https://www.terraform.io/docs/cli/config/config-file.html
# https://www.terraform.io/docs/cli/config/environment-variables.html
msg "Setting up Terraform configuration"
export TF_DATA_DIR="$XDG_STATE_HOME/terraform"
export TF_CLI_CONFIG_FILE="$XDG_CONFIG_HOME/terraform/terraformrc"
export TF_PLUGIN_CACHE_DIR="$XDG_CACHE_HOME/terraform/plugin-cache"
# tldr / tealdeer
msg "Setting up tldr configuration"
export TEALDEER_CONFIG_DIR="$XDG_CONFIG_HOME/tealdeer/"
# tmux
# https://tmux.github.io/
msg "Setting up tmux configuration"
export TMUX_CONF="$XDG_CONFIG_HOME/tmux/tmux.conf"
# wakatime, https://github.com/wakatime/wakatime-cli
msg "Setting up Wakatime configuration"
export WAKATIME_HOME="$XDG_STATE_HOME/wakatime"
x-dc "$WAKATIME_HOME"
# Misc
msg "Setting up miscellaneous configuration"
export CHEAT_USE_FZF=true
export SQLITE_HISTORY="${XDG_CACHE_HOME}/sqlite_history"

View File

@@ -1,150 +0,0 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# shellcheck enable=external-sources
# shellcheck disable=1091,2139
# vim: filetype=bash
# Antigen configuration
# https://github.com/zsh-users/antigen/wiki/Configuration
export ADOTDIR="$XDG_DATA_HOME/antigen"
export ANTIGEN_CACHE="$XDG_CACHE_HOME/antigen"
export ANTIGEN_SYSTEM_RECEIPT_F=".local/share/antigen/antigen_system_lastupdate"
export ANTIGEN_PLUGIN_RECEIPT_F=".local/share/antigen/antigen_plugin_lastupdate"
# Ansible configuration
# https://docs.ansible.com/ansible/latest/reference_appendices/config.html
export ANSIBLE_HOME="$XDG_CONFIG_HOME/ansible"
export ANSIBLE_CONFIG="$XDG_CONFIG_HOME/ansible.cfg"
export ANSIBLE_GALAXY_CACHE_DIR="$XDG_CACHE_HOME/ansible/galaxy_cache"
x-dc "$ANSIBLE_HOME"
x-dc "$ANSIBLE_GALAXY_CACHE_DIR"
export ANDROID_HOME="$XDG_DATA_HOME/android"
# asdf
# https://github.com/asdf-vm/asdf
export ASDF_DIR="${XDG_BIN_HOME}/asdf"
export ASDF_CONFIG_FILE="${XDG_CONFIG_HOME}/asdf/asdfrc"
export ASDF_DATA_DIR="${ASDF_DIR}"
# This seems wrong, but `asdf info` and `versions.bash` differ on path resolution.
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=".config/asdf/tool-versions"
export ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME="${XDG_CONFIG_HOME}/asdf/plugin-versions"
export ASDF_LOG_FILE="${XDG_CACHE_HOME}/asdf/asdf.log"
export ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY="latest_available"
export ASDF_NPM_DEFAULT_PACKAGES_FILE="${XDG_CONFIG_HOME}/asdf/npm-packages"
export ASDF_GOLANG_MOD_VERSION_ENABLED=true
export ASDF_GOLANG_DEFAULT_PACKAGES_FILE="${XDG_CONFIG_HOME}/asdf/golang-packages"
export ASDF_CRATE_DEFAULT_PACKAGES_FILE="${XDG_CONFIG_HOME}/asdf/cargo-packages"
export PATH="${ASDF_DIR}/bin:${PATH}"
# bob manages nvim versions
export PATH="$XDG_DATA_HOME/bob/nvim-bin:$PATH"
# bkt (shell command caching tool) configuration
export BKT_TTL=1m
# brew, https://docs.brew.sh/Manpage
export HOMEBREW_NO_ENV_HINTS=true
export HOMEBREW_BUNDLE_MAS_SKIP=true
export HOMEBREW_BUNDLE_FILE="$XDG_CONFIG_HOME/homebrew/Brewfile"
# composer, https://getcomposer.org/
export COMPOSER_HOME="$XDG_STATE_HOME/composer"
export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin"
export PATH="$COMPOSER_BIN:$PATH"
# docker, https://docs.docker.com/engine/reference/commandline/cli/
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
x-dc "$DOCKER_CONFIG"
# Docker: Disable snyk ad
export DOCKER_SCAN_SUGGEST=false
# ffmpeg
export FFMPEG_DATADIR="$XDG_CONFIG_HOME/ffmpeg"
x-have ffmpeg && x-dc "$FFMPEG_DATADIR"
# GnuPG
export GNUPGHOME="$XDG_DATA_HOME/gnupg"
# Go
export GOPATH="$XDG_DATA_HOME/go"
export GOBIN="$XDG_BIN_HOME"
# Herd, herd.laravel.com
# Herd injected PHP binary.
export PATH="$HOME/Library/Application\ Support/Herd/bin/":$PATH
x-have herd && {
# Herd injected PHP 8.3 configuration.
export HERD_PHP_83_INI_SCAN_DIR="$HOME/Library/Application\ Support/Herd/config/php/83/"
# Herd injected PHP 7.4 configuration.
export HERD_PHP_74_INI_SCAN_DIR="$HOME/Library/Application\ Support/Herd/config/php/74/"
}
# nb, https://xwmx.github.io/nb/
export NBRC_PATH="$XDG_CONFIG_HOME/nbrc"
export NB_DIR="$XDG_STATE_HOME/nb"
# NPM: Add npm packages to path
x-have node && {
NVM_NODE_BIN_DIR="$(dirname "$(which node)")"
export PATH="$NVM_NODE_BIN_DIR:$PATH"
}
# op (1Password cli) is present
export OP_CACHE="$XDG_STATE_HOME/1password"
# Python
#
# pyenv, python environments
export WORKON_HOME="$XDG_DATA_HOME/virtualenvs"
export PYENV_ROOT="$XDG_STATE_HOME/pyenv"
export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
x-have pyenv && {
eval "$(pyenv init -)"
}
# Ruby
#
# including: bundler, rbenv
export GEM_HOME="${XDG_DATA_HOME}"/gem
export GEM_SPEC_CACHE="${XDG_CACHE_HOME}"/gem
export BUNDLE_USER_CONFIG="$XDG_CONFIG_HOME"/bundle
export BUNDLE_USER_CACHE="$XDG_CACHE_HOME"/bundle
export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle
export RBENV_ROOT="$XDG_STATE_HOME/rbenv"
x-dc "$RBENV_ROOT"
x-have gem && export PATH="${GEM_HOME}/bin:$PATH"
# Rust / cargo
export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
export CARGO_HOME="$XDG_DATA_HOME/cargo"
export PATH="$CARGO_HOME/bin:$PATH"
# screen
export SCREENRC="$XDG_CONFIG_HOME/misc/screenrc"
# sonarlint
export SONARLINT_USER_HOME="$XDG_DATA_HOME/sonarlint"
# terraform
# https://www.terraform.io/docs/cli/config/config-file.html
# https://www.terraform.io/docs/cli/config/environment-variables.html
export TF_DATA_DIR="$XDG_STATE_HOME/terraform"
export TF_CLI_CONFIG_FILE="$XDG_CONFIG_HOME/terraform/terraformrc"
export TF_PLUGIN_CACHE_DIR="$XDG_CACHE_HOME/terraform/plugin-cache"
# tldr / tealdeer
export TEALDEER_CONFIG_DIR="$XDG_CONFIG_HOME/tealdeer/"
# tmux
export TMUX_CONF="$XDG_CONFIG_HOME/tmux/tmux.conf"
# wakatime, https://github.com/wakatime/wakatime-cli
export WAKATIME_HOME="$XDG_STATE_HOME/wakatime"
x-dc "$WAKATIME_HOME"
# Misc
export BAT_THEME="ansi"
export CHEAT_USE_FZF=true
export SQLITE_HISTORY="$XDG_CACHE_HOME"/sqlite_history

View File

@@ -1,19 +1,25 @@
# lakka exports # lakka exports
## LUA ## LUA
x-have luarocks && $(luarocks path --bin) if command -v luarocks &> /dev/null; then
eval "$(luarocks path --bin)"
fi
export PATH="$HOME/.local/go/bin:$PATH" export PATH="$HOME/.local/go/bin:$PATH"
alias logrotate='/usr/sbin/logrotate -s $HOME/logs/state' alias logrotate='/usr/sbin/logrotate -s "$HOME/logs/state"'
alias nano='nano -wS -$' alias nano='nano -wS -$'
alias gpg=gpg2 alias gpg=gpg2
ACME_PATH="$HOME/.acme.sh" ACME_PATH="$HOME/.acme.sh"
# shellcheck source=$HOME/.acme.sh/acme.sh.env # shellcheck source=$HOME/.acme.sh/acme.sh.env
[[ -s "$ACME_PATH/acme.sh.env" ]] && . "$ACME_PATH/acme.sh.env" if [[ -s "$ACME_PATH/acme.sh.env" ]]; then
source "$ACME_PATH/acme.sh.env"
fi
export RVM_PATH="$HOME/.rvm" export RVM_PATH="$HOME/.rvm"
export PATH="$RVM_PATH/bin:$PATH" export PATH="$RVM_PATH/bin:$PATH"
# shellcheck source=$HOME/.rvm/scripts/rvm # shellcheck source=$HOME/.rvm/scripts/rvm
[[ -s "$RVM_PATH/scripts/rvm" ]] && source "$RVM_PATH/scripts/rvm" # Load RVM into a shell session *as a function* if [[ -s "$RVM_PATH/scripts/rvm" ]]; then
source "$RVM_PATH/scripts/rvm" # Load RVM into a shell session *as a function*
fi

View File

@@ -1,40 +0,0 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# shellcheck disable=1091,2046
# vim: filetype=bash
# Bash completion file location
export BASH_COMPLETION_USER_FILE="${XDG_CONFIG_HOME}/bash-completion/bash_completion"
# History env variables
export HIST_STAMPS="yyyy-mm-dd"
# Larger bash history (allow 32³ entries; default is 500)
export HISTSIZE=32768
export HISTFILESIZE=$HISTSIZE
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
export HISTCONTROL=ignoreboth
# Make some commands not show up in history
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"
# And include the parameter for ZSH
export HISTORY_IGNORE="(ls|cd|cd -|pwd|exit|date|* --help)"
# Less history location
export LESSHISTFILE="$XDG_STATE_HOME"/less/history
# Highlight section titles in manual pages
# export LESS_TERMCAP_md="$ORANGE"
# zsh autoloaded terminfo
export TERMINFO="${XDG_DATA_HOME}/terminfo"
export TERMINFO_DIRS="${XDG_DATA_HOME}/terminfo":/usr/share/terminfo
# Don't clear the screen after quitting a manual page
export MANPAGER="less -X"
# Always enable colored `grep` output
export GREP_OPTIONS="--color=auto"
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
hash shopt 2> /dev/null && shopt -s checkwinsize

View File

@@ -1,3 +0,0 @@
#!/usr/bin/env bash
#
# shell functions

View File

@@ -1,23 +1,96 @@
#!/usr/bin/env bash
#
# Shared configuration
#
# shellcheck shell=bash # shellcheck shell=bash
# Defaults # Defaults
export DOTFILES="$HOME/.dotfiles" [ -z "$DOTFILES" ] && export DOTFILES="$HOME/.dotfiles"
export DOTFILES_CURRENT_SHELL=$(basename "$SHELL")
# Explicitly set XDG folders # Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
# Enable debugging with DEBUG=1
DEBUG="${DEBUG:-0}"
# Enable debugging with DEBUG=1
[ "${DEBUG:-0}" -eq 1 ] && set -x
# Explicitly set XDG folders, if not already set
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html # https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
export XDG_CONFIG_HOME="$HOME/.config" [ -z "$XDG_CONFIG_HOME" ] && export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share" [ -z "$XDG_DATA_HOME" ] && export $XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state" [ -z "$XDG_STATE_HOME" ] && export $XDG_STATE_HOME="$HOME/.local/state"
[ -z "$XDG_BIN_HOME" ] && export XDG_BIN_HOME="$HOME/.local/bin"
# custom variables [ -z "$XDG_CACHE_HOME" ] && export XDG_CACHE_HOME="$HOME/.cache"
export XDG_BIN_HOME="$HOME/.local/bin"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_RUNTIME_DIR="$HOME/.local/run"
# Paths # Paths
export PATH="$XDG_BIN_HOME:$DOTFILES/local/bin:$HOME/.local/go/bin:$XDG_DATA_HOME/bob/nvim-bin:$XDG_DATA_HOME/cargo/bin:/opt/homebrew/bin:/usr/local/bin:$PATH" x-path-prepend "/usr/local/bin"
x-path-prepend "/opt/homebrew/bin"
x-path-prepend "$XDG_DATA_HOME/cargo/bin"
x-path-prepend "$XDG_DATA_HOME/bob/nvim-bin"
x-path-prepend "$DOTFILES/local/bin"
x-path-prepend "$XDG_BIN_HOME"
# Custom completion paths
[ -z "$ZSH_CUSTOM_COMPLETION_PATH" ] && export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion"
x-dc "$ZSH_CUSTOM_COMPLETION_PATH"
export FPATH="$ZSH_CUSTOM_COMPLETION_PATH:$FPATH"
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
}
msg "msg was not defined, defined it now"
fi
if ! declare -f msg_err > /dev/null; then
msg "msg_err was not defined, defined it now"
# 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
msg "msg_done was not defined, defined it now"
# Function to print done message
# $1 - message (string)
msg_done()
{
echo "$1"
return 0
}
fi
if ! declare -f msg_run > /dev/null; then
msg "msg_run was not defined, defined it now"
# Function to print running message
# $1 - message (string)
msg_run()
{
echo "$1"
return 0
}
fi
if ! declare -f msg_ok > /dev/null; then
msg "msg_ok was not defined, defined it now"
# Function to print ok message
# $1 - message (string)
msg_ok()
{
echo "$1"
return 0
}
fi
# Split config files
source "$DOTFILES/config/exports" source "$DOTFILES/config/exports"
source "$DOTFILES/config/functions"
source "$DOTFILES/config/alias" source "$DOTFILES/config/alias"

View File

@@ -14,19 +14,92 @@
SCRIPT=$(basename "$0") SCRIPT=$(basename "$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
VERSION_NVM="v0.39.5" VERSION_NVM="v0.39.5"
export DOTFILES="$HOME/.dotfiles"
# shellcheck source=./../../scripts/shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
source "$DOTFILES/config/exports"
source "$DOTFILES/config/alias"
source "$DOTFILES/config/functions"
# Loads configs for better installation experience # Loads configs for better installation experience
x-load-configs source "$DOTFILES/config/shared.sh"
function section_install source "${DOTFILES}/local/bin/msgr"
# -- Menu builder -- #
menu_section()
{
LINE=$(printf '%-18s [ %-15s ]\n' "$1" "$2")
echo -e " $(__log_marker) $LINE"
}
menu_item()
{
LINE=$(printf '%-15s %-30s\n' "$1" "$2")
echo -e "$(__log_indent)$(__log_marker) $LINE"
}
# Takes a bash array ("cow:moo", "dinosaur:roar") and loops
# through the keys to build menu section listing.
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.
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
}
section_install()
{ {
USAGE_PREFIX="$SCRIPT install <command>" USAGE_PREFIX="$SCRIPT install <command>"
@@ -56,7 +129,6 @@ function section_install
case "$1" in case "$1" in
all) all)
msgr msg "Starting to install all and reloading configurations..." msgr msg "Starting to install all and reloading configurations..."
x-load-configs
$0 install macos $0 install macos
$0 install fonts $0 install fonts
$0 install antigen $0 install antigen
@@ -79,7 +151,7 @@ function section_install
$0 install ntfy $0 install ntfy
$0 install z $0 install z
msgr msg "Reloading configurations again..." msgr msg "Reloading configurations again..."
x-load-configs source "$DOTFILES/config/shared.sh"
msgr yay "All done!" msgr yay "All done!"
;; ;;
antigen) antigen)
@@ -210,7 +282,7 @@ function section_install
esac esac
} }
function section_brew section_brew()
{ {
USAGE_PREFIX="$SCRIPT brew <command>" USAGE_PREFIX="$SCRIPT brew <command>"
@@ -258,7 +330,7 @@ function section_brew
! x-have brew && menu_section "$USAGE_PREFIX" "brew not available on this system" ! x-have brew && menu_section "$USAGE_PREFIX" "brew not available on this system"
} }
function section_helpers section_helpers()
{ {
USAGE_PREFIX="$SCRIPT helpers <command>" USAGE_PREFIX="$SCRIPT helpers <command>"
MENU=( MENU=(
@@ -274,7 +346,7 @@ function section_helpers
esac esac
} }
function section_docs section_docs()
{ {
USAGE_PREFIX="$SCRIPT docs <command>" USAGE_PREFIX="$SCRIPT docs <command>"
@@ -288,7 +360,7 @@ function section_docs
esac esac
} }
function section_dotfiles section_dotfiles()
{ {
USAGE_PREFIX="$SCRIPT dotfiles <command>" USAGE_PREFIX="$SCRIPT dotfiles <command>"
@@ -344,7 +416,7 @@ function section_dotfiles
esac esac
} }
function section_check section_check()
{ {
USAGE_PREFIX="$SCRIPT check <command>" USAGE_PREFIX="$SCRIPT check <command>"
X_HOSTNAME=$(hostname) X_HOSTNAME=$(hostname)
@@ -369,7 +441,7 @@ function section_check
} }
# Secret menu for visual tests # Secret menu for visual tests
function section_tests section_tests()
{ {
USAGE_PREFIX="$SCRIPT tests <command>" USAGE_PREFIX="$SCRIPT tests <command>"
@@ -398,7 +470,7 @@ function section_tests
esac esac
} }
function usage usage()
{ {
echo "" echo ""
msg_prompt "Usage: $SCRIPT <section> <command>" msg_prompt "Usage: $SCRIPT <section> <command>"

View File

@@ -2,76 +2,97 @@
# Load our configuration files # Load our configuration files
# Copyright (c) 2023 Ismo Vuorinen. All Rights Reserved. # Copyright (c) 2023 Ismo Vuorinen. All Rights Reserved.
DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
source "$DOTFILES/config/shared.sh"
# Enable verbosity with VERBOSE=1 x-load-configs # Enable verbosity with VERBOSE=1 x-load-configs
VERBOSE="${VERBOSE:=0}" VERBOSE="${VERBOSE:-0}"
# Enable debugging with DEBUG=1 x-load-configs # Enable debugging with DEBUG=1 x-load-configs
DEBUG="${DEBUG:=0}" DEBUG="${DEBUG:-0}"
[ "$DEBUG" = "1" ] && { # Get the hostname
set -x CONFIG_HOST="$(hostname -s)"
# Enable debugging if requested
[ "$DEBUG" = "1" ] && set -x
CONFIG_PATH="${DOTFILES}/config"
[ -d "$DOTFILES" ] || {
msg_err "Error: DOTFILES is not set or $DOTFILES does not exist"
} }
CONFIG_PATH="$DOTFILES/config" # Function to print messages if VERBOSE is enabled
# $1 - message type (string)
# $2 - message content (string)
config_msg()
{
# if $1 is empty, return
[ -z "$1" ] && return
[ -z "$2" ] && $2=""
# Load the shell dotfiles, and then some: local msg_type="$1"
HOST="$(hostname -s)" local msg_content="$2"
[ "$VERBOSE" = "1" ] && { [[ "$VERBOSE" -eq 1 ]] && printf 'x-load-configs: %s %s\n' "$msg_type" "$msg_content"
echo "x-load-configs: VERBOSE=1" return 0
echo "x-load-configs: HOST: $HOST"
} }
configFile() # Function to get the full path of a config file
# $1 - filename (string)
config_file_path()
{ {
echo "$CONFIG_PATH/$1" echo "$CONFIG_PATH/$1"
} }
configMsg() # Function to source configuration files
source_config()
{ {
printf 'x-load-configs: %s %s\n' "$1" "$2" local config_file=$1
if [ -f "$config_file" ]; then
eval "$config_file"
config_msg "Sourced" "$config_file"
else
msg "Config file $config_file not found"
fi
return 0
} }
loadConfigFiles() # Function to load a configuration file
# $1 - base config file name (string)
load_config_files()
{ {
CONFIG_FILE=$1 local config_file="$1"
SECRET_FILE=$CONFIG_FILE-secret local secret_file="${config_file}-secret"
HOST_FILE=$CONFIG_FILE-$HOST local host_file="${config_file}-${CONFIG_HOST}"
SECRET_HOST=$HOST_FILE-secret local secret_host_file="${host_file}-secret"
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$CONFIG_FILE" config_msg "Looking for" "$config_file"
[ -r "$config_file" ] && {
# global (exports|alias|functions) FILENAME for all hosts source_config "$config_file"
# shellcheck source=../config/exports
[ -r "$CONFIG_FILE" ] && {
source "$CONFIG_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$CONFIG_FILE"
} }
# global secret FILENAME, git ignored config_msg "Looking for" "$secret_file"
# shellcheck source=../config/exports-secret [ -r "$secret_file" ] && {
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$SECRET_FILE" source_config "$secret_file"
[ -r "$SECRET_FILE" ] && {
source "$SECRET_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$SECRET_FILE"
} }
# host specific (exports|alias|functions) FILENAME
# shellcheck source=../config/exports config_msg "Looking for" "$host_file"
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$HOST_FILE" [ -r "$host_file" ] && {
[ -r "$HOST_FILE" ] && { source_config "$host_file"
source "$HOST_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$HOST_FILE"
} }
# host specific (exports|alias|functions) FILENAME, git ignored
# shellcheck source=../config/exports config_msg "Looking for" "$secret_host_file"
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$SECRET_HOST" [ -r "$secret_host_file" ] && {
[ -r "$SECRET_HOST" ] && { source_config "$secret_host_file"
source "$SECRET_HOST" \
&& [ "$VERBOSE" = "1" ] && configMsg "Found" "$SECRET_HOST"
} }
return 0
} }
FILE_EXPORTS=$(configFile "exports") config_msg "VERBOSE=1" "Verbose mode enabled"
FILE_FUNCTIONS=$(configFile "functions") config_msg "HOST" "$CONFIG_HOST"
FILE_ALIAS=$(configFile "alias")
loadConfigFiles "$FILE_EXPORTS"
loadConfigFiles "$FILE_FUNCTIONS"
loadConfigFiles "$FILE_ALIAS"
load_config_files "$(config_file_path "exports")"
load_config_files "$(config_file_path "functions")"
load_config_files "$(config_file_path "alias")"
exit 0 exit 0

View File

@@ -3,5 +3,65 @@
# Add a directory to the beginning of the PATH if it's not already there. # Add a directory to the beginning of the PATH if it's not already there.
# Usage: x-path-append <dir> # Usage: x-path-append <dir>
x-path-remove "$1" # Set verbosity with VERBOSE=1
export PATH="${PATH:+"$PATH:"}$1" VERBOSE="${VERBOSE:-0}"
# Function to print usage information
usage()
{
echo "Usage: $0 <dir>"
exit 1
}
# Function to print messages if VERBOSE is enabled
# $1 - message (string)
msg()
{
[[ "$VERBOSE" -eq 1 ]] && echo "$1"
}
# Function to remove a directory from PATH
# $1 - directory to remove (string)
remove_from_path()
{
local dir=$1
if echo "$PATH" | grep -qE "(^|:)$dir($|:)"; then
export PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$dir\"" | sed 's/:$//')
msg "Directory $dir has been removed from PATH"
else
msg "Directory $dir is not in PATH"
fi
}
# Function to append a directory to PATH
# $1 - directory to append (string)
append_to_path()
{
local dir=$1
if [ ! -d "$dir" ]; then
msg "(?) Directory $dir does not exist"
exit 0
fi
if echo "$PATH" | grep -qE "(^|:)$dir($|:)"; then
msg "(!) Directory $dir is already in PATH"
else
export PATH="${PATH:+"$PATH:"}$dir"
msg "(!) Directory $dir has been added to the end of PATH"
fi
}
# Main function
main()
{
if [ "$#" -ne 1 ]; then
usage
fi
remove_from_path "$1"
append_to_path "$1"
}
main "$@"

View File

@@ -3,4 +3,50 @@
# Add a directory to the front of the PATH if it exists and is not already there # Add a directory to the front of the PATH if it exists and is not already there
# Usage: x-path-prepend <dir> # Usage: x-path-prepend <dir>
export PATH="$1${PATH:+":$PATH"}" # Set verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
# Function to print usage information
usage()
{
echo "Usage: $0 <dir>"
exit 1
}
# Function to print messages if VERBOSE is enabled
# $1 - message (string)
msg()
{
[[ "$VERBOSE" -eq 1 ]] && echo "$1"
}
# Function to add a directory to the front of PATH
# $1 - directory to add (string)
prepend_to_path()
{
local dir=$1
if [ ! -d "$dir" ]; then
msg "(?) Directory $dir does not exist"
exit 0
fi
if echo "$PATH" | grep -qE "(^|:)$dir($|:)"; then
msg "(!) Directory $dir is already in PATH"
else
export PATH="$dir${PATH:+":$PATH"}"
msg "(!) Directory $dir has been added to the front of PATH"
fi
}
# Main function
main()
{
if [ "$#" -ne 1 ]; then
usage
fi
prepend_to_path "$1"
}
main "$@"

View File

@@ -3,4 +3,46 @@
# Remove a directory from the PATH # Remove a directory from the PATH
# Usage: x-path-remove <dir> # Usage: x-path-remove <dir>
export PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//') # Set verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
# Function to print usage information
usage()
{
echo "Usage: $0 <dir>"
exit 1
}
# Function to print messages if VERBOSE is enabled
# $1 - message (string)
msg()
{
[[ "$VERBOSE" -eq 1 ]] && echo "$1"
}
# Function to remove a directory from PATH
# $1 - directory to remove (string)
remove_from_path()
{
local dir=$1
if ! echo "$PATH" | grep -qE "(^|:)$dir($|:)"; then
msg "(?) Directory $dir is not in PATH"
exit 0
fi
export PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$dir\"" | sed 's/:$//')
msg "(!) Directory $dir has been removed from PATH"
}
# Main function
main()
{
if [ "$#" -ne 1 ]; then
usage
fi
remove_from_path "$1"
}
main "$@"

View File

@@ -1,20 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Create file containing key mappings for Neovim # Create file containing key mappings for Neovim
# Usage: ./create-nvim-keymaps.sh # 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" DEST="$HOME/.dotfiles/docs/nvim-keybindings.md"
main()
{ {
printf "# nvim keybindings\n"; msg "Generating Neovim keybindings documentation"
printf "\n";
printf "\`\`\`txt";
} > "$DEST"
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 printf "\n\`\`\`\n\n- Generated on %s\n" "$(date)" >> "$DEST"
sed -e '/^ Last set from/d' "$DEST" > "$DEST.tmp" && mv "$DEST.tmp" "$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 #!/usr/bin/env bash
# #
# Export oh-my-posh configuration as an image
#
# shellcheck source=shared.sh # shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh" source "${DOTFILES}/config/shared.sh"
set -e
cd "$DOTFILES" || exit main()
oh-my-posh config export image \ {
--config "$OHMYPOSH_CFG" \ cd "$DOTFILES" || msg_err "Failed to change directory to $DOTFILES"
--output "$HOME/.dotfiles/.github/screenshots/oh-my-posh.png" \
--author "Ismo Vuorinen" 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 #!/usr/bin/env bash
# #
# Install asdf # Install asdf
source "${DOTFILES}/config/shared.sh"
source "${XDG_CONFIG_HOME}/shared.sh"
source "${DOTFILES}/scripts/shared.sh"
export ASDF_DIR="${XDG_BIN_HOME}/asdf" export ASDF_DIR="${XDG_BIN_HOME}/asdf"
export PATH="${ASDF_DIR}/bin:$PATH" export PATH="${ASDF_DIR}/bin:$PATH"
@@ -11,16 +9,19 @@ export PATH="${ASDF_DIR}/bin:$PATH"
msg "Sourcing asdf in your shell" msg "Sourcing asdf in your shell"
. "$ASDF_DIR/asdf.sh" . "$ASDF_DIR/asdf.sh"
# Update asdf, and plugins # Function to update asdf and plugins
asdf update update_asdf()
{
asdf update
asdf plugin add asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git asdf plugin add asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git
asdf install asdf-plugin-manager latest asdf install asdf-plugin-manager latest
asdf global asdf-plugin-manager "$(asdf latest asdf-plugin-manager)" asdf global asdf-plugin-manager "$(asdf latest asdf-plugin-manager)"
asdf-plugin-manager version asdf-plugin-manager version
asdf-plugin-manager add-all asdf-plugin-manager add-all
asdf install asdf install
}
ASDF_INSTALLABLES=( ASDF_INSTALLABLES=(
"1password-cli:github.com/NeoHsu/asdf-1password-cli.git" "1password-cli:github.com/NeoHsu/asdf-1password-cli.git"
@@ -51,14 +52,25 @@ ASDF_INSTALLABLES=(
"yq:github.com/sudermanjr/asdf-yq.git" "yq:github.com/sudermanjr/asdf-yq.git"
) )
msg "Installing asdf plugins, if not already installed" # Function to install asdf plugins
for item in "${ASDF_INSTALLABLES[@]}"; do install_asdf_plugins()
CMD=$(echo "${item}" | awk -F ":" '{print $1}') {
URL=$(echo "${item}" | awk -F ":" '{print $2}') msg "Installing asdf plugins, if not already installed"
asdf plugin add "${CMD}" "https://${URL}" for item in "${ASDF_INSTALLABLES[@]}"; do
asdf install "${CMD}" latest CMD=$(echo "${item}" | awk -F ":" '{print $1}')
asdf global "${CMD}" "$(asdf latest "${CMD}")" URL=$(echo "${item}" | awk -F ":" '{print $2}')
done asdf plugin add "${CMD}" "https://${URL}"
asdf install "${CMD}" latest
asdf global "${CMD}" "$(asdf latest "${CMD}")"
done
}
msg "Reshim asdf" main()
asdf reshim {
update_asdf
install_asdf_plugins
msg "Reshim asdf"
asdf reshim
}
main "$@"

View File

@@ -2,18 +2,18 @@
# Install cargo/rust packages. # Install cargo/rust packages.
# #
# shellcheck source=shared.sh # shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh" eval "$HOME/.dotfiles/config/shared.sh"
msg "Starting to install rust/cargo packages" msg "Starting to install rust/cargo packages"
source "$CARGO_HOME/env" source "$CARGO_HOME/env"
# If we have cargo install-update, use it first # 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" msg_run "Updating cargo packages with cargo install-update"
cargo install-update -a cargo install-update -a
msg_done "Done with cargo install-update" msg_done "Done with cargo install-update"
} fi
packages=( packages=(
# A cargo subcommand for checking and applying # 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 # Number of jobs to run in parallel, this helps to keep the system responsive
BUILD_JOBS=$(nproc --ignore=2) BUILD_JOBS=$(nproc --ignore=2)
for pkg in "${packages[@]}"; do # Function to install cargo packages
# Trim spaces install_packages()
pkg=${pkg// /} {
# Skip comments for pkg in "${packages[@]}"; do
if [[ ${pkg:0:1} == "#" ]]; then continue; fi # Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_run "Installing cargo package $pkg" msg_run "Installing cargo package $pkg"
cargo install --jobs $BUILD_JOBS "$pkg" cargo install --jobs $BUILD_JOBS "$pkg"
echo ""
echo "" done
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 "Removing cargo cache" # Function to perform additional steps for installed cargo packages
cargo cache --autoclean post_install_steps()
msg_done "Done removing cargo cache" {
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 #!/usr/bin/env bash
# shellcheck disable=SC2231,SC2034,SC2181,SC2068 # shellcheck disable=SC2231,SC2034,SC2181,SC2068
# shellcheck source=shared.sh # shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh" source "${DOTFILES}/config/shared.sh"
PBB_REQUIRED_TOOLS=(git cheat) 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_GIT="https://github.com/dylanaraps/pure-bash-bible.git"
PBB_SOURCE="source: $PBB_GIT" PBB_SOURCE="source: $PBB_GIT"
PBB_SYNTAX="syntax: bash" PBB_SYNTAX="syntax: bash"
PBB_TAGS="tags: [bash]" PBB_TAGS="tags: [bash]"
PBB_TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/cheat/pbb"
PBB_TEMP_PREFIX=$(basename "$0") check_required_tools()
PBB_TEMP_DIR="$XDG_CACHE_HOME/cheat/pbb" {
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 clone_or_update_repo()
if [ ! -d "$PBB_TEMP_DIR/.git" ]; then {
msg_run "Starting to clone $PBB_GIT" if [ ! -d "$PBB_TEMP_DIR/.git" ]; then
git clone --depth 1 --single-branch -q "$PBB_GIT" "$PBB_TEMP_DIR" \ msg_run "Starting to clone $PBB_GIT"
&& msg_yay "Cloned $PBB_GIT" git clone --depth 1 --single-branch -q "$PBB_GIT" "$PBB_TEMP_DIR" \
else && msg_yay "Cloned $PBB_GIT"
# Update the repo else
msg_run "Starting to update $PBB_GIT" msg_run "Starting to update $PBB_GIT"
git -C "$PBB_TEMP_DIR" reset --hard origin/master git -C "$PBB_TEMP_DIR" reset --hard origin/master
git -C "$PBB_TEMP_DIR" pull -q \ git -C "$PBB_TEMP_DIR" pull -q \
&& msg_yay "Updated $PBB_GIT" && msg_yay "Updated $PBB_GIT"
fi fi
}
PBB_CHAPTERS=$(ls -1v "$PBB_TEMP_DIR"/manuscript/chapter*) prepare_cheat_dest()
CHEAT_DEST="$(cheat -d | grep pure-bash-bible | head -1 | awk '{print $2}')" {
local cheat_dest
cheat_dest="$(cheat -d | grep pure-bash-bible | head -1 | awk '{print $2}')"
if [ ! -d "$CHEAT_DEST" ]; then if [ ! -d "$cheat_dest" ]; then
mkdir -p "$CHEAT_DEST" 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"
fi fi
LC_ALL=C perl -pi.bak -e 's/\<\!-- CHAPTER END --\>//' "$CHEAT_FILE" echo "$cheat_dest"
rm "$CHEAT_FILE.bak" }
# add tags if the file doesn't have them process_chapters()
if [ '---' != "$(head -1 < "$CHEAT_FILE")" ]; then {
T="$PBB_SYNTAX\n$PBB_TAGS\n$PBB_SOURCE\n" local cheat_dest
echo -e "---\n$T---\n$(cat "$CHEAT_FILE")" > "$CHEAT_FILE" cheat_dest=$(prepare_cheat_dest)
fi
done 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 # Install PHP Package Manager Composer
# #
# shellcheck source="shared.sh" # 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");')" EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

View File

@@ -2,7 +2,7 @@
# Install NerdFonts # Install NerdFonts
# #
# shellcheck source="shared.sh" # shellcheck source="shared.sh"
eval "$HOME/.dotfiles/scripts/shared.sh" source "$DOTFILES/config/shared.sh"
GIT_REPO="https://github.com/ryanoasis/nerd-fonts.git" GIT_REPO="https://github.com/ryanoasis/nerd-fonts.git"
TMP_PATH="$XDG_CACHE_HOME/nerd-fonts" TMP_PATH="$XDG_CACHE_HOME/nerd-fonts"
@@ -17,28 +17,50 @@ fonts=(
SpaceMono SpaceMono
) )
if [ ! -d "$TMP_PATH" ]; then # Function to clone or update the NerdFonts repository
git clone --filter=blob:none --sparse "$GIT_REPO" "$TMP_PATH" clone_or_update_repo()
fi {
if [ ! -d "$TMP_PATH" ]; then
git clone --quiet --filter=blob:none --sparse "$GIT_REPO" "$TMP_PATH"
fi
cd "$TMP_PATH" || { cd "$TMP_PATH" || msg_err "No such folder $TMP_PATH"
msg_err "No such folder $TMP_PATH"
exit 1
} }
for ext in "${fonts[@]}"; do # Function to add fonts to sparse-checkout
# Trim spaces add_fonts_to_sparse_checkout()
ext=${ext// /} {
# Skip comments for font in "${fonts[@]}"; do
if [[ ${ext:0:1} == "#" ]]; then continue; fi # Trim spaces
font=${font// /}
# Skip comments
if [[ ${font:0:1} == "#" ]]; then continue; fi
msg_run "Adding $ext to sparse-checkout" msg_run "Adding $font to sparse-checkout"
git sparse-checkout add "patched-fonts/$ext" git sparse-checkout add "patched-fonts/$font"
echo "" echo ""
done 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 # Install fzf
# #
# shellcheck source=shared.sh # shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh" eval "$DOTFILES/config/shared.sh"
FZF_GIT="https://github.com/junegunn/fzf.git" FZF_GIT="https://github.com/junegunn/fzf.git"
FZF_PATH="${XDG_CONFIG_HOME}/fzf" FZF_PATH="${XDG_CONFIG_HOME}/fzf"
FZF_BUILD="/tmp/fzf" FZF_BUILD="/tmp/fzf"
if [ ! -d "$FZF_BUILD" ]; then main()
git clone --depth 1 "$FZF_GIT" "$FZF_BUILD" {
"$FZF_BUILD/install" \ if [ ! -d "$FZF_BUILD" ]; then
--xdg \ git clone --depth 1 "$FZF_GIT" "$FZF_BUILD"
--bin "$FZF_BUILD/install" \
else --xdg \
msg_done "fzf ($FZF_PATH/) already installed" --bin
fi msg_done "fzf installed"
else
msg_done "fzf ($FZF_PATH/) already installed"
fi
}
main "$@"

View File

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

View File

@@ -4,12 +4,14 @@
# NOTE: Experimental, wip # NOTE: Experimental, wip
# #
# shellcheck source=shared.sh # 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" 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" REPO_URL="https://github.com/AGWA/git-crypt.git"
CHECK_PATH="${XDG_BIN_HOME}/git-crypt" CHECK_PATH="${XDG_BIN_HOME}/git-crypt"
BUILD_PATH="/tmp/git-crypt" BUILD_PATH="/tmp/git-crypt"
@@ -23,5 +25,6 @@ x-have "git-crypt" || {
else else
msg_done "git-crypt ($CHECK_PATH) already installed" msg_done "git-crypt ($CHECK_PATH) already installed"
fi fi
} fi
msg_done "Done installing git-crypt" msg_done "Done installing git-crypt"

View File

@@ -2,7 +2,10 @@
# Install Go packages # Install Go packages
# #
# shellcheck source=shared.sh # 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" msg_run "Installing go packages"
@@ -33,32 +36,50 @@ packages=(
github.com/doron-cohen/antidot@latest github.com/doron-cohen/antidot@latest
) )
for pkg in "${packages[@]}"; do # Function to install go packages
# Trim spaces install_packages()
pkg=${pkg// /} {
# Skip comments for pkg in "${packages[@]}"; do
if [[ ${pkg:0:1} == "#" ]]; then continue; fi # Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_nested "Installing go package: $pkg" msg_nested "Installing go package: $pkg"
go install "$pkg" go install "$pkg"
echo "" echo ""
done 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"
} }
x-have antidot && { # Function to install completions and run actions for selected packages
antidot update \ post_install()
&& msg_ok "Updated antidot database" {
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" main()
go clean -cache -modcache {
install_packages
post_install
clear_go_cache
msg_ok "Done"
}
msg_ok "Done" main "$@"

View File

@@ -3,23 +3,71 @@
# Install neofetch from source # Install neofetch from source
# #
# shellcheck source=shared.sh # 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_REPO="https://github.com/dylanaraps/neofetch"
NEOFETCH_URL="${NEOFETCH_REPO}/archive/refs/tags/${NEOFETCH_VERSION}.tar.gz" NEOFETCH_URL="${NEOFETCH_REPO}/archive/refs/tags/${NEOFETCH_VERSION}.tar.gz"
NEOFETCH_TEMP="/tmp/neofetch" NEOFETCH_TEMP="/tmp/neofetch"
NEOFETCH_INSTALL_PREFIX="$HOME/.local" 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 LC_ALL=C
mkdir -p "$NEOFETCH_TEMP" "$NEOFETCH_INSTALL_PREFIX" 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" tar zxvf "$NEOFETCH_TEMP.tar.gz" --directory="$NEOFETCH_TEMP"
cd "$NEOFETCH_TEMP/neofetch-$NEOFETCH_VERSION" \ cd "$NEOFETCH_TEMP/neofetch-$NEOFETCH_VERSION" \
&& make PREFIX="${NEOFETCH_INSTALL_PREFIX}" install \ && make PREFIX="${NEOFETCH_INSTALL_PREFIX}" install \
&& rm -rf "$NEOFETCH_TEMP*" \ && rm -rf "$NEOFETCH_TEMP*" \
&& msg_yay "neofetch installed!" && 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. # Install npm packages globally.
# #
# shellcheck source=shared.sh # 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" 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=( packages=(
# This is a tool to check if your files consider your .editorconfig rules. # This is a tool to check if your files consider your .editorconfig rules.
@@ -18,27 +24,48 @@ packages=(
"corepack" "corepack"
) )
for pkg in "${packages[@]}"; do # Function to install npm packages
# Trim spaces install_packages()
pkg=${pkg// /} {
# Skip comments for pkg in "${packages[@]}"; do
if [[ ${pkg:0:1} == "#" ]]; then continue; fi # Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
if [[ $(npm ls -g -p "$pkg") != "" ]]; then if npm ls -g -p "$pkg" &> /dev/null; then
msg_run_done "$pkg" "already installed" msg_run_done "$pkg" "already installed"
else else
msg_run "Installing npm package:" "$pkg" msg_run "Installing npm package:" "$pkg"
npm install -g --no-fund --no-progress --no-timing "$pkg" npm install -g --no-fund --no-progress --no-timing "$pkg"
fi fi
echo ""
done
}
echo "" # Function to upgrade all global npm packages
done 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" # Function to clean npm cache
npm -g --no-progress --no-timing --no-fund outdated clean_npm_cache()
npm -g --no-timing --no-fund upgrade {
msg_run "Cleaning up npm cache"
npm cache verify
npm cache clean --force
npm cache verify
}
msg_run "Cleaning up npm cache" main()
npm cache verify {
npm cache clean --force install_packages
npm cache verify upgrade_global_packages
clean_npm_cache
msg_yay "npm package installations complete"
}
main "$@"

View File

@@ -3,11 +3,18 @@
# Install ntfy # Install ntfy
# #
# shellcheck source=shared.sh # shellcheck source=shared.sh
eval "$HOME/.dotfiles/scripts/shared.sh" eval "$DOTFILES/config/shared.sh"
set -e
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 case $(dfm check arch) in
Linux) Linux)
NTFY_ARCH="linux_$(arch)" NTFY_ARCH="linux_$(arch)"
@@ -15,21 +22,36 @@ case $(dfm check arch) in
Darwin) Darwin)
NTFY_ARCH="macOS_all" NTFY_ARCH="macOS_all"
;; ;;
*)
msg_err "Unsupported OS"
;;
esac esac
NTFY_VERSION=2.2.0 NTFY_VERSION="$(x-gh-get-latest-version binwiederhier/ntfy)"
NTFY_URL="https://github.com/binwiederhier/ntfy" NTFY_URL="https://github.com/binwiederhier/ntfy"
NTFY_DEST="/tmp/ntfy_${NTFY_VERSION}_${NTFY_ARCH}" NTFY_DEST="/tmp/ntfy_${NTFY_VERSION}_${NTFY_ARCH}"
curl -L "$NTFY_URL/releases/download/v${NTFY_VERSION}/${NTFY_DEST}.tar.gz" \ # Download and extract ntfy
> "${NTFY_DEST}.tar.gz" install_ntfy()
tar zxvf "${NTFY_DEST}.tar.gz" {
cp -a "${NTFY_DEST}/ntfy" ~/.local/bin/ntfy curl -L "$NTFY_URL/releases/download/v${NTFY_VERSION}/${NTFY_DEST}.tar.gz" -o "${NTFY_DEST}.tar.gz"
mkdir -p ~/.config/ntfy 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 # Copy config only if it does not exist
if [ ! -f "$HOME/.config/ntfy/client.yml" ]; then if [ ! -f "$HOME/.config/ntfy/client.yml" ]; then
cp "${NTFY_DEST}/client/client.yml" ~/.config/ntfy/client.yml cp "${NTFY_DEST}/client/client.yml" ~/.config/ntfy/client.yml
fi 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 # Install oh-my-bash
# #
# shellcheck source=shared.sh # 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 # Enable verbosity with VERBOSE=1
[ -f "$HOME/.bashrc" ] && mv "$HOME/.bashrc" "$HOME/.bashrc.temp" VERBOSE="${VERBOSE:-0}"
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" OSH="$HOME/.local/share/oh-my-bash"
else
msg_done "oh-my-bash ($OSH) already installed" # Function to install oh-my-bash
fi 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 # Install oh-my-posh
# #
# shellcheck source=shared.sh # 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. # Install python/pip packages.
# #
# shellcheck source=shared.sh # 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" msg "Starting to install pip packages"
x-have "python3" || { if ! command -v python3 &> /dev/null; then
msg_err "Could not find python3, something really weird is going on." && exit 1 msg_err "Could not find python3, something really weird is going on."
} exit 1
fi
msg_nested "Upgrading pip" msg_nested "Upgrading pip"
python3 -m pip install --user --upgrade pip python3 -m pip install --user --upgrade pip
@@ -18,16 +22,20 @@ packages=(
"libtmux" "libtmux"
) )
for pkg in "${packages[@]}"; do # Function to install pip packages
# Trim spaces install_packages()
pkg=${pkg// /} {
# Skip comments for pkg in "${packages[@]}"; do
if [[ ${pkg:0:1} == "#" ]]; then continue; fi # Trim spaces
pkg=${pkg// /}
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_nested "Installing pip package: $pkg" msg_nested "Installing pip package: $pkg"
python3 -m pip install --user --upgrade "$pkg" python3 -m pip install --user --upgrade "$pkg"
echo ""
echo "" done
done }
install_packages
msg_yay "Run pip package installations" msg_yay "Run pip package installations"

View File

@@ -4,29 +4,40 @@
# Ismo Vuorinen <https://github.com/ivuorinen> 2018 # 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 \ # Check if the script is running on macOS
&& msg_err "xcode-select could not be found, skipping" \ if [ "$(uname)" != "Darwin" ]; then
&& exit 0 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 # Ask for the administrator password upfront
sudo -v sudo -v
# Keep-alive: update existing `sudo` time stamp until `settler` has finished # Keep-alive: update existing `sudo` time stamp until the script has finished
while true; do keep_alive_sudo()
sudo -n true {
sleep 60 while true; do
kill -0 "$$" || exit sudo -n true
done 2> /dev/null & sleep 60
kill -0 "$$" || exit
done 2> /dev/null &
}
XCODE_TOOLS_PATH=$(xcode-select -p) XCODE_TOOLS_PATH=$(xcode-select -p)
XCODE_SWIFT_PATH="$XCODE_TOOLS_PATH/usr/bin/swift" XCODE_SWIFT_PATH="$XCODE_TOOLS_PATH/usr/bin/swift"
# Modified from https://unix.stackexchange.com/a/408305 # Function to prompt for XCode CLI Tools installation
if [ -a "$XCODE_SWIFT_PATH" ]; then prompt_xcode_install()
echo "You have swift from xcode-select. Continuing..." {
else
XCODE_MESSAGE="$( XCODE_MESSAGE="$(
osascript -e \ osascript -e \
'tell app "System Events" to display dialog "Please click install when Command Line Developer Tools appears"' 'tell app "System Events" to display dialog "Please click install when Command Line Developer Tools appears"'
@@ -36,11 +47,25 @@ else
xcode-select --install xcode-select --install
else else
echo "You have cancelled the installation, please rerun the installer." echo "You have cancelled the installation, please rerun the installer."
exit exit 1
fi fi
fi }
until [ -f "$XCODE_SWIFT_PATH" ]; do # Main function
echo -n "." main()
sleep 1 {
done 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 # Install z
# #
# shellcheck source=shared.sh # 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_GIT_PATH="https://github.com/rupa/z.git"
Z_BIN_PATH="$XDG_BIN_HOME/z" Z_BIN_PATH="$XDG_BIN_HOME/z"
if [ ! -d "$Z_BIN_PATH" ]; then # Function to clone the z repository
git clone "$Z_GIT_PATH" "$Z_BIN_PATH" clone_z_repo()
else {
msg_done "z ($Z_BIN_PATH/) already installed" local git_path=$1
fi 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 [ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0
# shellcheck source=shared.sh # 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:" 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 # Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true 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 defaults write com.apple.LaunchServices LSQuarantine -bool false
# Disable Resume system-wide # Disable Resume system-wide
@@ -79,10 +79,10 @@ defaults write NSGlobalDomain NSDisableAutomaticTermination -bool true
# in the login window # in the login window
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName 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 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 defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
############################################################################### ###############################################################################
@@ -94,7 +94,7 @@ msg_nested "Setting SSD-specific tweaks"
# Disable hibernation (speeds up entering sleep mode) # Disable hibernation (speeds up entering sleep mode)
sudo pmset -a hibernatemode 0 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 sudo pmset -a sms 0
############################################################################### ###############################################################################
@@ -117,7 +117,7 @@ defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Min" 80
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3 defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Set language and text formats # 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`. # `Inches`, `en_GB` with `en_US`, and `true` with `false`.
defaults write NSGlobalDomain AppleLanguages -array "en" defaults write NSGlobalDomain AppleLanguages -array "en"
defaults write NSGlobalDomain AppleLocale -string "en_GB@currency=EUR" defaults write NSGlobalDomain AppleLocale -string "en_GB@currency=EUR"
@@ -197,7 +197,7 @@ defaults write com.apple.finder WarnOnEmptyTrash -bool false
# chflags nohidden /Users # chflags nohidden /Users
# Expand the following File Info panes: # 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 \ defaults write com.apple.finder FXInfoPanesExpanded -dict \
General -bool true \ General -bool true \
OpenWith -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 defaults write com.apple.dock show-process-indicators -bool true
# Wipe all (default) app icons from the Dock # 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. # the Dock to launch apps.
# defaults write com.apple.dock persistent-apps -array "" # defaults write com.apple.dock persistent-apps -array ""
# Disable Dashboard # Disable Dashboard
defaults write com.apple.dashboard mcx-disabled -bool true 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 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 defaults write com.apple.dock mru-spaces -bool false
# Make Dock icons of hidden applications translucent # 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" msg_nested "Settings for Safari & WebKit"
# Enable Safaris debug menu # Enable Safari's debug menu
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
# Enable the Develop menu and the Web Inspector in Safari # Enable the Develop menu and the Web Inspector in Safari
@@ -268,7 +268,7 @@ defaults write com.apple.Safari \
com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled \ com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled \
-bool true -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 defaults write com.googlecode.iterm2 PromptOnQuit -bool false
# Use iTerm2 preferences from the .dotfiles folder. # Use iTerm2 preferences from the .dotfiles folder.
defaults write com.googlecode.iterm2 PrefsCustomFolder \ defaults write com.googlecode.iterm2 PrefsCustomFolder \
@@ -315,7 +315,7 @@ defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
msg_nested "Settings for Messages" 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 \ defaults write com.apple.messageshelper.MessageController \
SOInputLineSettings \ SOInputLineSettings \
-dict-add "automaticQuoteSubstitutionEnabled" \ -dict-add "automaticQuoteSubstitutionEnabled" \
@@ -335,7 +335,7 @@ msg_nested "Restarting applications to apply changes"
for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \ for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
"Dock" "Finder" "Mail" "Messages" "Safari" "SizeUp" "SystemUIServer" \ "Dock" "Finder" "Mail" "Messages" "Safari" "SizeUp" "SystemUIServer" \
"Terminal" "Transmission" "Twitter" "iCal"; do "Terminal" "Transmission" "iCal"; do
killall "${app}" > /dev/null 2>&1 killall "${app}" > /dev/null 2>&1
done done

View File

@@ -6,164 +6,14 @@
# Helper env variables. Use like this: VERBOSE=1 ./script.sh # Helper env variables. Use like this: VERBOSE=1 ./script.sh
: "${VERBOSE:=0}" : "${VERBOSE:=0}"
# Modified from https://stackoverflow.com/a/28776166 # 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
[[ -n $ZSH_VERSION && $ZSH_EVAL_CONTEXT =~ :file$ ]] \ [ -z "$SHARED_SCRIPTS_SOURCED" ] && {
|| [[ -n $BASH_VERSION ]] && (return 0 2> /dev/null)
) && sourced=1 || sourced=0
eval "$HOME/.dotfiles/config/shared.sh" source "${DOTFILES}/config/shared.sh"
msgr done "(!) shared.sh not sourced"
DOTFILES_CURRENT_SHELL=$(ps -p $$ -oargs=) # Set variable that checks if the shared.sh script has been sourced only once
export DOTFILES_CURRENT_SHELL # shellcheck disable=SC2034
export SHARED_SCRIPTS_SOURCED=1
# 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
} }