Compare commits

...

4 Commits

Author SHA1 Message Date
c1287c4ea8 dfm: menu rework, docs. codestyle fixes. 2023-04-14 10:10:32 +03:00
7b63afd4f5 dfm: Fix imagick installation 2023-04-14 00:48:37 +03:00
e5d6cb37fd shell: have, path_(append|prepend|remove)
- have: command -v shorthand
- path_append: appends dir to PATH
- path_prepend: prepends dir to PATH
- path_remove: removes dir from PATH
2023-04-14 00:42:08 +03:00
4492c386b6 dfm: rewrote the usage menu generation 2023-04-14 00:01:58 +03:00
18 changed files with 291 additions and 199 deletions

View File

@@ -7,25 +7,3 @@ indent_size = 2
indent_style = space
insert_final_newline = 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

2
.gitignore vendored
View File

@@ -1,6 +1,6 @@
Brewfile.lock.json
*.log
*-secret
*cache
.idea
.vscode

View File

@@ -6,6 +6,8 @@ colors
# Defaults
export DOTFILES="$HOME/.dotfiles"
# shellcheck source=shared.sh
source "$DOTFILES/scripts/shared.sh"
# Run x-load-configs in your terminal to reload the files.
function x-load-configs()
@@ -28,14 +30,14 @@ ANTIGEN_ZSH_PATH="$XDG_BIN_HOME/antigen.zsh"
[[ -f "$ANTIGEN_ZSH_PATH" ]] && source "$ANTIGEN_ZSH_PATH"
# antigen is present
if command -v antigen &> /dev/null; then
have antigen && {
antigen use oh-my-zsh
# config/functions
x-default-antigen-bundles
antigen apply
fi
eval "$(starship init zsh)"
}
# starship is present
have starship && eval "$(starship init zsh)"

View File

@@ -1,9 +1,11 @@
#!/usr/bin/env bash
# shellcheck source="../scripts/shared.sh"
source "$DOTFILES/scripts/shared.sh"
# Get installed php versions from brew and setup aliases
function x-set-php-aliases
{
if command -v brew &> /dev/null; then
have brew && {
local php_versions=()
while IFS="" read -r line; do php_versions+=("$line"); done < <(brew list | grep '^php')
@@ -31,7 +33,7 @@ function x-set-php-aliases
# shellcheck disable=SC2139,SC2140
alias "${php_alias}c"="$php_exec $php_error_reporting $(which composer)"
done
fi
}
}
if [[ $(uname) == 'Darwin' ]]; then
@@ -74,10 +76,8 @@ alias code_scanner='docker run
alias zedit='$EDITOR ~/.dotfiles'
if hash irssi 2> /dev/null; then
# shellcheck disable=2139
alias irssi="irssi --config='$IRSSI_CONFIG_FILE' --home='$IRSSI_CONFIG_HOME'"
fi
have irssi \
&& alias irssi="irssi --config='$IRSSI_CONFIG_FILE' --home='$IRSSI_CONFIG_HOME'"
if [[ -f "$HOME/.aliases.local" ]]; then
# shellcheck disable=SC1091

View File

@@ -3,7 +3,8 @@
# vim: filetype=zsh
export DOTFILES="$HOME/.dotfiles"
export PATH="$DOTFILES/local/bin:$PATH"
source "$DOTFILES/scripts/shared.sh"
path_append "$DOTFILES/local/bin"
# Explicitly set XDG folders
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
@@ -23,21 +24,20 @@ export HOMEBREW_SBIN="$HOMEBREW/sbin"
export HOMEBREW_PKG="$HOMEBREW/opt"
export HOMEBREW_NO_ENV_HINTS=1
export PATH="$XDG_BIN_HOME:$HOMEBREW_BIN:$HOMEBREW_SBIN:/usr/local/sbin:$PATH"
path_append "/usr/local/bin"
path_append "$HOMEBREW_SBIN"
path_append "$HOMEBREW_BIN"
path_append "$XDG_BIN_HOME"
# brew, https://brew.sh
if command -v brew &> /dev/null; then
BREW_PYTHON=$(brew --prefix python)/bin
GNUBIN_DIR=$(brew --prefix coreutils)/libexec/gnubin
BREW_RUBY=$(brew --prefix ruby)/bin
BREW_GEMS=$(gem environment gemdir)/bin
export PATH="$BREW_PYTHON:$GNUBIN_DIR:$BREW_GEMS:$BREW_RUBY:$PATH"
fi
have brew && {
path_append "$(brew --prefix python)/bin"
path_append "$(brew --prefix coreutils)/libexec/gnubin"
path_append "$(brew --prefix ruby)/bin"
path_append "$(gem environment gemdir)/bin"
}
source "$DOTFILES/config/exports-shell"
source "$DOTFILES/config/exports-apps"
if command -v nvim &> /dev/null; then
export EDITOR="nvim"
fi
have nvim && export EDITOR="nvim"

