From c24a45b485e6e7fbc0501993c6a3b2876e9ee25c Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Eugenio Halili Date: Mon, 22 Aug 2022 23:16:16 +0800 Subject: [PATCH] Add quality of life improvements to different parts of my config THis include fixing filenames for konsole because the whole repo can't be checked out on Windows, migrating some directories into the config folder and even a bit of cleanup. Signed-off-by: Andrei Jiroh Eugenio Halili --- bin/code | 5 -- bin/reload-funcs-bashrc | 17 ---- bin/system-install | 11 ++- config/bashrc/chain-source | 2 +- config/bashrc/functions | 86 +++++++++++++++++++ config/bashrc/ubuntu.bashrc | 47 +++++----- config/bashrc/worthwhile-functions | 48 ----------- ...tu.profile => SSH to WSL - Ubuntu.profile} | 0 ... => mikedmoy-byobu-attach-session.profile} | 0 ...moy:tmux.profile => mikedmoy-tmux.profile} | 0 {tmux => config/tmux}/main.conf | 0 {zshrc => config/zshrc}/ubuntu.zshrc | 0 tools/bootstrap-utils/00-script-library.sh | 24 +++++- tools/bootstrap-utils/10-config-symlinking.sh | 9 +- 14 files changed, 148 insertions(+), 101 deletions(-) delete mode 100755 bin/code delete mode 100755 bin/reload-funcs-bashrc create mode 100644 config/bashrc/functions delete mode 100644 config/bashrc/worthwhile-functions rename config/konsole/{SSH to WSL:Ubuntu.profile => SSH to WSL - Ubuntu.profile} (100%) rename config/konsole/{mikedmoy:byobu-attach-session.profile => mikedmoy-byobu-attach-session.profile} (100%) rename config/konsole/{mikedmoy:tmux.profile => mikedmoy-tmux.profile} (100%) rename {tmux => config/tmux}/main.conf (100%) rename {zshrc => config/zshrc}/ubuntu.zshrc (100%) diff --git a/bin/code b/bin/code deleted file mode 100755 index feeec5b..0000000 --- a/bin/code +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -if [[ -f "/snap/bin/code" ]]; then - exec /snap/bin/code $* -fi diff --git a/bin/reload-funcs-bashrc b/bin/reload-funcs-bashrc deleted file mode 100755 index b68270a..0000000 --- a/bin/reload-funcs-bashrc +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/env bash - -echo "---> Refreshing custom functions..." -sleep 5 -# change the path if it's different -source ~/.dotfiles/bashrc/worthwhile-functions -if [[ $? == 0 ]]; then - echo "info: Successfully refreshed functions to current session." - echo "info: Something don't work? Run edit-funcs-bashrc to edit" - echo "info: or even remove problematic functions" -else - echo "! Problems found, please run edit-funcs-bashrc to fix" - echo " and re-run this command again. In case of path changes," - echo " please do 'source ~/.bashrc' if issue presists." - echo " If you ever moved that file, also update your ~/.bashrc and" - echo " the ~/.dotfiles/bin/reload-funcs-bashrc\#L5" -fi diff --git a/bin/system-install b/bin/system-install index cf7d431..4bd85a6 100755 --- a/bin/system-install +++ b/bin/system-install @@ -1,9 +1,8 @@ #!/bin/env sh -SUDO_PATH=$(command -v sudo) -SU_PATH=$(command -v su) +SUDO=${SUDO:-"sudo"} -if [ "$1" = "" -o "$1" = "help" ]; then +if [ "$1" = "" ] || [ "$1" = "help" ]; then echo "Usage: [sudo|su root -] $0 COMMAND [ARG]" echo "Permanently installs your .dotfiles/bin scripts into your system for" echo "all users. These system-wide installs are on /usr/local/bin/dotfiles-bin" @@ -36,11 +35,11 @@ if [ "$1" = "" -o "$1" = "help" ]; then exit 0 fi -if [ $@ = "status" ]; then - if [ ! $DOTFILES_SYS_INSTALL_PATH = "" ]; then +if [ "$1" = "status" ]; then + if [ "! $DOTFILES_SYS_INSTALL_PATH" = "" ]; then echo "Local install: $DOTFILES_SYS_INSTALL_PATH" elif [ -f "$HOME/.dotfiles/config/sysbin-path" ]; then - DOTFILES_SYS_IBSTALL_PATH=$(cat "$HOME/.dotfiles/config/sysbin-path") + DOTFILES_SYS_INSTALL_PATH=$(cat "$HOME/.dotfiles/config/sysbin-path") echo "Local install: $DOTFILES_SYS_INSTALL_PATH" else echo "Local install: ✖ Not found" diff --git a/config/bashrc/chain-source b/config/bashrc/chain-source index 5f9d539..9140836 100644 --- a/config/bashrc/chain-source +++ b/config/bashrc/chain-source @@ -2,5 +2,5 @@ # these commands should be triggered on shell startup source "$DOTFILES_HOME/config/bashrc/aliases" -source "$DOTFILES_HOME/config/bashrc/worthwhile-functions" +source "$DOTFILES_HOME/config/bashrc/functions" #guild-test diff --git a/config/bashrc/functions b/config/bashrc/functions new file mode 100644 index 0000000..cafdc63 --- /dev/null +++ b/config/bashrc/functions @@ -0,0 +1,86 @@ +#!/bin/bash +# shellcheck disable=SC2199,SC2068,SC1091,SC2086,SC2145 + +# custom function management here +# changes to the worthwhile-functions filepath requires +# an update o the filepath via 'edit-script reload-funcs-bashrc +# and also any reference here + +DOTFILES_HOME=${DOTFILES_HOME:-"$HOME/.dotfiles"} +source "$DOTFILES_HOME/tools/bootstrap-utils/00-script-library.sh" + +disable-funcs () { + echo "info: Unimplemented yet. Tell Andrei to add it to his todo." +} + +edit-funcs-bashrc() { + $(command -v nano>>/dev/null && echo nano || echo vi) ~/.dotfiles/bashrc/worthwhile-functions +} + +list-debs-size() { + dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | less +} + +edit-script-file() { + # if you use other editor, please set $EDITOR. + $EDITOR "$(command -v $1)" +} + +# reloading stuff +refresh-funcs() { + showStage "reloading current session with fresh functions" + source "$DOTFILES_HOME/config/bashrc/functions" +} +refresh-aliases() { + showStage "reloading current session with fresh aliases" + source "$DOTFILES_HOME/config/bashrc/aliases" +} + +# https://commentedcode.org/blog/2020/09/21/changing-default-branch-of-git-init/ +# TODO: Deprecate this function once git-config:init.defaultBranch is used. +git() { + # check command for some automation KEK, especially i want to do DCO by default + if [[ "$1" == "init" && "$@" != *"--help"* ]]; then + if command git "$@"; then + echo "Setting HEAD to branch main" + command git symbolic-ref HEAD refs/heads/main + fi + else + command git "$@" + fi +} + +list-nodejs-scripts() { + [[ -f "package.json" ]] && jq .scripts < package.json || echo "No package.json found in current directory." +} + +code() { + # quick trick in case only code-insiders is installed and not code + if ! command -v code >> /dev/null; then + if command -v code-insiders >>/dev/null; then + warn "code-stable is not installed, but code-insiders is found in PATH, setting USE_CODE_INSIDERS" + warn "for this run" + USE_CODE_INSIDERS=true + fi + fi + + if [[ -f "/snap/bin/code" && "$USE_CODE_INSIDERS" == "" ]]; then + echo "info: execing /snap/bin/code with params: $*" + exec /snap/bin/code "$@" + elif [[ -f "/snap/bin/code-insiders" ]]; then + echo "info: execing /snap/bin/code-insiders with params: $*" + exec /snap/bin/code-insiders "$*" + fi + + if [[ "$(command -v code)" != "" && "$USE_CODE_INSIDERS" == "" ]]; then + info "execing $(command -v code) with params: $*" + exec "$(command -v code)" "$*" + elif [[ $(command -v code-insiders) != "" ]]; then + info "execing $(command -v code-insiders) with params: $*" + exec "$(command -v code-insiders)" "$*" + fi + + echo "Either VS Code Stable or Insiders aren't installed on your system. Please visit" + echo "https://go.rtapp.tk/get-code to install the code editor." + return 1 +} \ No newline at end of file diff --git a/config/bashrc/ubuntu.bashrc b/config/bashrc/ubuntu.bashrc index d308362..f1d2051 100644 --- a/config/bashrc/ubuntu.bashrc +++ b/config/bashrc/ubuntu.bashrc @@ -5,11 +5,30 @@ # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples +############################################################################ + +# https://packaging.ubuntu.com/html/getting-set-up.html#configure-your-shell +export DEBFULLNAME="Andrei Jiroh Halili" +# Temporary Gmail address for devel stuff, even through my longer email one is, well, +# on my public GPG key btw, so YOLO it. +export DEBEMAIL="ajhalili2006@gmail.com" + +## Update path and inject some vars before the shell interactivity checks ## +export DOTFILES_HOME="$HOME/.dotfiles" +export DOTFILES_STUFF_BIN="$DOTFILES_HOME/bin" +export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$DOTFILES_STUFF_BIN:$PATH" + +## Add homebrew to path ## +test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" +test -d $HOME/.linuxbrew && eval $($HOME/.linuxbrew/bin/brew shellenv) + +############################################################################ + # If not running interactively, don't do anything -#case $- in -# *i*) ;; -# *) return;; -#esac +case $- in + *i*) ;; + *) return;; +esac # don't put duplicate lines or lines starting with space in the history. # See bash(1) for more options @@ -127,12 +146,6 @@ export NVM_DIR="$HOME/.nvm" # Deta CLI export PATH="$HOME/.deta/bin:$PATH" -# scripts in ~/.local/bin and ~/.dotfiles/bin -# also $HOME/.cargo/bin -export DOTFILES_HOME="$HOME/.dotfiles" -export DOTFILES_STUFF_BIN="$DOTFILES_HOME/bin" -export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$DOTFILES_STUFF_BIN:$PATH" - # use nano instead of vi by default when on SSH # for git, there's the option of firing up VS Code, if you prefered. #export VISUAL="code --wait" @@ -170,18 +183,8 @@ fi # autocompletion for GitHub CLI eval "$(gh completion -s bash)" -# custom aliases and functions I made -# sorucing through the chain-source script -source "$DOTFILES_HOME/config/bashrc/chain-source" # TODO: Remove guild-test stuff - -# https://packaging.ubuntu.com/html/getting-set-up.html#configure-your-shell -export DEBFULLNAME="Andrei Jiroh Halili" -# Temporary Gmail address for devel stuff, even through my longer email one is, well, -# on my public GPG key btw, so YOLO it. -export DEBEMAIL="ajhalili2006@gmail.com" - -# Homebrew -test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" +# Source both the custom aliases and shell functions in one go +source "$DOTFILES_HOME/config/bashrc/chain-source" # Golang, probably we need to tweak this btw export PATH="$HOME/go/bin:$PATH" GOPATH="$HOME/go" diff --git a/config/bashrc/worthwhile-functions b/config/bashrc/worthwhile-functions deleted file mode 100644 index dbaf2c3..0000000 --- a/config/bashrc/worthwhile-functions +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -# shellcheck disable=SC2199,SC2068,SC1091,SC2086,SC2145 - -# custom function management here -# changes to the worthwhile-functions filepath requires -# an update o the filepath via 'edit-script reload-funcs-bashrc -# and also any reference here -disable-funcs () { - echo "info: Unimplemented yet. Tell Andrei to add it to his todo." -} - -edit-funcs-bashrc() { - $(command -v nano>>/dev/null && echo nano || echo vi) ~/.dotfiles/bashrc/worthwhile-functions -} - -list-debs-size() { - dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | less -} - -edit-script-file() { - # if you use other editor, please set $EDITOR. - $EDITOR "$(command -v $1)" -} - -# reloading stuff -refresh-funcs() { - "$DOTFILES_STUFF_BIN/reload-funcs-bashrc" -} -refresh-aliases() { - source "$HOME/.dotfiles/bashrc/aliases" -} - -# https://commentedcode.org/blog/2020/09/21/changing-default-branch-of-git-init/ -git() { - # check command for some automation KEK, especially i want to do DCO by default - if [[ "$1" == "init" && "$@" != *"--help"* ]]; then - if command git "$@"; then - echo "Setting HEAD to branch main" - command git symbolic-ref HEAD refs/heads/main - fi - else - command git "$@" - fi -} - -list-nodejs-scripts() { - [[ -f "package.json" ]] && jq .scripts < package.json || echo "No package.json found in current directory." -} diff --git a/config/konsole/SSH to WSL:Ubuntu.profile b/config/konsole/SSH to WSL - Ubuntu.profile similarity index 100% rename from config/konsole/SSH to WSL:Ubuntu.profile rename to config/konsole/SSH to WSL - Ubuntu.profile diff --git a/config/konsole/mikedmoy:byobu-attach-session.profile b/config/konsole/mikedmoy-byobu-attach-session.profile similarity index 100% rename from config/konsole/mikedmoy:byobu-attach-session.profile rename to config/konsole/mikedmoy-byobu-attach-session.profile diff --git a/config/konsole/mikedmoy:tmux.profile b/config/konsole/mikedmoy-tmux.profile similarity index 100% rename from config/konsole/mikedmoy:tmux.profile rename to config/konsole/mikedmoy-tmux.profile diff --git a/tmux/main.conf b/config/tmux/main.conf similarity index 100% rename from tmux/main.conf rename to config/tmux/main.conf diff --git a/zshrc/ubuntu.zshrc b/config/zshrc/ubuntu.zshrc similarity index 100% rename from zshrc/ubuntu.zshrc rename to config/zshrc/ubuntu.zshrc diff --git a/tools/bootstrap-utils/00-script-library.sh b/tools/bootstrap-utils/00-script-library.sh index fc0c36d..4d0946e 100644 --- a/tools/bootstrap-utils/00-script-library.sh +++ b/tools/bootstrap-utils/00-script-library.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash +#shellcheck disable=SC2034 # Library code for the bootstrap scripts # Adding colors to some text in termnial based on checks +# NO_COLOR: https://no-color.org/ if [ -t 1 ] && [[ "$NO_COLOR" == "" ]]; then RED=$(printf '\033[31m') GREEN=$(printf '\033[32m') @@ -18,4 +20,24 @@ else MAGENTA="" BOLD="" RESET="" -fi \ No newline at end of file +fi + +error() { + echo "${RED}error: $*${RESET}" +} + +success() { + echo "${GREEN}success: $*${RESET}" +} + +warn() { + echo "${YELLOW}warning: $*${RESET}" +} + +info() { + echo "${BOLD}info: $*${RESET}" +} + +showStage() { + echo "${BOLD}==> $*${RESET}" +} \ No newline at end of file diff --git a/tools/bootstrap-utils/10-config-symlinking.sh b/tools/bootstrap-utils/10-config-symlinking.sh index ddaa96c..38ae157 100644 --- a/tools/bootstrap-utils/10-config-symlinking.sh +++ b/tools/bootstrap-utils/10-config-symlinking.sh @@ -1,9 +1,16 @@ #!/usr/bin/env bash +source "$(dirname $0)/00-script-library.sh" + +stage "Symlinking shell configuration files..." + if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then if [ ! -f "$HOME/.bashrc" ]; then - ln -s $HOME/.dotfiles/termux.bashrc ~/.bashrc + ln -s "$HOME/.dotfiles/termux.bashrc" ~/.bashrc elif [ -f "$HOME/.bashrc" ]; then + cp "$HOME/.bashrc" "$HOME/.bashrc.bak" + ln -s "$HOME/.dotfiles/termux.bashrc" ~/.bashrc + fi elif [[ $DOTFILES_OS_NAME == "debian" ]] || [[ $DOTFILES_OS_NAME == "ubuntu" ]]; then if [[ $SKIP_CONFIG_LINKING == "" ]] && [ ! -f "$HOME/.bashrc" ]; then ln -s "$HOME/.dotfiles/ubuntu.bashrc" ~/.bashrc