From 4699233d469531d62b532726dce4011d801bd457 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Mon, 13 Nov 2023 09:25:58 +0200 Subject: [PATCH] chore(shell): touching the paths again, no regrats --- base/bashrc | 6 +--- base/zshrc | 15 ++------ config/alias | 17 +++++----- config/exports-apps | 13 ++++--- config/exports-lakka | 2 +- local/bin/x-load-configs | 47 ++++++++++++++------------ scripts/install-cargo-packages.sh | 6 ++-- scripts/install-cheat-purebashbible.sh | 2 +- scripts/install-cheat-tldr.sh | 2 +- scripts/install-composer.sh | 2 +- scripts/install-gh-extensions.sh | 2 +- scripts/install-git-crypt.sh | 2 +- scripts/install-go-packages.sh | 4 +-- scripts/install-neofetch.sh | 2 +- scripts/install-npm-packages.sh | 2 +- scripts/install-ntfy.sh | 2 +- scripts/install-pip-packages.sh | 2 +- scripts/install-xcode-cli-tools.sh | 2 +- scripts/shared.sh | 40 ---------------------- 19 files changed, 59 insertions(+), 111 deletions(-) diff --git a/base/bashrc b/base/bashrc index 5f54f03..3f1702b 100644 --- a/base/bashrc +++ b/base/bashrc @@ -18,11 +18,7 @@ export XDG_RUNTIME_DIR="$HOME/.local/run" # Paths export PATH="$XDG_BIN_HOME:$DOTFILES/local/bin:$HOME/.local/go/bin:$XDG_DATA_HOME/cargo/bin:$PATH" -# shellcheck source=scripts/shared.sh -# source "$DOTFILES/scripts/shared.sh" - -source "$DOTFILES/config/exports" -source "$DOTFILES/config/alias" +x-load-configs # shellcheck source=../config/fzf/fzf.bash [ -f "${DOTFILES}/config/fzf/fzf.bash" ] && diff --git a/base/zshrc b/base/zshrc index 35e253f..9c1cb1d 100755 --- a/base/zshrc +++ b/base/zshrc @@ -14,28 +14,17 @@ export XDG_BIN_HOME="$HOME/.local/bin" export XDG_CACHE_HOME="$HOME/.cache" export XDG_RUNTIME_DIR="$HOME/.local/run" -export PATH="$XDG_BIN_HOME:$DOTFILES/local/bin:$HOME/.local/go/bin:$XDG_DATA_HOME/cargo/bin:$PATH" +export PATH="$XDG_BIN_HOME:$DOTFILES/local/bin:$HOME/.local/go/bin:$XDG_DATA_HOME/bob/nvim-bin:$XDG_DATA_HOME/cargo/bin:/opt/homebrew/bin:/usr/local/bin:$PATH" -source "$DOTFILES/config/exports" -source "$DOTFILES/config/alias" -source "$DOTFILES/config/functions" - -source "$DOTFILES/scripts/shared.sh" +x-load-configs export COMPLETION_WAITING_DOTS=true -path_append "/opt/homebrew/bin" if type brew &> /dev/null; then eval "$(brew shellenv)" FPATH="$HOMEBREW_PREFIX/share/zsh/site-functions:${FPATH}" fi -path_append "/usr/local/bin" -path_prepend "$XDG_DATA_HOME/cargo/bin" -path_prepend "$XDG_BIN_HOME" -path_prepend "$HOME/.local/go/bin" -path_prepend "$XDG_DATA_HOME/bob/nvim-bin" - export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion" x-dc "$ZSH_CUSTOM_COMPLETION_PATH" diff --git a/config/alias b/config/alias index b697dea..066ae6d 100755 --- a/config/alias +++ b/config/alias @@ -61,7 +61,6 @@ alias please="sudo " # Color the grep output alias grep='grep --color' -! x-have eza && alias ls='ls --color=auto' x-have eza && { alias ls='eza -h -s=type --git --icons --group-directories-first' } @@ -148,13 +147,13 @@ alias wget="wget --hsts-file=$XDG_DATA_HOME/wget-hsts" alias svn="svn --config-dir $XDG_CONFIG_HOME/subversion" # Alacritty preexec hook to update dynamic title -preexec() +function preexec() { print -Pn "\e]0;$1%~\a" } # Update dotfiles -dfu() +function dfu() { ( cd "$DOTFILES" && git pull --ff-only && ./install -q @@ -162,7 +161,7 @@ dfu() } # Weather in Tampere, or other city -weather() +function weather() { # https://github.com/chubin/wttr.in#usage local city="${1:-Tampere}" @@ -170,19 +169,19 @@ weather() } # Docker -ssh-docker() +function ssh-docker() { docker exec -it "$@" bash } # All the dig info -digga() +function digga() { dig +nocmd "$1" any +multiline +noall +answer } # Rector project to php version 8.2 by default. -rector() +function rector() { local php="${1:-82}" docker run -v "$(pwd)":/project rector/rector:latest process \ @@ -192,7 +191,7 @@ rector() } # Commit everything -commit() +function commit() { commitMessage="$*" @@ -204,7 +203,7 @@ commit() eval "git commit -a -m '${commitMessage}'" } -scheduler() +function scheduler() { while :; do php artisan schedule:run diff --git a/config/exports-apps b/config/exports-apps index 92b0fb3..4094cbb 100755 --- a/config/exports-apps +++ b/config/exports-apps @@ -21,15 +21,14 @@ x-dc "$ANSIBLE_GALAXY_CACHE_DIR" export ANDROID_HOME="$XDG_DATA_HOME/android" # bob manages nvim versions -x-path-prepend "$XDG_DATA_HOME/bob/nvim-bin" -x-have nvim && export EDITOR="nvim" +export PATH="$XDG_DATA_HOME/bob/nvim-bin:$PATH" export HOMEBREW_NO_ENV_HINTS=true # composer, https://getcomposer.org/ export COMPOSER_HOME="$XDG_STATE_HOME/composer" export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin" -x-path-append "$COMPOSER_BIN" +export PATH="$COMPOSER_BIN:$PATH" # docker, https://docs.docker.com/engine/reference/commandline/cli/ export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker" @@ -55,7 +54,7 @@ export NB_DIR="$XDG_STATE_HOME/nb" # NPM: Add npm packages to path x-have node && { NVM_NODE_BIN_DIR="$(dirname "$(which node)")" - x-path-append "$NVM_NODE_BIN_DIR" + export PATH="$NVM_NODE_BIN_DIR:$PATH" } # op (1Password cli) is present @@ -73,7 +72,7 @@ x-have op && { export WORKON_HOME="$XDG_DATA_HOME/virtualenvs" export PYENV_ROOT="$XDG_STATE_HOME/pyenv" x-have pyenv && { - x-path-append "$PYENV_ROOT/shims" + export PATH="$PYENV_ROOT/shims:$PATH" eval "$(pyenv init -)" } @@ -87,7 +86,7 @@ export BUNDLE_USER_CACHE="$XDG_CACHE_HOME"/bundle export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle export RBENV_ROOT="$XDG_STATE_HOME/rbenv" x-dc "$RBENV_ROOT" -x-have gem && x-path-append "${GEM_HOME}/bin" +x-have gem && export PATH="${GEM_HOME}/bin:$PATH" x-have rbenv && { [ "$DOTFILES_CURRENT_SHELL" = "zsh" ] && eval "$(rbenv init - zsh)" [ "$DOTFILES_CURRENT_SHELL" = "bash" ] && eval "$(rbenv init - bash)" @@ -96,7 +95,7 @@ x-have rbenv && { # Rust / cargo export RUSTUP_HOME="$XDG_DATA_HOME/rustup" export CARGO_HOME="$XDG_DATA_HOME/cargo" -x-path-append "$CARGO_HOME/bin" +export PATH="$CARGO_HOME/bin:$PATH" # screen export SCREENRC="$XDG_CONFIG_HOME/misc/screenrc" diff --git a/config/exports-lakka b/config/exports-lakka index 95d5ed3..c75cbab 100644 --- a/config/exports-lakka +++ b/config/exports-lakka @@ -3,7 +3,7 @@ ## LUA have luarocks && $(luarocks path --bin) -path_prepend "$HOME/.local/go/bin" +export PATH="$HOME/.local/go/bin:$PATH" alias logrotate='/usr/sbin/logrotate -s $HOME/logs/state' alias nano='nano -wS -$' diff --git a/local/bin/x-load-configs b/local/bin/x-load-configs index 563a10f..dbd6aed 100755 --- a/local/bin/x-load-configs +++ b/local/bin/x-load-configs @@ -2,30 +2,35 @@ # Load our configuration files # Copyright (c) 2023 Ismo Vuorinen. All Rights Reserved. +# Set verbosity with VERBOSE=1 x-load-configs +: "${VERBOSE:0}" + DOTFILES="$HOME/.dotfiles" -source "$HOME/.dotfiles/scripts/shared.sh" CONFIG_PATH="$DOTFILES/config" # Load the shell dotfiles, and then some: -function x-load-config-fn() -{ - for FILE in $CONFIG_PATH/{exports,alias,functions}; do - FILENAME="$FILE" - HOST="$(hostname -s)" - # global (exports|alias|functions) FILENAME for all hosts - # shellcheck source=../config/exports - [ -r "$FILENAME" ] && source "$FILENAME" - # global secret FILENAME, git ignored - # shellcheck source=../config/exports-secret - [ -r "$FILENAME-secret" ] && source "$FILENAME-secret" - # host specific (exports|alias|functions) FILENAME - # shellcheck source=../config/exports - [ -r "$FILENAME-$HOST" ] && source "$FILENAME-$HOST" - # host specific (exports|alias|functions) FILENAME, git ignored - # shellcheck source=../config/exports - [ -r "$FILENAME-$HOST-secret" ] && source "$FILENAME-$HOST-secret" - done +HOST="$(hostname -s)" +[ "$VERBOSE" = "1" ] && { + echo "x-load-config-fn: VERBOSE=1" + echo "x-load-config-fn: HOST: $HOST" } - -x-load-config-fn +for FILE in $CONFIG_PATH/{exports,alias,functions}; do + FILENAME="$FILE" + # global (exports|alias|functions) FILENAME for all hosts + # shellcheck source=../config/exports + [ -r "$FILENAME" ] && source "$FILENAME" \ + && [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME" + # global secret FILENAME, git ignored + # shellcheck source=../config/exports-secret + [ -r "$FILENAME-secret" ] && source "$FILENAME-secret" \ + && [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME-secret" + # host specific (exports|alias|functions) FILENAME + # shellcheck source=../config/exports + [ -r "$FILENAME-$HOST" ] && source "$FILENAME-$HOST" \ + && [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME-$HOST" + # host specific (exports|alias|functions) FILENAME, git ignored + # shellcheck source=../config/exports + [ -r "$FILENAME-$HOST-secret" ] && source "$FILENAME-$HOST-secret" \ + && [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME-$HOST-secret" +done diff --git a/scripts/install-cargo-packages.sh b/scripts/install-cargo-packages.sh index 5139f99..455b9ed 100755 --- a/scripts/install-cargo-packages.sh +++ b/scripts/install-cargo-packages.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg "Starting to install rust/cargo packages" -[[ $(x-have "cargo") == "1" ]] && { +! x-have cargo && { msg "cargo could not be found. installing cargo with rustup.rs" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path } @@ -53,8 +53,8 @@ msg_done "Installed cargo packages!" msg_run "Now doing the next steps for cargo packages" # use bob to install nvim -have bob && { - bob use stable && path_append "$XDG_DATA_HOME/bob/nvim-bin" +x-have bob && { + bob use stable && x-path-append "$XDG_DATA_HOME/bob/nvim-bin" } msg_done "All next steps done!" diff --git a/scripts/install-cheat-purebashbible.sh b/scripts/install-cheat-purebashbible.sh index ecdc737..29daafd 100755 --- a/scripts/install-cheat-purebashbible.sh +++ b/scripts/install-cheat-purebashbible.sh @@ -5,7 +5,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" PBB_REQUIRED_TOOLS=(git cheat) for t in ${PBB_REQUIRED_TOOLS[@]}; do - [[ $(x-have "$t") == "1" ]] && echo "(!) $t is missing, can't continue..." && exit 1 + ! x-have "$t" && echo "(!) $t is missing, can't continue..." && exit 1 done PBB_GIT="https://github.com/dylanaraps/pure-bash-bible.git" diff --git a/scripts/install-cheat-tldr.sh b/scripts/install-cheat-tldr.sh index e852c46..df1e641 100755 --- a/scripts/install-cheat-tldr.sh +++ b/scripts/install-cheat-tldr.sh @@ -5,7 +5,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" TLDR_REQUIRED_TOOLS=(git cheat) for t in ${TLDR_REQUIRED_TOOLS[@]}; do - [[ $(x-have "$t") == "1" ]] && echo "(!) $t is missing, can't continue..." && exit 1 + ! x-have "$t" && echo "(!) $t is missing, can't continue..." && exit 1 done TLDR_GIT="https://github.com/tldr-pages/tldr.git" diff --git a/scripts/install-composer.sh b/scripts/install-composer.sh index 1d2458e..b77c6e3 100755 --- a/scripts/install-composer.sh +++ b/scripts/install-composer.sh @@ -4,7 +4,7 @@ # shellcheck source="shared.sh" source "$HOME/.dotfiles/scripts/shared.sh" -[[ $(x-have "php") == "1" ]] && msg_err "PHP Not Available, cannot install composer" && exit 0 +! x-have "php" && msg_err "PHP Not Available, cannot install composer" && exit 0 EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" diff --git a/scripts/install-gh-extensions.sh b/scripts/install-gh-extensions.sh index 3b89940..e307859 100755 --- a/scripts/install-gh-extensions.sh +++ b/scripts/install-gh-extensions.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg_run "Installing gh (GitHub Client) extensions" -[[ $(x-have "gh") == "1" ]] \ +! x-have "gh" \ && msg_err "gh (GitHub Client) could not be found, please install it first" \ && exit 0 diff --git a/scripts/install-git-crypt.sh b/scripts/install-git-crypt.sh index 71f0e6d..e7c0a3b 100755 --- a/scripts/install-git-crypt.sh +++ b/scripts/install-git-crypt.sh @@ -8,7 +8,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg_run "Installing git-crypt" -[[ $(x-have "git-crypt") == "1" ]] && { +x-have "git-crypt" || { REPO_URL="https://github.com/AGWA/git-crypt.git" CHECK_PATH="${XDG_BIN_HOME}/git-crypt" diff --git a/scripts/install-go-packages.sh b/scripts/install-go-packages.sh index 9b6b47b..1d5521d 100755 --- a/scripts/install-go-packages.sh +++ b/scripts/install-go-packages.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg_run "Installing go packages" -[[ $(x-have "go") == "1" ]] && msg "go hasn't been installed yet." && exit 0 +! x-have "go" && msg "go hasn't been installed yet." && exit 0 packages=( # A shell parser, formatter, and interpreter with bash support; includes shfmt @@ -44,7 +44,7 @@ done msg_run "Installing completions for selected packages" -have git-profile && { +x-have git-profile && { git-profile completion zsh > "$ZSH_CUSTOM_COMPLETION_PATH/_git-profile" \ && msg_ok "Installed completions for git-profile" } diff --git a/scripts/install-neofetch.sh b/scripts/install-neofetch.sh index 0aa01ce..290acae 100755 --- a/scripts/install-neofetch.sh +++ b/scripts/install-neofetch.sh @@ -11,7 +11,7 @@ NEOFETCH_URL="${NEOFETCH_REPO}/archive/refs/tags/${NEOFETCH_VERSION}.tar.gz" NEOFETCH_TEMP="/tmp/neofetch" NEOFETCH_INSTALL_PREFIX="$HOME/.local" -[[ $(x-have "neofetch") == "1" ]] && { +x-have "neofetch" || { LC_ALL=C mkdir -p "$NEOFETCH_TEMP" "$NEOFETCH_INSTALL_PREFIX" diff --git a/scripts/install-npm-packages.sh b/scripts/install-npm-packages.sh index 20df8bb..7e41720 100755 --- a/scripts/install-npm-packages.sh +++ b/scripts/install-npm-packages.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg "Starting to install npm packages" -[[ $(x-have "npm") == "1" ]] && msg_err "npm could not be found." && exit 0 +! x-have "npm" && msg_err "npm could not be found." && exit 0 packages=( # This is a tool to check if your files consider your .editorconfig rules. diff --git a/scripts/install-ntfy.sh b/scripts/install-ntfy.sh index cda813a..2e05738 100755 --- a/scripts/install-ntfy.sh +++ b/scripts/install-ntfy.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" set -e -[[ $(x-have "ntfy") == "0" ]] && msg "ntfy already installed" && exit 0 +x-have "ntfy" && msg "ntfy already installed" && exit 0 case $(dfm check arch) in Linux) diff --git a/scripts/install-pip-packages.sh b/scripts/install-pip-packages.sh index de75538..1caf803 100755 --- a/scripts/install-pip-packages.sh +++ b/scripts/install-pip-packages.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg "Starting to install pip packages" -[[ $(x-have "python3") == "1" ]] && { +x-have "python3" || { msg_err "Could not find python3, something really weird is going on." && exit 1 } diff --git a/scripts/install-xcode-cli-tools.sh b/scripts/install-xcode-cli-tools.sh index 25df175..5c1e8f2 100755 --- a/scripts/install-xcode-cli-tools.sh +++ b/scripts/install-xcode-cli-tools.sh @@ -6,7 +6,7 @@ [ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0 -! have xcode-select \ +! x-have xcode-select \ && msg_err "xcode-select could not be found, skipping" \ && exit 0 diff --git a/scripts/shared.sh b/scripts/shared.sh index 2377380..b231be1 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -50,21 +50,6 @@ function path_prepend x-path-prepend "$1" } -# Create directory if it doesn't exist already -x-dc() -{ - dir="$1" - - [ $# -eq 0 ] && { - echo "Usage: $0 full/path/to/dir/to/create" - exit 1 - } - - if [ ! -d "$dir" ]; then - mkdir -p "$dir" && exit 0 - fi -} - # Create a new directory and enter it mkd() { @@ -84,31 +69,6 @@ nonascii() LC_ALL=C grep -n '[^[:print:][:space:]]' "${@}" } -CONFIG_PATH="$DOTFILES/config" - -# Load the shell dotfiles, and then some: -function x-load-config-fn() -{ - for FILE in $CONFIG_PATH/{exports,alias,functions}; do - FILENAME="$FILE" - HOST="$(hostname -s)" - # global (exports|alias|functions) FILENAME for all hosts - # shellcheck source=../config/exports - [ -r "$FILENAME" ] && source "$FILENAME" - # global secret FILENAME, git ignored - # shellcheck source=../config/exports-secret - [ -r "$FILENAME-secret" ] && source "$FILENAME-secret" - # host specific (exports|alias|functions) FILENAME - # shellcheck source=../config/exports - [ -r "$FILENAME-$HOST" ] && source "$FILENAME-$HOST" - # host specific (exports|alias|functions) FILENAME, git ignored - # shellcheck source=../config/exports - [ -r "$FILENAME-$HOST-secret" ] && source "$FILENAME-$HOST-secret" - done -} - -x-load-config-fn - source "$DOTFILES/local/bin/msgr" # -- Menu builder -- #