View File

@@ -2,6 +2,7 @@
# shellcheck shell=bash
# shellcheck enable=external-sources
# vim: filetype=zsh
source "$DOTFILES/scripts/shared.sh"
# Antigen configuration
# https://github.com/zsh-users/antigen/wiki/Configuration
@@ -11,61 +12,62 @@ export ANTIGEN_PLUGIN_RECEIPT_F=".local/share/antigen/antigen_plugin_lastupdate"
# Ansible configuration
# https://docs.ansible.com/ansible/latest/reference_appendices/config.html
if hash ansible 2> /dev/null; then
have ansible && {
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"
fi
}
# composer, https://getcomposer.org/
if command -v composer &> /dev/null; then
have composer && {
export COMPOSER_HOME="$XDG_STATE_HOME/composer"
export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin"
export PATH="$COMPOSER_BIN:$PATH"
fi
}
# docker, https://docs.docker.com/engine/reference/commandline/cli/
if command -v docker &> /dev/null; then
have docker && {
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
x-dc "$DOCKER_CONFIG"
fi
}
# ffmpeg
if hash ffmpeg 2> /dev/null; then
have ffmpeg && {
export FFMPEG_DATADIR="$XDG_CONFIG_HOME/ffmpeg"
x-dc "$FFMPEG_DATADIR"
fi
}
# gcloud
if hash gcloud 2> /dev/null; then
have gcloud && {
GCLOUD_LOC=$(gcloud info --format="value(installation.sdk_root)" --quiet)
[[ -f "$GCLOUD_LOC/path.zsh.inc" ]] && builtin source "$GCLOUD_LOC/path.zsh.inc"
[[ -f "$GCLOUD_LOC/completion.zsh.inc" ]] && builtin source "$GCLOUD_LOC/completion.zsh.inc"
fi
}
# gem, rubygems
if command -v gem &> /dev/null; then
have gem && {
export GEM_HOME="$XDG_STATE_HOME/gem"
export GEM_PATH="$XDG_STATE_HOME/gem"
export PATH="$GEM_HOME/bin:$PATH"
fi
path_append "$GEM_PATH/bin"
}
# If we have go packages, include them to the PATH
if command -v go &> /dev/null; then
have go && {
export GOPATH="$XDG_DATA_HOME/go"
export GOBIN="$XDG_BIN_HOME"
x-dc "$GOPATH"
fi
}
# irssi
if hash irssi 2> /dev/null; then
have irssi && {
# These variables are used in ./alias with --config and --home
export IRSSI_CONFIG_HOME="$XDG_CONFIG_HOME/irssi"
export IRSSI_CONFIG_FILE="$IRSSI_CONFIG_HOME/config"
x-dc "$IRSSI_CONFIG_HOME"
fi
}
# nvm, the node version manager
export NVM_LAZY_LOAD=true
@@ -76,21 +78,21 @@ export NVM_DIR="$XDG_CONFIG_HOME/nvm"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# op (1Password cli) is present
if hash op 2> /dev/null; then
have op && {
export OP_CACHE="$XDG_STATE_HOME/1password"
x-dc "$OP_CACHE"
eval "$(op completion zsh)"
compdef _op op
fi
}
# pyenv, python environments
if command -v pyenv &> /dev/null; then
have pyenv && {
export PYENV_ROOT="$XDG_STATE_HOME/pyenv"
x-dc "$PYENV_ROOT"
export PATH="$PYENV_ROOT/bin:$PATH"
path_append "$PYENV_ROOT/bin"
eval "$(pyenv init -)"
fi
}
# wakatime, https://github.com/wakatime/wakatime-cli
export WAKATIME_HOME="$XDG_STATE_HOME/wakatime"
@@ -104,4 +106,3 @@ export _Z_DATA="$XDG_STATE_HOME/z"
export ANDROID_HOME="$XDG_DATA_HOME/android"
export GNUPGHOME="$XDG_DATA_HOME/gnupg"
export SCREENRC="$XDG_CONFIG_HOME/misc/screenrc"

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# vim: filetype=zsh
source "$DOTFILES/scripts/shared.sh"
export LC_ALL=fi_FI.utf8
@@ -39,10 +40,7 @@ hash shopt 2> /dev/null && shopt -s checkwinsize
&& source "$XDG_BIN_HOME/iterm2_shell_integration.zsh"
# Set dircolors based on the file, if it exists
if command -v dircolors &> /dev/null; then
# shellcheck disable=SC2046
eval $(dircolors "$XDG_CONFIG_HOME/dircolors")
fi
have dircolors && eval $(dircolors "$XDG_CONFIG_HOME/dircolors")
# If we are using zsh, color our dir lists and such
if [ "$SHELL" = "$(which zsh)" ]; then
@@ -52,4 +50,3 @@ if [ "$SHELL" = "$(which zsh)" ]; then
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
zstyle ':completion:*' list-colors "$LS_COLORS"
fi

