ref(sh): check exit code rather than stdout

This commit is contained in:
AJ ONeal
2023-10-30 06:03:41 +00:00
parent 9f391b30be
commit afd490e47f
6 changed files with 29 additions and 22 deletions

View File

@@ -4,20 +4,21 @@ set -u
__init_git() {
if [ -z "$(command -v git)" ]; then
if [ "Darwin" = "$(uname -s)" ]; then
echo >&2 "Error: 'git' not found. You may have to re-install 'git' on Mac after every major update."
echo >&2 " for example, try: xcode-select --install"
# sudo xcodebuild -license accept
else
echo >&2 "Error: to install 'git' on Linux use the built-in package manager."
echo >&2 " for example, try: sudo apt install -y git"
fi
exit 1
else
if command -v git > /dev/null; then
echo "'git' already installed"
return 0
fi
if [ "Darwin" = "$(uname -s)" ]; then
echo >&2 "Error: 'git' not found. You may have to re-install 'git' on Mac after every major update."
echo >&2 " for example, try: xcode-select --install"
# sudo xcodebuild -license accept
else
echo >&2 "Error: to install 'git' on Linux use the built-in package manager."
echo >&2 " for example, try: sudo apt install -y git"
fi
exit 1
}
__init_git

View File

@@ -17,7 +17,7 @@ __init_pyenv() {
} >> ~/.bashrc
fi
if [ -n "$(command -v zsh)" ]; then
if command -v zsh > /dev/null; then
touch ~/.zshrc
if ! grep -q 'pyenv init' ~/.zshrc; then
{
@@ -31,7 +31,7 @@ __init_pyenv() {
fi
fi
if [ -n "$(command -v fish)" ]; then
if command -v fish > /dev/null; then
mkdir -p ~/.config/fish
touch ~/.config/fish/config.fish
if ! grep -q 'pyenv init' ~/.config/fish/config.fish; then

View File

@@ -4,14 +4,20 @@ set -u
__init_sudo() {
if [ -z "$(command -v sudo)" ]; then
echo >&2 "Error: on Linux and BSD you should install sudo via the native package manager"
echo >&2 " for example: apt install -y sudo"
exit 1
else
if command -v sudo > /dev/null; then
echo "'sudo' already installed"
exit 0
fi
echo >&2 "Error: on Linux & BSD use the native package manager to install sudo:"
echo >&2 " For Ubuntu / Debian:"
echo >&2 " apt install -y sudo"
echo >&2 ""
echo >&2 " For Alpine / Docker:"
echo >&2 " apk add sudo"
echo >&2 ""
exit 1
}
__init_sudo

View File

@@ -22,7 +22,7 @@ __init_vim_beyondcode() {
nerdfont \
vim-devicons
if [ -n "$(command -v go)" ]; then
if command -v go > /dev/null; then
"$HOME/.local/bin/webi" vim-go
fi
# done

View File

@@ -8,7 +8,7 @@ __init_vim_prettier() {
rm -rf "$HOME/.vim/pack/plugins/start/vim-prettier"
git clone --depth=1 https://github.com/prettier/vim-prettier.git "$HOME/.vim/pack/plugins/start/vim-prettier"
if [ -z "$(command -v node)" ]; then
if ! command -v node > /dev/null; then
export PATH="$HOME/.local/opt/node/bin:$HOME/.local/bin:${PATH}"
"$HOME/.local/bin/webi" node
fi

View File

@@ -9,10 +9,10 @@ __init_vim_shfmt() {
git clone --depth=1 https://github.com/z0mbix/vim-shfmt.git "$HOME/.vim/pack/plugins/start/vim-shfmt"
export PATH="$HOME/.local/bin:${PATH}"
if [ -z "$(command -v shfmt)" ]; then
if ! command -v shfmt > /dev/null; then
"$HOME/.local/bin/webi" shfmt
fi
if [ -z "$(command -v shellcheck)" ]; then
if ! command -v shellcheck > /dev/null; then
"$HOME/.local/bin/webi" shellcheck
fi