mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-03-07 06:02:09 +00:00
dfm: rewrote the usage menu generation
This commit is contained in:
@@ -7,25 +7,3 @@ indent_size = 2
|
|||||||
indent_style = space
|
indent_style = space
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[*.lua]
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.yaml]
|
|
||||||
indent_size = 2
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.yml]
|
|
||||||
indent_size = 2
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.sh]
|
|
||||||
indent_size = 2
|
|
||||||
indent_style = space
|
|
||||||
insert_final_newline = true
|
|
||||||
shell_variant = bash # --language-variant
|
|
||||||
binary_next_line = true
|
|
||||||
switch_case_indent = true # --case-indent
|
|
||||||
space_redirects = false
|
|
||||||
keep_padding = false
|
|
||||||
function_next_line = true # --func-next-line
|
|
||||||
|
|||||||
132
local/bin/dfm
132
local/bin/dfm
@@ -24,6 +24,22 @@ function section_install
|
|||||||
{
|
{
|
||||||
USAGE_PREFIX="$SCRIPT install"
|
USAGE_PREFIX="$SCRIPT install"
|
||||||
|
|
||||||
|
MENU=(
|
||||||
|
"all:Installs macos defaults, antigen, starship, brew, nvm, npm packages and others"
|
||||||
|
"antigen:Updates the antigen.zsh file"
|
||||||
|
"composer:Install composer"
|
||||||
|
"dotenv:Install dotenv-linter"
|
||||||
|
"gh:Install GitHub CLI Extensions"
|
||||||
|
"go:Install Go Packages"
|
||||||
|
"imagick:Install ImageMagick CLI"
|
||||||
|
"starship:Install starship.rs"
|
||||||
|
"macos:Setup nice macOS defaults"
|
||||||
|
"nvm:Install Node Version Manager (nvm)"
|
||||||
|
"npm:Install NPM Packages"
|
||||||
|
"ntfy:Install ntfy"
|
||||||
|
"z:Install z"
|
||||||
|
)
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
all)
|
all)
|
||||||
$0 install macos
|
$0 install macos
|
||||||
@@ -42,71 +58,58 @@ function section_install
|
|||||||
;;
|
;;
|
||||||
antigen)
|
antigen)
|
||||||
curl -L git.io/antigen > "$DOTFILES/local/bin/antigen.zsh" \
|
curl -L git.io/antigen > "$DOTFILES/local/bin/antigen.zsh" \
|
||||||
&& msg_done "🎉 New antigen installed!"
|
&& msg_yay "New antigen installed!"
|
||||||
;;
|
;;
|
||||||
composer)
|
composer)
|
||||||
bash "$DOTFILES/scripts/install-composer.sh" \
|
bash "$DOTFILES/scripts/install-composer.sh" \
|
||||||
&& msg_done "🎉 composer installed!"
|
&& msg_yay "composer installed!"
|
||||||
;;
|
;;
|
||||||
dotenv)
|
dotenv)
|
||||||
curl -sSfL \
|
curl -sSfL \
|
||||||
https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh \
|
https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh \
|
||||||
| sh -s -- -b "$XDG_BIN_HOME" \
|
| sh -s -- -b "$XDG_BIN_HOME" \
|
||||||
&& msg_done "🎉 dotenv-linter installed!"
|
&& msg_yay "dotenv-linter installed!"
|
||||||
;;
|
;;
|
||||||
gh)
|
gh)
|
||||||
bash "$DOTFILES/scripts/install-gh-extensions.sh" \
|
bash "$DOTFILES/scripts/install-gh-extensions.sh" \
|
||||||
&& msg_done "🎉 github cli extensions installed!"
|
&& msg_yay "github cli extensions installed!"
|
||||||
;;
|
;;
|
||||||
go)
|
go)
|
||||||
bash "$DOTFILES/scripts/install-go-packages.sh" \
|
bash "$DOTFILES/scripts/install-go-packages.sh" \
|
||||||
&& msg_done "🎉 go packages installed!"
|
&& msg_yay "go packages installed!"
|
||||||
;;
|
;;
|
||||||
imagick)
|
imagick)
|
||||||
wget https://imagemagick.org/archive/binaries/magick > "$XDG_BIN_HOME/magick" \
|
wget https://imagemagick.org/archive/binaries/magick > "$XDG_BIN_HOME/magick" \
|
||||||
&& msg_done "🎉 imagick installed!"
|
&& msg_yay "imagick installed!"
|
||||||
;;
|
;;
|
||||||
starship)
|
starship)
|
||||||
curl -sS https://starship.rs/install.sh | sh -s -- --bin-dir ~/.local/bin \
|
curl -sS https://starship.rs/install.sh | sh -s -- --bin-dir ~/.local/bin \
|
||||||
&& msg_done "🎉 starship installed!"
|
&& msg_yay "starship installed!"
|
||||||
;;
|
;;
|
||||||
macos)
|
macos)
|
||||||
bash "$DOTFILES/scripts/set-macos-defaults.sh" \
|
bash "$DOTFILES/scripts/set-macos-defaults.sh" \
|
||||||
&& msg_done "🎉 Brewfile defined apps has been installed!"
|
&& msg_yay "Brewfile defined apps has been installed!"
|
||||||
;;
|
;;
|
||||||
nvm)
|
nvm)
|
||||||
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION_NVM/install.sh" | bash \
|
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION_NVM/install.sh" | bash \
|
||||||
&& nvm install --lts --latest-npm --default \
|
&& nvm install --lts --latest-npm --default \
|
||||||
&& git checkout "$HOME/.zshrc" \
|
&& git checkout "$HOME/.zshrc" \
|
||||||
&& msg_done "🎉 nvm installed!"
|
&& msg_yay "nvm installed!"
|
||||||
;;
|
;;
|
||||||
npm)
|
npm)
|
||||||
bash "$DOTFILES/scripts/install-npm-packages.sh" \
|
bash "$DOTFILES/scripts/install-npm-packages.sh" \
|
||||||
&& msg_done "🎉 NPM Packages have been installed!"
|
&& msg_yay "NPM Packages have been installed!"
|
||||||
;;
|
;;
|
||||||
ntfy)
|
ntfy)
|
||||||
bash "$DOTFILES/scripts/install-ntfy.sh" \
|
bash "$DOTFILES/scripts/install-ntfy.sh" \
|
||||||
&& msg_done "🎉 ntfy installed!"
|
&& msg_yay "ntfy installed!"
|
||||||
;;
|
;;
|
||||||
z)
|
z)
|
||||||
bash "$DOTFILES/scripts/install-z.sh" \
|
bash "$DOTFILES/scripts/install-z.sh" \
|
||||||
&& msg_done "🎉 z has been installed!"
|
&& msg_yay "z has been installed!"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
menu_section "$USAGE_PREFIX" "all | antigen | composer | dotenv | gh | go | imagick | starship | macos | nvm | npm"
|
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
|
||||||
menu_item "all" "Installs macos defaults, antigen, starship, brew, nvm, npm packages and others"
|
|
||||||
menu_item "antigen" "Updates the antigen.zsh file"
|
|
||||||
menu_item "composer" "Install composer"
|
|
||||||
menu_item "dotenv" "Install dotenv-linter"
|
|
||||||
menu_item "gh" "Install GitHub CLI Extensions"
|
|
||||||
menu_item "go" "Install Go Packages"
|
|
||||||
menu_item "imagick" "Install ImageMagick CLI"
|
|
||||||
menu_item "starship" "Install starship.rs"
|
|
||||||
menu_item "macos" "Setup nice macOS defaults"
|
|
||||||
menu_item "nvm" "Install Node Version Manager (nvm)"
|
|
||||||
menu_item "npm" "Install NPM Packages"
|
|
||||||
menu_item "ntfy" "Install ntfy"
|
|
||||||
menu_item "z" "Install z"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -115,34 +118,37 @@ function section_brew
|
|||||||
{
|
{
|
||||||
USAGE_PREFIX="$SCRIPT brew"
|
USAGE_PREFIX="$SCRIPT brew"
|
||||||
|
|
||||||
|
MENU=(
|
||||||
|
"install:Installs items defined in Brewfile"
|
||||||
|
"update:Updates and upgrades brew packages"
|
||||||
|
"updatebundle:Updates Brewfile with descriptions"
|
||||||
|
"autoupdate:Setups brew auto-update and runs it immediately"
|
||||||
|
)
|
||||||
|
|
||||||
if ! command -v brew &> /dev/null; then
|
if ! command -v brew &> /dev/null; then
|
||||||
menu_section "$USAGE_PREFIX" "brew not available on this system"
|
menu_section "$USAGE_PREFIX" "brew not available on this system"
|
||||||
else
|
else
|
||||||
case "$1" in
|
case "$1" in
|
||||||
install)
|
install)
|
||||||
brew bundle install --file="$BREWFILE" && msg_done "🎉 Done!"
|
brew bundle install --file="$BREWFILE" && msg_yay "Done!"
|
||||||
;;
|
;;
|
||||||
update)
|
update)
|
||||||
brew update && brew outdated && brew upgrade && brew cleanup
|
brew update && brew outdated && brew upgrade && brew cleanup
|
||||||
msg_done "🎉 Done!"
|
msg_yay "Done!"
|
||||||
;;
|
;;
|
||||||
updatebundle)
|
updatebundle)
|
||||||
# Updates .dotfiles/Brewfile with descriptions
|
# Updates .dotfiles/Brewfile with descriptions
|
||||||
brew bundle dump \
|
brew bundle dump \
|
||||||
--force \
|
--force \
|
||||||
--file="$BREWFILE" \
|
--file="$BREWFILE" \
|
||||||
--describe && msg_done "🎉 Done!"
|
--describe && msg_yay "Done!"
|
||||||
;;
|
;;
|
||||||
autoupdate)
|
autoupdate)
|
||||||
brew autoupdate delete
|
brew autoupdate delete
|
||||||
brew autoupdate start 43200 --upgrade --cleanup --immediate
|
brew autoupdate start 43200 --upgrade --cleanup --immediate
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
menu_section "$USAGE_PREFIX" "install | update | updatebundle | autoupdate"
|
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
|
||||||
menu_item "install" "Installs items defined in Brewfile"
|
|
||||||
menu_item "update" "Updates and upgrades brew packages"
|
|
||||||
menu_item "updatebundle" "Updates Brewfile with descriptions"
|
|
||||||
menu_item "autoupdate" "Setups brew auto-update and runs it immediately"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
@@ -152,6 +158,14 @@ function section_dotfiles
|
|||||||
{
|
{
|
||||||
USAGE_PREFIX="$SCRIPT dotfiles"
|
USAGE_PREFIX="$SCRIPT dotfiles"
|
||||||
|
|
||||||
|
MENU=(
|
||||||
|
"fmt:Run all formatters"
|
||||||
|
"yamlfmt:Run yamlfmt to all dotfiles, which are in our control"
|
||||||
|
"shfmt:Run shfmt to all dotfiles"
|
||||||
|
"reset_all:Reset everything, runs all configured reset actions"
|
||||||
|
"reset_nvim:Resets nvim. Deletes caches, removes nvim folders and relinks nvim folders"
|
||||||
|
)
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
fmt)
|
fmt)
|
||||||
msg_ok "Running all formatters"
|
msg_ok "Running all formatters"
|
||||||
@@ -171,8 +185,8 @@ function section_dotfiles
|
|||||||
~/.config/astronvim \
|
~/.config/astronvim \
|
||||||
~/.config/nvim
|
~/.config/nvim
|
||||||
msg_ok "Deleted old nvim files"
|
msg_ok "Deleted old nvim files"
|
||||||
ln -s ~/.dotfiles/config/astronvim ~/.config/astronvim
|
ln -s $DOTFILES/config/astronvim ~/.config/astronvim
|
||||||
ln -s ~/.dotfiles/config/nvim ~/.config/nvim
|
ln -s $DOTFILES/config/nvim ~/.config/nvim
|
||||||
msg_ok "Linked nvim and astronvim"
|
msg_ok "Linked nvim and astronvim"
|
||||||
hash npm 2> /dev/null && $0 install npm
|
hash npm 2> /dev/null && $0 install npm
|
||||||
msg_ok "Installed packages"
|
msg_ok "Installed packages"
|
||||||
@@ -197,15 +211,10 @@ function section_dotfiles
|
|||||||
--func-next-line --list --write \
|
--func-next-line --list --write \
|
||||||
--indent 2 --case-indent --space-redirects \
|
--indent 2 --case-indent --space-redirects \
|
||||||
--binary-next-line {} \;
|
--binary-next-line {} \;
|
||||||
msg_done "🎉 dotfiles have been shfmt formatted!"
|
msg_yay "dotfiles have been shfmt formatted!"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
menu_section "$USAGE_PREFIX" "fmt | reset_all | reset_nvim | yamlfmt | shfmt"
|
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
|
||||||
menu_item "fmt" "Run all formatters"
|
|
||||||
menu_item "reset_all" "Reset everything, runs all configured reset actions"
|
|
||||||
menu_item "reset_nvim" "Resets nvim. Deletes caches, removes nvim folders and relinks nvim folders"
|
|
||||||
menu_item "yamlfmt" "Run yamlfmt to all dotfiles, which are in our control"
|
|
||||||
menu_item "shfmt" "Run shfmt to all dotfiles"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -216,6 +225,11 @@ function section_check
|
|||||||
X_HOSTNAME=$(hostname)
|
X_HOSTNAME=$(hostname)
|
||||||
X_ARCH=$(uname)
|
X_ARCH=$(uname)
|
||||||
|
|
||||||
|
MENU=(
|
||||||
|
"arch <arch>:Empty returns current. Exit code 0 when match, 1 when not."
|
||||||
|
"host <host>:Empty returns current. Exit code 0 when match, 1 when not."
|
||||||
|
)
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
a | arch)
|
a | arch)
|
||||||
[[ "$2" = "" ]] && echo "$X_ARCH" && exit 0
|
[[ "$2" = "" ]] && echo "$X_ARCH" && exit 0
|
||||||
@@ -226,9 +240,7 @@ function section_check
|
|||||||
[[ $X_HOSTNAME = "$2" ]] && exit 0 || exit 1
|
[[ $X_HOSTNAME = "$2" ]] && exit 0 || exit 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
menu_section "$USAGE_PREFIX" "arch | host"
|
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
|
||||||
menu_item "arch <arch>" "Empty returns current. Exit code 0 when match, 1 when not."
|
|
||||||
menu_item "host <host>" "Empty returns current. Exit code 0 when match, 1 when not."
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -238,30 +250,44 @@ function section_tests
|
|||||||
{
|
{
|
||||||
USAGE_PREFIX="$SCRIPT tests"
|
USAGE_PREFIX="$SCRIPT tests"
|
||||||
|
|
||||||
|
MENU=(
|
||||||
|
"msg:List all log functions from shared.sh"
|
||||||
|
)
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
msg)
|
msg)
|
||||||
msg "msg"
|
msg "msg"
|
||||||
msg_done "msg_done"
|
msg_done "msg_done"
|
||||||
msg_prompt "msg_prompt"
|
msg_done_suffix "msg_done_suffix"
|
||||||
msg_prompt_done "msg_prompt_done"
|
msg_err "msg_err"
|
||||||
msg_nested "msg_nested"
|
msg_nested "msg_nested"
|
||||||
msg_nested_done "msg_nested_done"
|
msg_nested_done "msg_nested_done"
|
||||||
msg_run "msg_run" "second_param"
|
|
||||||
msg_ok "msg_ok"
|
msg_ok "msg_ok"
|
||||||
|
msg_prompt "msg_prompt"
|
||||||
|
msg_prompt_done "msg_prompt_done"
|
||||||
|
msg_run "msg_run" "second_param"
|
||||||
|
msg_run_done "msg_run_done" "second_param"
|
||||||
msg_warn "msg_warn"
|
msg_warn "msg_warn"
|
||||||
msg_err "msg_err"
|
msg_yay "msg_yay"
|
||||||
|
msg_yay_done "msg_yay_done"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
menu_section "$USAGE_PREFIX" "msg"
|
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
|
||||||
menu_item "msg" "List all log functions from shared.sh"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage
|
function usage
|
||||||
{
|
{
|
||||||
|
SECTIONS=(
|
||||||
|
"install"
|
||||||
|
"reset"
|
||||||
|
"brew"
|
||||||
|
"check"
|
||||||
|
"dotfiles"
|
||||||
|
)
|
||||||
echo ""
|
echo ""
|
||||||
menu_section "Usage: $SCRIPT" "install | reset | brew | check | dotfiles"
|
menu_usage_header "Usage: $SCRIPT" "${SECTIONS[@]}"
|
||||||
echo $" All commands have their own subcommands."
|
echo $" All commands have their own subcommands."
|
||||||
echo ""
|
echo ""
|
||||||
section_install
|
section_install
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ function __log_marker_warn()
|
|||||||
echo -e "${CLR_YELLOW}⁕${CLR_RESET}"
|
echo -e "${CLR_YELLOW}⁕${CLR_RESET}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __log_marker_question()
|
||||||
|
{
|
||||||
|
echo -e "${CLR_YELLOW}?${CLR_RESET}"
|
||||||
|
}
|
||||||
|
|
||||||
function __log_marker_err()
|
function __log_marker_err()
|
||||||
{
|
{
|
||||||
echo -e "${CLR_RED}⛌${CLR_RESET}"
|
echo -e "${CLR_RED}⛌${CLR_RESET}"
|
||||||
@@ -48,19 +53,33 @@ function msg()
|
|||||||
echo -e "$(__log_marker) $1"
|
echo -e "$(__log_marker) $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function msg_yay()
|
||||||
|
{
|
||||||
|
echo -e "🎉 $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function msg_yay_done()
|
||||||
|
{
|
||||||
|
echo -e "🎉 $1 ...$(__log_marker_ok)"
|
||||||
|
}
|
||||||
|
|
||||||
function msg_done()
|
function msg_done()
|
||||||
{
|
{
|
||||||
echo -e "$(__log_marker) $1 ...$(__log_marker_ok)"
|
echo -e "$(__log_marker) $1 ...$(__log_marker_ok)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function msg_done_suffix() {
|
||||||
|
echo -e "$(__log_marker) ...$(__log_marker_ok)"
|
||||||
|
}
|
||||||
|
|
||||||
function msg_prompt()
|
function msg_prompt()
|
||||||
{
|
{
|
||||||
echo -e "$(__log_marker) $1"
|
echo -e "$(__log_marker_question) $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
function msg_prompt_done()
|
function msg_prompt_done()
|
||||||
{
|
{
|
||||||
echo -e "$(__log_marker) $1 ...$(__log_marker_ok)"
|
echo -e "$(__log_marker_question) $1 ...$(__log_marker_ok)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function msg_nested()
|
function msg_nested()
|
||||||
@@ -78,6 +97,11 @@ function msg_run()
|
|||||||
echo -e "${CLR_GREEN}➜ $1${CLR_RESET} $2"
|
echo -e "${CLR_GREEN}➜ $1${CLR_RESET} $2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function msg_run_done()
|
||||||
|
{
|
||||||
|
echo -e "${CLR_GREEN}➜ $1${CLR_RESET} $2 ...$(__log_marker_ok)"
|
||||||
|
}
|
||||||
|
|
||||||
function msg_ok()
|
function msg_ok()
|
||||||
{
|
{
|
||||||
echo -e "$(__log_marker_ok) $1"
|
echo -e "$(__log_marker_ok) $1"
|
||||||
@@ -111,3 +135,39 @@ function fn_exists()
|
|||||||
declare -f -F "$1" > /dev/null
|
declare -f -F "$1" > /dev/null
|
||||||
return $?
|
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=("$@")
|
||||||
|
|
||||||
|
menu_usage_header "$MENU_CMD" "${MENU_ARRAY[@]}"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user