View File

@@ -2,6 +2,8 @@
#
# shell functions
#
# shellcheck source="../scripts/shared.sh"
source "$DOTFILES/scripts/shared.sh"
# Weather in Tampere, or other city
function weather
@@ -66,29 +68,6 @@ function silent
"$@" >&/dev/null
}
# Remove directory from the PATH variable
# usage: path_remove ~/.local/bin
function path_remove
{
PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//')
}
# Append directory to the PATH
# usage: path_append ~/.local/bin
function path_append
{
path_remove "$1"
PATH="${PATH:+"$PATH:"}$1"
}
# Prepend directory to the PATH
# usage: path_prepend ~/.local/bin
function path_prepend
{
path_remove "$1"
PATH="$1${PATH:+":$PATH"}"
}
# Defines default antigen bundles
function x-default-antigen-bundles
{
@@ -104,13 +83,13 @@ function x-default-antigen-bundles
antigen bundle zsh-users/zsh-syntax-highlighting
# these should be available if there's need
hash git 2> /dev/null && antigen bundle git
hash brew 2> /dev/null && antigen bundle brew
hash docker 2> /dev/null && antigen bundle docker
hash docker-compose 2> /dev/null && antigen bundle sroze/docker-compose-zsh-plugin
hash jq 2> /dev/null && antigen bundle reegnz/jq-zsh-plugin
hash nvm 2> /dev/null && antigen bundle nvm
hash php 2> /dev/null && antigen bundle php
hash python 2> /dev/null && antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
hash rvm 2> /dev/null && antigen bundle unixorn/rvm-plugin
have git && antigen bundle git
have brew && antigen bundle brew
have docker && antigen bundle docker
have docker-compose && antigen bundle sroze/docker-compose-zsh-plugin
have jq && antigen bundle reegnz/jq-zsh-plugin
have nvm && antigen bundle nvm
have php && antigen bundle php
have python && antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
have rvm && antigen bundle unixorn/rvm-plugin
}

View File

