From c9bc6e597a9865f2fdb35bbc5787855cf761b833 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Fri, 17 Mar 2023 13:37:58 +0200 Subject: [PATCH] host-* to hosts/*, dfm rework, renaming and stuff --- base/bashrc | 114 ++++++++++++++++-- {host-air => hosts/air}/.gitkeep | 0 {host-air => hosts/air}/README.md | 2 +- {host-lakka => hosts/lakka}/irssi/config | 0 .../lakka}/irssi/default.theme | 0 {host-lakka => hosts/lakka}/zshrc | 0 {host-tunkki => hosts/tunkki}/bash_logout | 0 {host-tunkki => hosts/tunkki}/bashrc | 0 {host-v => hosts/v}/.gitkeep | 0 {host-v => hosts/v}/README.md | 2 +- {host-v => hosts/v}/config/git/config | 0 install.conf.yaml | 68 +++++++---- local/bin/dfm | 39 +++++- scripts/install-gh-extensions.sh | 53 -------- ...{settler.sh => install-xcode-cli-tools.sh} | 2 +- 15 files changed, 182 insertions(+), 98 deletions(-) rename {host-air => hosts/air}/.gitkeep (100%) rename {host-air => hosts/air}/README.md (55%) rename {host-lakka => hosts/lakka}/irssi/config (100%) rename {host-lakka => hosts/lakka}/irssi/default.theme (100%) rename {host-lakka => hosts/lakka}/zshrc (100%) rename {host-tunkki => hosts/tunkki}/bash_logout (100%) rename {host-tunkki => hosts/tunkki}/bashrc (100%) rename {host-v => hosts/v}/.gitkeep (100%) rename {host-v => hosts/v}/README.md (57%) rename {host-v => hosts/v}/config/git/config (100%) delete mode 100755 scripts/install-gh-extensions.sh rename scripts/{settler.sh => install-xcode-cli-tools.sh} (94%) diff --git a/base/bashrc b/base/bashrc index a20758c..742fe8a 100644 --- a/base/bashrc +++ b/base/bashrc @@ -1,21 +1,113 @@ # shellcheck shell=bash -# Fig pre block. Keep at the top of this file. -[[ -f "$HOME/.fig/shell/bashrc.pre.bash" ]] && builtin source "$HOME/.fig/shell/bashrc.pre.bash" +# Defaults +export DOTFILES="$HOME/.dotfiles" +# Explicitly set XDG folders +# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html +export XDG_DATA_HOME="$HOME/.local/share" +export XDG_CONFIG_HOME="$HOME/.config" +export XDG_STATE_HOME="$HOME/.local/state" +export XDG_BIN_HOME="$HOME/.local/bin" # this one is custom + +# Homebrew configuration +export HOMEBREW="/opt/homebrew" +export HOMEBREW_BIN="$HOMEBREW/bin" +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" + +# brew, https://brew.sh if command -v brew &> /dev/null; then - PHP_PATH=$(brew --prefix php)/bin - export PATH="$PHP_PATH:$HOME/.composer/vendor/bin/:/usr/local/sbin:$PATH" + BREW_BIN=$(brew --prefix)/bin + BREW_SBIN=$(brew --prefix)/sbin + + BREW_PYTHON=$(brew --prefix python@3.8)/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:$BREW_BIN:$BREW_SBIN:$PATH" fi -if command -v nvm &> /dev/null; then - export NVM_DIR="$HOME/.nvm" - [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm - [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion +# nvm, the node version manager +export NVM_LAZY_LOAD=true +export NVM_COMPLETION=true +export NVM_AUTO_USE=true +export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + +# If we have go packages, include them to the PATH +if command -v go &> /dev/null; then + export GOPATH=$(go env GOPATH); + if [ -d "$GOPATH/bin" ]; then + export PATH="$GOPATH/bin:$PATH" + fi +fi + +if command -v nvim &> /dev/null; then + export EDITOR="nvim" +fi + +# z, https://github.com/rupa/z +export _Z_DATA="$XDG_STATE_HOME/z" + +# composer, https://getcomposer.org/ +if command -v composer &> /dev/null; then + export COMPOSER_HOME="$XDG_STATE_HOME/composer" + export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin" + export PATH="$COMPOSER_BIN:$PATH" +fi + +# gem, rubygems +if command -v gem &>/dev/null; then + export GEM_HOME="$XDG_STATE_HOME/gem" + export GEM_PATH="$XDG_STATE_HOME/gem" fi +# wakatime, https://github.com/wakatime/wakatime-cli +export WAKATIME_HOME="$XDG_STATE_HOME/wakatime" -# Fig post block. Keep at the bottom of this file. -[[ -f "$HOME/.fig/shell/bashrc.post.bash" ]] && builtin source "$HOME/.fig/shell/bashrc.post.bash" -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +# Run x-load-configs in your terminal to reload the files. +function x-load-configs() +{ + # Load the shell dotfiles, and then some: + for file in $DOTFILES/config/{exports,alias,functions}; do + [ -r "$file" ] && [ -f "$file" ] && source "$file" + [ -r "$file-secret" ] && [ -f "$file-secret" ] && source "$file-secret" + [ -r "$file-$HOSTNAME" ] && [ -f "$file-$HOSTNAME" ] && source "$file-$HOSTNAME" + [ -r "$file-$HOSTNAME-secret" ] && [ -f "$file-$HOSTNAME-secret" ] && source "$file-$HOSTNAME-secret" + done +} +x-load-configs + +# Import ssh keys in keychain +ssh-add -A 2>/dev/null; + +# op (1Password cli) is present +if hash op 2>/dev/null; then + export OP_CACHE="$XDG_STATE_HOME/1password" + mkdir -p "$OP_CACHE"; + eval "$(op completion zsh)"; compdef _op op +fi + +# Ansible configuration +# https://docs.ansible.com/ansible/latest/reference_appendices/config.html +if hash ansible 2>/dev/null; then + export ANSIBLE_HOME="$XDG_STATE_HOME/ansible" + mkdir -p "$ANSIBLE_HOME" +fi + +# gcloud is present +#if hash gcloud 2>/dev/null; then +# 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 + +# Load iterm2 shell integration +# https://iterm2.com/documentation-shell-integration.html +[[ -f "$XDG_BIN_HOME/iterm2_shell_integration.zsh" ]] && source "$XDG_BIN_HOME/iterm2_shell_integration.zsh" diff --git a/host-air/.gitkeep b/hosts/air/.gitkeep similarity index 100% rename from host-air/.gitkeep rename to hosts/air/.gitkeep diff --git a/host-air/README.md b/hosts/air/README.md similarity index 55% rename from host-air/README.md rename to hosts/air/README.md index a17ab91..cfae3fc 100644 --- a/host-air/README.md +++ b/hosts/air/README.md @@ -1,3 +1,3 @@ -# .dotfiles/host-air +# .dotfiles/hosts/air This is my home computer. diff --git a/host-lakka/irssi/config b/hosts/lakka/irssi/config similarity index 100% rename from host-lakka/irssi/config rename to hosts/lakka/irssi/config diff --git a/host-lakka/irssi/default.theme b/hosts/lakka/irssi/default.theme similarity index 100% rename from host-lakka/irssi/default.theme rename to hosts/lakka/irssi/default.theme diff --git a/host-lakka/zshrc b/hosts/lakka/zshrc similarity index 100% rename from host-lakka/zshrc rename to hosts/lakka/zshrc diff --git a/host-tunkki/bash_logout b/hosts/tunkki/bash_logout similarity index 100% rename from host-tunkki/bash_logout rename to hosts/tunkki/bash_logout diff --git a/host-tunkki/bashrc b/hosts/tunkki/bashrc similarity index 100% rename from host-tunkki/bashrc rename to hosts/tunkki/bashrc diff --git a/host-v/.gitkeep b/hosts/v/.gitkeep similarity index 100% rename from host-v/.gitkeep rename to hosts/v/.gitkeep diff --git a/host-v/README.md b/hosts/v/README.md similarity index 57% rename from host-v/README.md rename to hosts/v/README.md index 3abfc4c..f61fbf6 100644 --- a/host-v/README.md +++ b/hosts/v/README.md @@ -1,3 +1,3 @@ -# .dotfiles/host-v +# .dotfiles/hosts/v This is my work computer. diff --git a/host-v/config/git/config b/hosts/v/config/git/config similarity index 100% rename from host-v/config/git/config rename to hosts/v/config/git/config diff --git a/install.conf.yaml b/install.conf.yaml index 045fbe1..cab3a4b 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -44,57 +44,75 @@ path: base/** prefix: '.' -- shell: [git submodule update --init --recursive --force, Installing submodules] +- shell: + - [git submodule update --init --recursive --force] + - [bash scripts/set-macos-defaults.sh] + - [bash scripts/install-npm-packages.sh] +- brewfile: + - Brewfile + +- go: + - github.com/skx/sysbox@latest + +# hosts: air - if: - - cond: "[ $(uname) = Darwin ]" + - cond: '[[ $(hostname) = air ]]' met: - - shell: - - echo "Darwin system" - - [brew bundle install --file="Brewfile", Installing Brewfile contents] - - cond: "[[ $(hostname) = v ]]" - met: - - shell: - - echo "host is v" - - link: - ~/.config/*: - force: true - glob: true - path: host-v/config/** - go: - - github.com/delicb/cliware - github.com/skx/sysbox@latest - - cond: "[[ $(hostname) = lakka ]]" + +# hosts: v +- if: + - cond: '[[ $(hostname) = v ]]' + met: + - link: + ~/.config/: + glob: true + force: true + path: hosts/v/config/** + - go: + - github.com/skx/sysbox@latest + +# hosts: lakka +- if: + - cond: '[[ $(hostname) = lakka ]]' met: - - shell: - - echo "host is lakka" - link: ~/.irssi/*: force: true glob: true - path: host-lakka/irssi/** + path: hosts/lakka/irssi/** ~/.zshrc*: force: true - path: host-lakka/zshrc - - cond: "command -v npm" - met: - - shell: - - echo "we have npm" - - ["$HOME/.dotfiles/scripts/install-npm-packages.sh", Installing npm packages] + path: hosts/lakka/zshrc # GitHub CLI Extensions - ghe: + # GitHub CLI extension for generating a report on repository dependencies. - andyfeller/gh-dependency-report + # GitHub CLI extension to generate montage from GitHub user avatars - andyfeller/gh-montage + # An opinionated GitHub Cli extension for creating + # changelogs that adhere to the keep a changelog specification. - chelnak/gh-changelog + # Safely deletes local branches with no upstream and no un-pushed commits - davidraviv/gh-clean-branches + # A beautiful CLI dashboard for GitHub 🚀 - dlvhdr/gh-dash + # GitHub CLI extension for reviewing Dependabot PRs. - einride/gh-dependabot + # A GitHub CLI extension that provides summary pull request metrics. - hectcastro/gh-metrics + # A github-cli extension script to clone all repositories + # in an organization, optionally filtering by topic. - matt-bartel/gh-clone-org + # being an extension to view the overall health of an organization's use of actions - rsese/gh-actions-status - samcoe/gh-triage + # Generate account/organization/enterprise reports - stoe/gh-report + # Organisation specific extension for gh cli to retrieve different statistics - VildMedPap/gh-orgstats - vilmibm/gh-screensaver - vilmibm/gh-user-status diff --git a/local/bin/dfm b/local/bin/dfm index 8a1e0a1..2181ad2 100755 --- a/local/bin/dfm +++ b/local/bin/dfm @@ -11,6 +11,7 @@ : "${DOTFILES:=$HOME/.dotfiles}" : "${INSTALL_SCRIPT:=$DOTFILES/scripts/install-dotfiles.sh}" : "${BREWFILE:=$DOTFILES/Brewfile}" +: "${HOSTFILES:=$DOTFILES/hosts}" SCRIPT=$(basename "$0") @@ -26,7 +27,7 @@ function section_install $0 install antigen $0 install starship $0 install macos - $0 install ext_npm + $0 install npm ;; antigen) curl -L git.io/antigen > "$DOTFILES/local/bin/antigen.zsh" && msg_done "🎉 New antigen installed!" @@ -37,18 +38,18 @@ function section_install macos) bash "$DOTFILES/scripts/set-macos-defaults.sh" && msg_done "🎉 Brewfile defined apps has been installed!" ;; - ext_npm) + npm) bash "$DOTFILES/scripts/install-npm-packages.sh" && msg_done "NPM Packages have been installed!" ;; settler) bash "$DOTFILES/scripts/settler.sh" && msg_done "🎉 Settler has been run!" ;; *) - menu_section "$USAGE_PREFIX" "all | antigen | starship | ext_npm | macos | settler" + menu_section "$USAGE_PREFIX" "all | antigen | starship | npm | macos | settler" menu_item "all" "Installs antigen, macos, brew and ext_gh" menu_item "antigen" "Updates the antigen.zsh file" menu_item "starship" "Install starship.rs" - menu_item "ext_npm" "Install NPM Packages" + menu_item "npm" "Install NPM Packages" menu_item "macos" "Setup nice macOS defaults" menu_item "settler" "Runs the WIP settler.sh" ;; @@ -112,7 +113,7 @@ function section_dotfiles 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 ext_npm + hash npm 2>/dev/null && $0 install npm msg_ok "Installed packages" msg_done "...and we are done!" ;; @@ -132,6 +133,29 @@ function section_dotfiles esac } +function section_check +{ + USAGE_PREFIX="$SCRIPT check" + X_HOSTNAME=$(hostname) + X_ARCH=$(uname) + + case "$1" in + a|arch) + [[ "$2" = "" ]] && echo "$X_ARCH" && exit 0 + [[ $X_ARCH = "$2" ]] && exit 0 || exit 1 + ;; + h|host|hostname) + [[ "$2" = "" ]] && echo "$X_HOSTNAME" && exit 0 + [[ $X_HOSTNAME = "$2" ]] && exit 0 || exit 1 + ;; + *) + menu_section "$USAGE_PREFIX" "arch | host" + menu_item "arch " "Empty returns current. Exit code 0 when match, 1 when not." + menu_item "host " "Empty returns current. Exit code 0 when match, 1 when not." + ;; + esac +} + # Secret menu for visual tests function section_tests { @@ -160,13 +184,15 @@ function section_tests function usage { echo "" - menu_section "Usage: $SCRIPT" "install | reset | brew | dotfiles" + menu_section "Usage: $SCRIPT" "install | reset | brew | check | dotfiles" echo $" All commands have their own subcommands." echo "" section_install echo "" section_brew echo "" + section_check + echo "" section_dotfiles } @@ -174,6 +200,7 @@ function usage case "$1" in install) section_install "$2" ;; brew) section_brew "$2" ;; + check) section_check "$2" ;; dotfiles) section_dotfiles "$2" ;; tests) section_tests "$2" ;; *) usage && exit 0 ;; diff --git a/scripts/install-gh-extensions.sh b/scripts/install-gh-extensions.sh deleted file mode 100755 index d00b32b..0000000 --- a/scripts/install-gh-extensions.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -# Install GitHub CLI extensions -# -# 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 - extensions=( - # GitHub CLI extension for reviewing Dependabot PRs. - einride/gh-dependabot - # A GitHub CLI extension that provides summary pull request metrics. - hectcastro/gh-metrics - # being an extension to view the overall health of an organization's use of actions - rsese/gh-actions-status - # GitHub CLI extension for label management - heaths/gh-label - # An opinionated GitHub Cli extension for creating - # changelogs that adhere to the keep a changelog specification. - chelnak/gh-changelog - # Safely deletes local branches with no upstream and no un-pushed commits - davidraviv/gh-clean-branches - # A beautiful CLI dashboard for GitHub 🚀 - dlvhdr/gh-dash - # A github-cli extension script to clone all repositories - # in an organization, optionally filtering by topic. - matt-bartel/gh-clone-org - # GitHub CLI extension to generate montage from GitHub user avatars - andyfeller/gh-montage - # Organisation specific extension for gh cli to retrieve different statistics - VildMedPap/gh-orgstats - # GitHub CLI extension for generating a report on repository dependencies. - andyfeller/gh-dependency-report - # gh cli extension to generate account/organization/enterprise reports - stoe/gh-report - ) - - msg "Starting to install GitHub CLI extensions..." - - for ext in "${extensions[@]}"; do - # Trim spaces - ext=${ext// /} - # Skip comments - if [[ ${ext:0:1} == "#" ]]; then continue; fi - - msg_run "Installing $ext" - gh extensions install "$ext" - echo "" - done - - msg_ok "Done" -fi diff --git a/scripts/settler.sh b/scripts/install-xcode-cli-tools.sh similarity index 94% rename from scripts/settler.sh rename to scripts/install-xcode-cli-tools.sh index c270fd1..24044c0 100755 --- a/scripts/settler.sh +++ b/scripts/install-xcode-cli-tools.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Settler - my macOS setup automator +# Install XCode CLI Tools with osascript magic. # Ismo Vuorinen 2018 #