From 95774f8c9cb61f4ddbbf7249150b92a555743f62 Mon Sep 17 00:00:00 2001 From: "david@david-m2" <3200210+davidjenni@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:08:29 -0800 Subject: [PATCH 1/5] config.fish correctly initialize brew for macOS and linux --- fish/config.fish | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fish/config.fish b/fish/config.fish index 2151843..beaf251 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -10,13 +10,15 @@ set fish_greeting "" switch (uname) case Linux + if test -d /home/linuxbrew/.linuxbrew/bin + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + end if test -x /usr/bin/lesspipe.sh set -x LESSOPEN "|lesspipe.sh %s" end case Darwin if test -d /opt/homebrew/bin - fish_add_path /opt/homebrew/bin - set -g fish_user_paths "(brew --prefix)/bin" $fish_user_paths + eval "$(brew shellenv)" if test -x (brew --prefix)/bin/lesspipe.sh set -x LESSOPEN "|lesspipe.sh %s" end From 3a7f981c201bd3674d11263f23ca7b82af804518 Mon Sep 17 00:00:00 2001 From: "david@DAVID-PC" <3200210+davidjenni@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:59:16 -0800 Subject: [PATCH 2/5] use Homebrew's linuxbrew to install productivity apps in WSL/Ubuntu --- README.md | 4 +-- bash/bash_aliases | 13 +++++++++ bootstrap.sh | 70 ++++++++++++++++++++--------------------------- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index c826c90..b5cabb4 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ irm 'https://raw.githubusercontent.com/davidjenni/dotfiles/main/bootstrap.ps1' | to bootstrap, run this in a default Terminal.app prompt: ````shell - curl -fsSL https://github.com/davidjenni/dotfiles/raw/master/bootstrap.sh | bash +curl -fsSL https://raw.githubusercontent.com/davidjenni/dotfiles/main/bootstrap.sh | bash ```` ### Linux (Ubuntu/Debian) @@ -29,5 +29,5 @@ still missing apps! * open terminal/WSL: ````shell - curl -fsSL https://github.com/davidjenni/dotfiles/raw/master/bootstrap.sh | bash +curl -fsSL https://raw.githubusercontent.com/davidjenni/dotfiles/main/bootstrap.sh | bash ```` diff --git a/bash/bash_aliases b/bash/bash_aliases index b9a8c6f..1ac820c 100644 --- a/bash/bash_aliases +++ b/bash/bash_aliases @@ -23,3 +23,16 @@ if uname -r | grep -q "WSL"; then alias ssh='ssh.exe' alias ssh-add='ssh-add.exe' fi + +case `uname` in + 'Darwin') + if [ -d "/opt/homebrew/bin" ] ; then + eval "$(/opt/homebrew/bin/brew shellenv)" ;; + fi + ;; + 'Linux') + if [ -d "home/linuxbrew/.linuxbrew/bin" ] ; then + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" ;; + fi + ;; +esac diff --git a/bootstrap.sh b/bootstrap.sh index 2c42113..34d891a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,4 +1,6 @@ #!/bin/bash +# install with: +# > curl -fsSL https://raw.githubusercontent.com/davidjenni/dotfiles/main/bootstrap.sh | bash originGitHub='https://github.com/davidjenni/dotfiles.git' dotPath=$HOME/dotfiles @@ -65,9 +67,23 @@ function ensureBrew { brew update return fi + case `uname` in + 'Darwin') + xcode-select --install + ;; + 'Linux') + sudo apt-get install -y build-essential procps curl file git + ;; + esac echo "Installing Homebrew..." - # TODO: Test brew install + # https://brew.sh/ + # https://docs.brew.sh/Homebrew-on-Linux NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + case `uname` in + 'Darwin') eval "$(/opt/homebrew/bin/brew shellenv)" ;; + 'Linux') eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" ;; + esac + # TODO: Test brew install } function cloneDotFiles { @@ -84,7 +100,7 @@ function cloneDotFiles { git clone $originGitHub $dotPath } -function installAppsMacOS { +function installApps { echo "Installing apps via brew..." local var apps=( 7zip @@ -113,6 +129,7 @@ function installAppsMacOS { alacritty font-jetbrains-mono-nerd-font ) + local var _apps=${apps[*]} echo ">> brew install $_apps" brew install $_apps @@ -120,38 +137,15 @@ function installAppsMacOS { echo "Failed to install apps via brew" exit 2 fi - brew tap homebrew/cask-fonts - local var _casks=${casks[*]} - echo ">> brew install --cask $_casks" - brew install --cask $_casks - exit $? -} - -function installAppsLinux { - echo "Installing apps via apt..." - echo "NOTE: apps install for Linux is still very brittle and incomplete, YMMV !!!" - local var apps=( - bat - fd-find - fish - fzf - git - # git-delta # no apt installer for git-delta, but snap has it? - less - # lsd # no lsd installer for linux :-() - neovim - ripgrep - tmux - wget - xz-utils - ) - - # curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash - # curl -sS https://starship.rs/install.sh | sh - local var _apps=${apps[*]} - # echo ">> sudo apt install $_apps" - sudo apt install $_apps + local var _casks=${casks[*]} + case `uname` in + 'Darwin') + brew tap homebrew/cask-fonts + echo ">> brew install --cask $_casks" + brew install --cask $_casks + ;; + esac exit $? } @@ -266,17 +260,11 @@ main() { ;; "setup") echo "Setting up..." - case `uname` in - 'Darwin') ensureBrew ;; - 'Linux') ;; - esac + ensureBrew main apps ;; "apps") - case `uname` in - 'Darwin') installAppsMacOS ;; - 'Linux') installAppsLinux ;; - esac + installApps if [ $? -ne 0 ] ; then exit $? fi From ef1d8ec90de522ab4ca04abf461711e19de1a5f7 Mon Sep 17 00:00:00 2001 From: "david@DAVID-PC" <3200210+davidjenni@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:52:06 -0800 Subject: [PATCH 3/5] test & fix in Ubunty 22.x WSL --- bash/bash_aliases | 36 +++++++++++++++++++++++++++++------- bootstrap.sh | 4 ++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bash/bash_aliases b/bash/bash_aliases index 1ac820c..702d509 100644 --- a/bash/bash_aliases +++ b/bash/bash_aliases @@ -1,9 +1,24 @@ +function have { + hash "$1" >&/dev/null +} + alias cls='clear' -alias la='ls -AGF' -alias ls='ls -GF' -alias ll='ls -lGF' +if have lsd; then + alias la='lsd -a --group-directories-first' + alias ls='lsd --group-directories-first' + alias ll='lsd -l --group-directories-first' +else + alias la='ls -aGF' + alias ls='ls -GF' + alias ll='ls -lGF' +fi + +if have bat; then + alias l='bat' +else + alias l='less' +fi -alias l='less' export LESS="-c -i -x4 -J -w -M -r" export VISUAL='nvim' alias v='nvim' @@ -27,12 +42,19 @@ fi case `uname` in 'Darwin') if [ -d "/opt/homebrew/bin" ] ; then - eval "$(/opt/homebrew/bin/brew shellenv)" ;; + eval "$(/opt/homebrew/bin/brew shellenv)" fi ;; 'Linux') - if [ -d "home/linuxbrew/.linuxbrew/bin" ] ; then - eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" ;; + if [ -d "/home/linuxbrew/.linuxbrew/bin" ] ; then + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" fi ;; esac + +if have starship; then + eval "$(starship init bash)" +fi +if have zoxide; then + eval "$(zoxide init bash)" +fi diff --git a/bootstrap.sh b/bootstrap.sh index 34d891a..8ee2c48 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -121,7 +121,7 @@ function installApps { tmux tre-command tokei - wget + zoxide xz ) @@ -146,7 +146,7 @@ function installApps { brew install --cask $_casks ;; esac - exit $? + return $? } function copyFile { From b43febc278e9c8e0418991a95f05ac23d82a1ee0 Mon Sep 17 00:00:00 2001 From: "david@DAVID-PC" <3200210+davidjenni@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:06:38 -0800 Subject: [PATCH 4/5] emit script and pwd path at start; setupEnv has paths relative to script --- bootstrap.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 8ee2c48..5ef4e11 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -4,6 +4,7 @@ originGitHub='https://github.com/davidjenni/dotfiles.git' dotPath=$HOME/dotfiles +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) shopt -s nocasematch @@ -158,7 +159,7 @@ function copyFile { fi targetDir=$(dirname $target) mkdir -p $targetDir - sourceFile=$dotPath/$sourceRelPath + sourceFile=$scriptDir/$sourceRelPath echo " $sourceFile -> $target" cp $sourceFile $target } @@ -171,7 +172,7 @@ function copyDir { rm -rf $targetDir >&/dev/null fi mkdir -p $targetDir - sourceDir=$dotPath/$sourceRelPath + sourceDir=$scriptDir/$sourceRelPath echo " $sourceDir -> $targetDir" cp -R $sourceDir/* $targetDir } @@ -179,7 +180,7 @@ function copyDir { function setupShellEnv { echo "Setting up shell environment..." ensureGitNames noprompt - writeGitConfig $dotPath/gitconfig.ini + writeGitConfig $scriptDir/gitconfig.ini local configDir=$HOME/.config if [ ! -d "$configDir" ] ; then @@ -290,5 +291,5 @@ main() { echo "Done." } -echo "Starting bootstrap.sh..." +echo "Starting bootstrap.sh (in $scriptDir with working dir: $(pwd))..." main $* From 6e22936df7524afe8bc7d0172b39d6acfd07f277 Mon Sep 17 00:00:00 2001 From: "david@DAVID-PC" <3200210+davidjenni@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:48:42 -0800 Subject: [PATCH 5/5] add login info for bash (similar to fish) --- bash/bash_aliases | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bash/bash_aliases b/bash/bash_aliases index 702d509..13688bb 100644 --- a/bash/bash_aliases +++ b/bash/bash_aliases @@ -58,3 +58,16 @@ fi if have zoxide; then eval "$(zoxide init bash)" fi + +case $- in + *i*) # interactive + if `shopt -q login_shell`; then + if have neofetch; then + neofetch + else + echo " $(uname -a)" + uptime + fi + fi + ;; +esac