mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
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
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -171,3 +171,33 @@ function menu_usage()
|
||||
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"}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user