@@ -9,6 +9,7 @@
# Helper variables, override with ENVs like `VERBOSE=1 dfm help`
: "${VERBOSE:=0}"
: "${DOTFILES:=$HOME/.dotfiles}"
: "${SHARED_SCRIPT:=$DOTFILES/scripts/shared.sh}"
: "${INSTALL_SCRIPT:=$DOTFILES/scripts/install-dotfiles.sh}"
: "${BREWFILE:=$DOTFILES/Brewfile}"
: "${HOSTFILES:=$DOTFILES/hosts}"
@@ -18,11 +19,27 @@ SCRIPT=$(basename "$0")
VERSION_NVM="v0.39.3"
# shellcheck source=./../../scripts/shared.sh
source "$DOTFILES/scripts/shared.sh"
source "$SHARED_SCRIPT"
function section_install
{
USAGE_PREFIX="$SCRIPT install"
USAGE_PREFIX="$SCRIPT install <command>"
MENU=(
"all:Installs everything in the correct order"
"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
all)
@@ -42,115 +59,111 @@ function section_install
;;
antigen)
curl -L git.io/antigen > "$DOTFILES/local/bin/antigen.zsh" \
&& msg_done "🎉 New antigen installed!"
&& msg_yay "New antigen installed!"
;;
composer)
bash "$DOTFILES/scripts/install-composer.sh" \
&& msg_done "🎉 composer installed!"
&& msg_yay "composer installed!"
;;
dotenv)
curl -sSfL \
https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh \
| sh -s -- -b "$XDG_BIN_HOME" \
&& msg_done "🎉 dotenv-linter installed!"
&& msg_yay "dotenv-linter installed!"
;;
gh)
bash "$DOTFILES/scripts/install-gh-extensions.sh" \
&& msg_done "🎉 github cli extensions installed!"
&& msg_yay "github cli extensions installed!"
;;
go)
bash "$DOTFILES/scripts/install-go-packages.sh" \
&& msg_done "🎉 go packages installed!"
&& msg_yay "go packages installed!"
;;
imagick)
wget https://imagemagick.org/archive/binaries/magick > "$XDG_BIN_HOME/magick" \
&& msg_done "🎉 imagick installed!"
curl -L https://imagemagick.org/archive/binaries/magick > "$XDG_BIN_HOME/magick" \
&& msg_yay "imagick installed!"
;;
starship)
curl -sS https://starship.rs/install.sh | sh -s -- --bin-dir ~/.local/bin \
&& msg_done "🎉 starship installed!"
&& msg_yay "starship installed!"
;;
macos)
bash "$DOTFILES/scripts/set-macos-defaults.sh" \
&& msg_done "🎉 Brewfile defined apps has been installed!"
&& msg_yay "Brewfile defined apps has been installed!"
;;
nvm)
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION_NVM/install.sh" | bash \
&& nvm install --lts --latest-npm --default \
&& git checkout "$HOME/.zshrc" \
&& msg_done "🎉 nvm installed!"
&& msg_yay "nvm installed!"
;;
npm)
bash "$DOTFILES/scripts/install-npm-packages.sh" \
&& msg_done "🎉 NPM Packages have been installed!"
&& msg_yay "NPM Packages have been installed!"
;;
ntfy)
bash "$DOTFILES/scripts/install-ntfy.sh" \
&& msg_done "🎉 ntfy installed!"
&& msg_yay "ntfy installed!"
;;
z)
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_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"
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
;;
esac
}
function section_brew
{
USAGE_PREFIX="$SCRIPT brew"
USAGE_PREFIX="$SCRIPT brew <command>"
if ! command -v brew &> /dev/null; then
menu_section "$USAGE_PREFIX" "brew not available on this system"
else
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"
)
have brew && {
case "$1" in
install)
brew bundle install --file="$BREWFILE" && msg_done "🎉 Done!"
brew bundle install --file="$BREWFILE" && msg_yay "Done!"
;;
update)
brew update && brew outdated && brew upgrade && brew cleanup
msg_done "🎉 Done!"
msg_yay "Done!"
;;
updatebundle)
# Updates .dotfiles/Brewfile with descriptions
brew bundle dump \
--force \
--file="$BREWFILE" \
--describe && msg_done "🎉 Done!"
--describe && msg_yay "Done!"
;;
autoupdate)
brew autoupdate delete
brew autoupdate start 43200 --upgrade --cleanup --immediate
;;
*)
menu_section "$USAGE_PREFIX" "install | update | updatebundle | autoupdate"
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"
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
;;
esac
fi
} || menu_section "$USAGE_PREFIX" "brew not available on this system"
}
function section_dotfiles
{
USAGE_PREFIX="$SCRIPT dotfiles"
USAGE_PREFIX="$SCRIPT dotfiles <command>"
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
fmt)
@@ -171,16 +184,16 @@ function section_dotfiles
~/.config/astronvim \
~/.config/nvim
msg_ok "Deleted old nvim files"
ln -s ~/.dotfiles/config/astronvim ~/.config/astronvim
ln -s ~/.dotfiles/config/nvim ~/.config/nvim
ln -s $DOTFILES/config/astronvim ~/.config/astronvim
ln -s $DOTFILES/config/nvim ~/.config/nvim
msg_ok "Linked nvim and astronvim"
hash npm 2> /dev/null && $0 install npm
have npm && $0 install npm
msg_ok "Installed packages"
msg_done "nvim reset!"
;;
yamlfmt)
# format yaml files
yamlfmt -conf "$DOTFILES/.yamlfmt"
have yamlfmt && yamlfmt -conf "$DOTFILES/.yamlfmt" || msg_err "yamlfmt not found"
;;
shfmt)
# Format shell scripts according to following rules.
@@ -197,25 +210,25 @@ function section_dotfiles
--func-next-line --list --write \
--indent 2 --case-indent --space-redirects \
--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_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"
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
;;
esac
}
function section_check
{
USAGE_PREFIX="$SCRIPT check"
USAGE_PREFIX="$SCRIPT check <command>"
X_HOSTNAME=$(hostname)
X_ARCH=$(uname)
MENU=(
"arch <arch>:Empty <arch> returns current. Exit code 0=match to current, 1=no match."
"host <host>:Empty <host> returns current. Exit code 0=match to current, 1=no match."
)
case "$1" in
a | arch)
[[ "$2" = "" ]] && echo "$X_ARCH" && exit 0
@@ -226,9 +239,7 @@ function section_check
[[ $X_HOSTNAME = "$2" ]] && exit 0 || exit 1
;;
*)
menu_section "$USAGE_PREFIX" "arch | host"
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."
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
;;
esac
}
@@ -236,24 +247,31 @@ function section_check
# Secret menu for visual tests
function section_tests
{
USAGE_PREFIX="$SCRIPT tests"
USAGE_PREFIX="$SCRIPT tests <command>"
MENU=(
"msg:List all log functions from shared.sh"
)
case "$1" in
msg)
msg "msg"
msg_done "msg_done"
msg_prompt "msg_prompt"
msg_prompt_done "msg_prompt_done"
msg_done_suffix "msg_done_suffix"
msg_err "msg_err"
msg_nested "msg_nested"
msg_nested_done "msg_nested_done"
msg_run "msg_run" "second_param"
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_err "msg_err"
msg_yay "msg_yay"
msg_yay_done "msg_yay_done"
;;
*)
menu_section "$USAGE_PREFIX" "msg"
menu_item "msg" "List all log functions from shared.sh"
menu_usage "$USAGE_PREFIX" "${MENU[@]}"
;;
esac
}
@@ -261,8 +279,8 @@ function section_tests
function usage
{
echo ""
menu_section "Usage: $SCRIPT" "install | reset | brew | check | dotfiles"
echo $" All commands have their own subcommands."
msg_prompt "Usage: $SCRIPT <section> <command>"
echo $" Empty <command> prints <section> help."
echo ""
section_install
echo ""

View File

@@ -11,4 +11,3 @@ dir="$1"
if [ ! -d "$dir" ]; then
mkdir -p "$dir" && exit 0
fi

View File

@@ -2,4 +2,3 @@
# Source: https://github.com/thirtythreeforty/dotfiles/blob/master/bin/extip
curl icanhazip.com "${@}"

View File

@@ -1,6 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash
# Install PHP Package Manager Composer
#
# shellcheck source="shared.sh"
source "$HOME/.dotfiles/scripts/shared.sh"
if command -v php &> /dev/null; then
have php && {
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
@@ -16,4 +20,4 @@ if command -v php &> /dev/null; then
rm composer-setup.php
mv composer.phar ~/.local/bin/composer
exit $RESULT
fi
} || msg_err "PHP Not Available, cannot install composer"

View File

@@ -4,9 +4,7 @@
# shellcheck source="shared.sh"
source "$HOME/.dotfiles/scripts/shared.sh"
if ! command -v gh &> /dev/null; then
msg_run "gh (GitHub Client) could not be found, please install it first"
else
have gh && {
extensions=(
# GitHub CLI extension for generating a report on repository dependencies.
andyfeller/gh-dependency-report
@@ -41,4 +39,4 @@ else
done
msg_ok "Done"
fi
} || msg_err "gh (GitHub Client) could not be found, please install it first"

View File

@@ -4,9 +4,7 @@
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
if ! command -v go &> /dev/null; then
msg "go hasn't been installed yet."
else
have go && {
packages=(
# sysadmin/scripting utilities, distributed as a single binary
github.com/skx/sysbox@latest
@@ -28,5 +26,4 @@ else
done
msg_ok "Done"
fi
} || msg "go hasn't been installed yet."

View File

@@ -4,9 +4,7 @@
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
if ! command -v npm &> /dev/null; then
msg_err "npm could not be found."
else
have npm && {
packages=(
# This is a tool to check if your files consider your .editorconfig rules.
"editorconfig-checker"
@@ -35,4 +33,4 @@ else
npm install -g --no-fund --no-progress --no-timing "$pkg"
echo ""
done
fi
} || msg_err "npm could not be found."

View File

@@ -1,8 +1,14 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Install ntfy
#
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
set -e
if ! command -v ntfy &> /dev/null; then
have ntfy && {
msg "ntfy already installed"
} || {
case $(dfm check arch) in
Linux)
NTFY_ARCH="linux_$(arch)"
@@ -28,6 +34,4 @@ if ! command -v ntfy &> /dev/null; then
fi
rm -rf "${NTFY_DEST}" "${NTFY_DEST}.tar.gz"
else
echo "ntfy already installed"
fi
}

View File

@@ -1,4 +1,9 @@
#!/usr/bin/env bash
#
# Install z
#
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
Z_GIT_PATH="https://github.com/rupa/z.git"
Z_BIN_PATH="$XDG_BIN_HOME/z"
@@ -6,5 +11,5 @@ Z_BIN_PATH="$XDG_BIN_HOME/z"
if [ ! -d "$Z_BIN_PATH" ]; then
git clone "$Z_GIT_PATH" "$Z_BIN_PATH"
else
echo "z ($Z_BIN_PATH/) already installed"
msg_done "z ($Z_BIN_PATH/) already installed"
fi

View File

@@ -11,6 +11,28 @@ CLR_GREEN="\033[1;32m"
CLR_BLUE="\033[1;34m"
CLR_RESET="\033[0m"
# -- Color functions -- #
function __color_red()
{
local MSG="$1"
echo -e "${CLR_RED}${MSG}${CLR_RESET}"
}
function __color_yellow()
{
local MSG="$1"
echo -e "${CLR_YELLOW}${MSG}${CLR_RESET}"
}
function __color_green()
{
local MSG="$1"
echo -e "${CLR_GREEN}${MSG}${CLR_RESET}"
}
function __color_blue()
{
local MSG="$1"
echo -e "${CLR_BLUE}${MSG}${CLR_RESET}"
}
# -- Helpers -- #
function __log_marker()
{
@@ -32,6 +54,11 @@ function __log_marker_warn()
echo -e "${CLR_YELLOW}${CLR_RESET}"
}
function __log_marker_question()
{
echo -e "${CLR_YELLOW}?${CLR_RESET}"
}
function __log_marker_err()
{
echo -e "${CLR_RED}${CLR_RESET}"
@@ -48,19 +75,34 @@ function msg()
echo -e "$(__log_marker) $1"
}
function msg_yay()
{
echo -e "🎉 $1"
}
function msg_yay_done()
{
echo -e "🎉 $1 ...$(__log_marker_ok)"
}
function msg_done()
{
echo -e "$(__log_marker) $1 ...$(__log_marker_ok)"
}
function msg_done_suffix()
{
echo -e "$(__log_marker) ...$(__log_marker_ok)"
}
function msg_prompt()
{
echo -e "$(__log_marker) $1"
echo -e "$(__log_marker_question) $1"
}
function msg_prompt_done()
{
echo -e "$(__log_marker) $1 ...$(__log_marker_ok)"
echo -e "$(__log_marker_question) $1 ...$(__log_marker_ok)"
}
function msg_nested()
@@ -78,6 +120,11 @@ function msg_run()
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()
{
echo -e "$(__log_marker_ok) $1"
@@ -111,3 +158,69 @@ 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
}
# shorthand for checking if the system has the bin in path.
# usage: have php && php -v
function have
{
command -v "$1" >&/dev/null
}
# Remove directory from the PATH variable
# usage: path_remove ~/.local/bin
function path_remove
{
PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//')
}
# Append directory to the PATH
# usage: path_append ~/.local/bin
function path_append
{
path_remove "$1"
PATH="${PATH:+"$PATH:"}$1"
}
# Prepend directory to the PATH
# usage: path_prepend ~/.local/bin
function path_prepend
{
path_remove "$1"
PATH="$1${PATH:+":$PATH"}"
}