feat(asdf): drop asdf-plugin-manager, use dotbot-asdf

This commit is contained in:
2024-12-28 16:58:31 +02:00
parent 193fae662e
commit eb91a43bbd
11 changed files with 338 additions and 195 deletions

View File

@@ -26,6 +26,8 @@ indent_size = 1
indent_style = tab
[{local/bin/*,**/*.sh,**/zshrc,config/*,scripts/*}]
indent_size = 2
tab_width = 2
shell_variant = bash # --language-variant
binary_next_line = true
switch_case_indent = true # --case-indent
@@ -37,5 +39,5 @@ function_next_line = true # --func-next-line
# such as "shfmt -l -w .". When formatting files directly,
# like "shfmt -w third_party/foo.sh" or "shfmt --filename=third_party/foo.sh",
# the ignore logic is applied only when the --apply-ignore flag is given.
[{tools/**,local/bin/asdf/**,config/cheat/cheatsheets/**}]
[{tools/**,local/bin/asdf/**,config/cheat/cheatsheets/**,config/tmux/plugins/**}]
ignore = true

2
.gitignore vendored
View File

@@ -29,4 +29,4 @@ config/gnupg/private-keys-v1.d
config/nvim/spell/*
!config/nvim/spell/.gitkeep
antidote_plugins.zsh
*.bak

3
.gitmodules vendored
View File

@@ -64,3 +64,6 @@
path = tools/antidote
url = https://github.com/mattmc3/antidote.git
shallow = true
[submodule "dotbot-asdf"]
path = tools/dotbot-asdf
url = https://github.com/sobolevn/dotbot-asdf

View File

@@ -9,6 +9,8 @@ git submodule add --name dotbot-include \
-f https://gitlab.com/gnfzdz/dotbot-include.git tools/dotbot-include
git submodule add --name dotbot-pip \
-f https://github.com/sobolevn/dotbot-pip.git tools/dotbot-pip
git submodule add --name dotbot-asdf \
-f https://github.com/sobolevn/dotbot-asdf tools/dotbot-asdf
# other repos
git submodule add --name cheat-community \
@@ -19,8 +21,7 @@ git submodule add --name asdf \
-f https://github.com/asdf-vm/asdf.git local/bin/asdf
git submodule add --name antidote \
--depth 1 \
-f https://github.com/mattmc3/antidote.git tools/antidote \
-f https://github.com/mattmc3/antidote.git tools/antidote
# tmux plugin manager and plugins
git submodule add --name tmux/tmux-continuum \

View File

@@ -1,11 +1,9 @@
asdf-plugin-manager 1.4.0
golang 1.23.4
rust 1.82.0
rust 1.83.0
direnv 2.35.0
fd 10.2.0
1password-cli 2.30.3
age 1.2.1
bottom 0.10.2
dotenv-linter 3.3.0
editorconfig-checker 2.8.0
github-cli 2.64.0
@@ -15,7 +13,7 @@ pre-commit 4.0.1
ripgrep 14.1.1
shellcheck 0.10.0
shfmt 3.10.0
terragrunt 0.68.8
terragrunt 0.71.1
tf-summarize 0.3.14
yamllint 1.35.1
yq 4.44.6

145
config/zsh/completion/_dfm Normal file
View File

@@ -0,0 +1,145 @@
#compdef dfm
_dfm() {
local -a commands sections
sections=(
'install:Installation commands'
'asdf:ASDF version manager commands'
'brew:Homebrew package manager commands'
'check:System check commands'
'dotfiles:Dotfiles management commands'
'docs:Documentation commands'
'helpers:Helper utilities'
'tests:Test commands'
)
_arguments -C \
"1: :->sections" \
"*::arg:->args"
case "$state" in
sections)
_describe 'sections' sections
;;
args)
case $line[1] in
install)
local -a install_cmds
install_cmds=(
'all:Install everything in correct order'
'cargo:Install rust/cargo packages'
'cheat-databases:Install cheat external cheatsheet databases'
'composer:Install composer'
'dotenv:Install dotenv-linter'
'fonts:Install programming fonts'
'gh:Install GitHub CLI Extensions'
'go:Install Go Packages'
'imagick:Install ImageMagick CLI'
'starship:Install starship.rs'
'macos:Setup nice macOS defaults'
'neofetch:Install neofetch'
'nvm:Install Node Version Manager'
'nvm-latest:Install latest LTS node'
'npm:Install NPM Packages'
'ntfy:Install ntfy'
'ohmybash:Install oh-my-bash'
'pip:Install pip/python packages'
'z:Install z'
)
_describe 'install commands' install_cmds
;;
asdf)
local -a asdf_cmds
asdf_cmds=(
'current:Show current versions'
'global:Show global versions'
'installed:Show installed versions'
'plugins-update:Update all plugins'
'plugins-install:Install plugins from configuration'
'plugins-remove:Remove installed plugins'
'reset:Reset plugins'
'fix-tool-versions:Remove uninstalled plugins from .tool-versions'
'versions:Show versions'
'where:Show where'
'which:Show which'
)
_describe 'asdf commands' asdf_cmds
;;
brew)
local -a brew_cmds
brew_cmds=(
'install:Install items from Brewfile'
'update:Update and upgrade packages'
'updatebundle:Update Brewfile with descriptions'
'autoupdate:Setup brew auto-update'
'leaves:List brew leaves'
'clean:Clean up packages'
'untracked:List untracked packages'
)
_describe 'brew commands' brew_cmds
;;
check)
local -a check_cmds
check_cmds=(
'arch:Check architecture'
'host:Check hostname'
)
_describe 'check commands' check_cmds
;;
dotfiles)
local -a dotfiles_cmds
dotfiles_cmds=(
'fmt:Run all formatters'
'yamlfmt:Run yamlfmt'
'shfmt:Run shfmt'
'reset_all:Reset everything'
'reset_nvim:Reset neovim'
)
_describe 'dotfiles commands' dotfiles_cmds
;;
docs)
local -a docs_cmds
docs_cmds=(
'all:Update all documentation'
'tmux:Update tmux documentation'
'nvim:Update nvim documentation'
'wezterm:Update wezterm documentation'
)
_describe 'docs commands' docs_cmds
;;
helpers)
local -a helpers_cmds
helpers_cmds=(
'aliases:Show aliases'
'colors:Show colors'
'env:Show environment variables'
'functions:Show functions'
'nvim:Show nvim keybindings'
'path:Show PATH'
'tmux:Show tmux keybindings'
'wezterm:Show wezterm keybindings'
)
_describe 'helper commands' helpers_cmds
;;
tests)
local -a test_cmds
test_cmds=(
'msg:List log functions'
'params:List parameters'
)
_describe 'test commands' test_cmds
;;
esac
;;
esac
}
_dfm "$@"

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env bash
set -e
CONFIG="install.conf.yaml"
@@ -16,6 +15,7 @@ git submodule update --init --recursive "${DOTBOT_DIR}"
"${DOTBOT_BIN_PATH}" \
-d "${BASEDIR}" \
--plugin-dir=tools/dotbot-asdf \
--plugin-dir=tools/dotbot-brew \
--plugin-dir=tools/dotbot-include \
--plugin-dir=tools/dotbot-pip \
@@ -29,6 +29,7 @@ if [ "${DOTBOT_HOST}" != "" ]; then
echo "(!) Found $DOTBOT_HOST_CONFIG" &&
"$DOTBOT_BIN_PATH" \
-d "$BASEDIR" \
--plugin-dir=tools/dotbot-asdf \
--plugin-dir=tools/dotbot-brew \
--plugin-dir=tools/dotbot-include \
--plugin-dir=tools/dotbot-pip \

View File

@@ -1,5 +1,6 @@
---
- include: 'tools/dotbot-defaults.yaml'
- clean:
~/:
~/.config:
@@ -8,6 +9,7 @@
recursive: true
~/.ssh:
recursive: true
- create:
~/.cache:
~/.cache/git:
@@ -25,6 +27,7 @@
~/.ssh/local.d:
mode: 0700
~/Code:
- link:
~/:
force: true
@@ -53,10 +56,54 @@
glob: true
mode: 0600
path: ssh/*
- shell:
- bash add-submodules.sh || true
- git submodule update --init --recursive --force
- asdf:
- plugin: 1password-cli
url: https://github.com/NeoHsu/asdf-1password-cli.git
- plugin: age
url: https://github.com/threkk/asdf-age.git
- plugin: direnv
url: https://github.com/asdf-community/asdf-direnv.git
- plugin: dotenv-linter
url: https://github.com/wesleimp/asdf-dotenv-linter.git
- plugin: editorconfig-checker
url: https://github.com/gabitchov/asdf-editorconfig-checker.git
- plugin: fd
url: https://gitlab.com/wt0f/asdf-fd.git
- plugin: github-cli
url: https://github.com/bartlomiejdanek/asdf-github-cli.git
- plugin: golang
url: https://github.com/asdf-community/asdf-golang.git
- plugin: hadolint
url: https://github.com/devlincashman/asdf-hadolint.git
- plugin: kubectl
url: https://github.com/asdf-community/asdf-kubectl.git
- plugin: pre-commit
url: https://github.com/jonathanmorley/asdf-pre-commit.git
- plugin: ripgrep
url: https://gitlab.com/wt0f/asdf-ripgrep.git
- plugin: rust
url: https://github.com/code-lever/asdf-rust.git
- plugin: shellcheck
url: https://github.com/luizm/asdf-shellcheck.git
- plugin: shfmt
url: https://github.com/luizm/asdf-shfmt.git
- plugin: terragrunt
url: https://github.com/ohmer/asdf-terragrunt.git
- plugin: tf-summarize
url: https://github.com/adamcrews/asdf-tf-summarize.git
- plugin: yamllint
url: https://github.com/ericcornelissen/asdf-yamllint.git
- plugin: yq
url: https://github.com/sudermanjr/asdf-yq.git
- shell:
- bash local/bin/dfm install all
- pipx:
file: tools/requirements-pipx.txt
stdout: true

View File

@@ -73,6 +73,25 @@ source "$DOTFILES/config/shared.sh"
source "${DOTFILES}/local/bin/msgr"
# -- Menu builder -- #
menu_builder()
{
local title=$1
local commands=("${@:2}")
local width=60
printf "\n%s\n" "$(printf '%.s─' $(seq 1 $width))"
printf "%-${width}s\n" " $title"
printf "%s\n" "$(printf '%.s─' $(seq 1 $width))"
for cmd in "${commands[@]}"; do
local name=${cmd%%:*}
local desc=${cmd#*:}
printf " %-20s %s\n" "$name" "$desc"
done
# printf "\n"
}
menu_section()
{
LINE=$(printf '%-18s [ %-15s ]\n' "$1" "$2")
@@ -374,10 +393,11 @@ section_asdf()
"current:Show asdf current versions"
"global:Show asdf global versions"
"installed:Show asdf installed versions"
"local:Show asdf local versions"
"plugins-add:Add and update direnv and asdf-plugin-manager, and all other plugins"
"plugins-update:Update all asdf plugins"
"plugins-install:Install plugins from configuration"
"plugins-remove:Remove installed plugins"
"reset:Reset asdf plugins"
"fix-tool-versions:Remove uninstalled plugins from .tool-versions"
"versions:Show asdf versions"
"where:Show asdf where"
"which:Show asdf which"
@@ -385,120 +405,159 @@ section_asdf()
case "$1" in
plugins-update)
APM_BIN="$(asdf where asdf-plugin-manager)/bin/asdf-plugin-manager"
msgr run "Updating all asdf plugins"
$APM_BIN update-all
$APM_BIN export > "$ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME"
asdf plugin update --all
msgr run_done "Updated all plugins"
;;
plugins-add)
X_GH_BIN="$DOTFILES/local/bin/x-gh-get-latest-version"
LATEST_APM="$($X_GH_BIN asdf-community/asdf-plugin-manager | sed 's/^v//')"
LATEST_DIRENV="$($X_GH_BIN asdf-community/asdf-direnv)"
PLUGIN_VERSIONS="$DOTFILES/config/asdf/plugin-versions"
APM_BIN="$HOME/.local/bin/asdf/shims/asdf-plugin-manager"
msgr run "Adding and updating direnv and asdf-plugin-manager"
asdf plugin add direnv https://github.com/asdf-community/asdf-direnv.git
asdf global direnv "$LATEST_DIRENV"
asdf install direnv "$LATEST_DIRENV"
plugins-install)
msgr run "Installing plugins from configuration"
asdf plugin add asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git
asdf global asdf-plugin-manager "$LATEST_APM"
asdf install asdf-plugin-manager "$LATEST_APM"
asdf reshim
msgr run_done "direnv and asdf-plugin-manager added and updated"
# Asennetaan ensin direnv jos sitä ei ole
if ! asdf plugin list | grep -q "^direnv$"; then
msgr nested "Installing direnv plugin"
asdf plugin add direnv https://github.com/asdf-community/asdf-direnv.git
msgr run "Reset plugin-versions file to the original using git"
if git ls-files --error-unmatch "$PLUGIN_VERSIONS" > /dev/null 2>&1; then
git checkout -- "$PLUGIN_VERSIONS"
# Asennetaan direnv latest
local latest_direnv
latest_direnv=$(asdf latest direnv)
asdf install direnv "$latest_direnv"
asdf global direnv "$latest_direnv"
fi
msgr run_done "Reset plugin-versions file"
msgr run "Adding all plugins with asdf-plugin-manager"
"$APM_BIN" add-all
msgr run_done "Added all plugins with asdf-plugin-manager"
# Tarkistetaan että kaikki konfiguroidut pluginit on asennettu
local installed_plugins
installed_plugins=$(asdf plugin list)
msgr run "Install all plugins"
PLUGINS=$($APM_BIN list | awk -F ' ' '{print $1}' | sort)
for P in $PLUGINS; do
msgr run "Installing $P"
asdf install "$P" latest
asdf global "$P" latest
done
while IFS= read -r line; do
# Ohita tyhjät rivit ja kommentit
[[ -z "$line" || "$line" =~ ^# ]] && continue
local plugin
plugin=$(echo "$line" | awk '{print $1}')
msgr run_done "Installed all plugins"
# Ohita direnv, käsiteltiin jo
[[ "$plugin" == "direnv" ]] && continue
msgr run "Reshimming"
asdf reshim
msgr run_done "Reshimmed"
if ! echo "$installed_plugins" | grep -q "^${plugin}$"; then
msgr nested "Installing $plugin plugin"
asdf plugin add "$plugin"
fi
done < "$DOTFILES/base/tool-versions"
msgr run_done "All plugins installed"
;;
plugins-remove)
PLUGIN_VERSIONS="$DOTFILES/config/asdf/plugin-versions"
msgr run "Remove installed plugins"
INSTALLED_ASDF_PLUGINS=$(asdf list | grep -vE "direnv|asdf-plugin-manager" | grep -v "^ ")
for P in $INSTALLED_ASDF_PLUGINS; do
asdf plugin remove "$P"
msgr nested_done "Removed $P"
done
local installed_plugins
installed_plugins=$(asdf plugin list | grep -v "^direnv$")
msgr run "Reset plugin-versions file to the original using git"
if git ls-files --error-unmatch "$PLUGIN_VERSIONS" > /dev/null 2>&1; then
git checkout -- "$PLUGIN_VERSIONS"
fi
msgr run_done "Reset plugin-versions file"
for plugin in $installed_plugins; do
msgr nested "Removing $plugin"
asdf plugin remove "$plugin"
done
msgr run_done "Remove plugins done!"
;;
reset)
APM_BIN="$(asdf where asdf-plugin-manager)/bin/asdf-plugin-manager"
msgr run "Get currently installed plugins, remove those that are not defined"
reset)
msgr run "Resetting asdf environment"
$0 asdf plugins-remove
$0 asdf plugins-add
$0 asdf fixtoolversions
$0 asdf plugins-install
asdf reshim
msgr yay "Reset asdf plugins done!"
;;
fixtoolversions)
ASDF_TOOL_VERSIONS_FILE="$DOTFILES/base/tool-versions"
ASDF_TOOL_FILE_PLUGINS=$(awk '{print $1 " " $2}' "$ASDF_TOOL_VERSIONS_FILE")
APM_BIN="$(asdf where asdf-plugin-manager)/bin/asdf-plugin-manager"
msgr run "Loading $ASDF_TOOL_VERSIONS_FILE and collecting installed"
ASDF_PLUGINS_DEFINED=$($APM_BIN list | awk -F ' ' '{print $1}')
fix-tool-versions)
local tool_versions_file="$DOTFILES/base/tool-versions"
local temp_file
temp_file=$(mktemp)
echo "$ASDF_TOOL_FILE_PLUGINS" | \
grep -Fxv -f <(echo "$ASDF_PLUGINS_DEFINED") > tmp && \
mv tmp "$ASDF_TOOL_VERSIONS_FILE"
msgr run "Fixing tool-versions file"
msgr run_done "Fixed $ASDF_TOOL_VERSIONS_FILE"
# Tarkista että tiedosto on olemassa
if [[ ! -f "$tool_versions_file" ]]; then
msgr error "tool-versions file not found: $tool_versions_file"
rm -f "$temp_file"
return 1
fi
# Tarkista että asdf on asennettu
if ! command -v asdf > /dev/null; then
msgr error "asdf not found"
rm -f "$temp_file"
return 1
fi
# Lue asennetut pluginit
msgr nested "Reading installed plugins"
local installed_plugins
installed_plugins=$(asdf plugin list | sort)
# Käy läpi tool-versions tiedosto ja säilytä vain asennetut pluginit
msgr nested "Updating tool-versions file"
while IFS= read -r line; do
# Säilytä kommentit ja tyhjät rivit
if [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]]; then
echo "$line" >> "$temp_file"
continue
fi
local plugin
plugin=$(echo "$line" | awk '{print $1}')
if echo "$installed_plugins" | grep -q "^${plugin}$"; then
echo "$line" >> "$temp_file"
else
msgr nested "Removing $plugin - not installed"
fi
done < "$tool_versions_file"
# Tarkista että temp-tiedosto ei ole tyhjä tai sisällä vain kommentteja
if [[ ! -s "$temp_file" ]] || ! grep -v '^[[:space:]]*#' "$temp_file" | grep -q .; then
msgr error "Generated file is empty or contains only comments, keeping original"
rm -f "$temp_file"
return 1
fi
# Varmuuskopioi alkuperäinen
cp "$tool_versions_file" "${tool_versions_file}.bak"
# Siirrä uusi versio paikalleen
mv "$temp_file" "$tool_versions_file"
msgr run_done "Updated $tool_versions_file"
msgr nested "Backup saved as ${tool_versions_file}.bak"
return 0
;;
current)
asdf current
;;
global)
asdf global
;;
installed)
asdf list
;;
local)
asdf local
;;
versions)
asdf list all
;;
where)
asdf where
;;
which)
asdf which
;;
*) menu_usage "$USAGE_PREFIX" "${MENU[@]}" ;;
*) menu_builder "$USAGE_PREFIX" "${MENU[@]}" ;;
esac
}

View File

@@ -7,120 +7,6 @@
# Usage: ./install-asdf.sh [both|install|update|add_plugins]
# Author: Ismo Vuorinen <https://github.com/ivuorinen>
# License: MIT
#
source "${DOTFILES}/config/shared.sh"
export ASDF_DIR="${XDG_BIN_HOME}/asdf"
export PATH="${ASDF_DIR}/bin:$PATH"
# If ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME is not set, set it
if [ -z "${ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME}" ]; then
export ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME="${XDG_CONFIG_HOME}/asdf/plugin-versions"
fi
msg "Sourcing asdf in your shell"
. "$ASDF_DIR/asdf.sh"
ASDF_INSTALLABLES=(
"1password-cli:github.com/NeoHsu/asdf-1password-cli.git"
"age:github.com/threkk/asdf-age.git"
"bottom:github.com/carbonteq/asdf-btm.git"
"direnv:github.com/asdf-community/asdf-direnv.git"
"dotenv-linter:github.com/wesleimp/asdf-dotenv-linter.git"
"editorconfig-checker:github.com/gabitchov/asdf-editorconfig-checker.git"
"fd:gitlab.com/wt0f/asdf-fd.git"
"github-cli:github.com/bartlomiejdanek/asdf-github-cli.git"
"golang:github.com/asdf-community/asdf-golang.git"
"hadolint:github.com/devlincashman/asdf-hadolint.git"
"kubectl:github.com/asdf-community/asdf-kubectl.git"
"pre-commit:github.com/jonathanmorley/asdf-pre-commit.git"
"ripgrep:gitlab.com/wt0f/asdf-ripgrep.git"
"rust:github.com/code-lever/asdf-rust.git"
"shellcheck:github.com/luizm/asdf-shellcheck.git"
"shfmt:github.com/luizm/asdf-shfmt.git"
"terragrunt:github.com/ohmer/asdf-terragrunt.git"
"tf-summarize:github.com/adamcrews/asdf-tf-summarize.git"
"yamllint:github.com/ericcornelissen/asdf-yamllint.git"
"yq:github.com/sudermanjr/asdf-yq.git"
)
# Function to update asdf and plugins
update_asdf()
{
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-manager export > "${ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME}"
asdf install
return 0
}
update_asdf_commands()
{
msg "Updating asdf commands using asdf-plugin-manager"
asdf-plugin-manager update-all
return 0
}
# Function to install asdf plugins
install_asdf_plugins()
{
msg "Installing asdf plugins"
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}"
done
msg "Exporting asdf plugin versions"
asdf-plugin-manager export > "${ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME}"
return 0
}
reshim()
{
msg "Reshim asdf"
asdf reshim
return 0
}
# create usage function
usage()
{
echo "Usage: $0 [both|install|add_plugins|update]"
exit 1
}
main()
{
case $1 in
"both")
install_asdf_plugins
update_asdf
reshim
;;
"update")
update_asdf_commands
reshim
;;
"install")
update_asdf
reshim
;;
"add_plugins")
install_asdf_plugins
reshim
;;
*)
usage
;;
esac
}
main "$@"
msgr warn "The asdf plugins should be installed with dotbot, and 'dfm asdf'."
exit 0

1
tools/dotbot-asdf Submodule

Submodule tools/dotbot-asdf added at 1ff44a2848