From 5293300a3d860ddc4aa3fa486319099d7f4735ad Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 3 Jun 2024 01:14:49 +0200 Subject: [PATCH] Seperate bashrc into seperate shell scripts --- bash/bashrc | 111 +-------------- bash/bashrc.d/config.sh | 7 + bash/bashrc.d/init.d/aliases.sh | 25 ++++ bash/bashrc.d/init.d/functions.sh | 128 ++++++++++++++++++ bash/bashrc.d/init.d/variables.sh | 21 +++ bash/bashrc.d/programs.d/icons-in-terminal.sh | 2 + .../programs.d/node-version-manager.sh | 2 + bash/bashrc.d/programs.d/sdkman.sh | 3 + bash/bashrc.d/programs.d/starship.sh | 2 + .../startup.d/punktdateien-updatechecker.sh | 2 + bash/bashrc.d/startup.d/quote.sh | 3 + bash/bashrc.d/startup.sh | 63 +++++++++ install.sh | 1 + 13 files changed, 260 insertions(+), 110 deletions(-) create mode 100644 bash/bashrc.d/config.sh create mode 100755 bash/bashrc.d/init.d/aliases.sh create mode 100755 bash/bashrc.d/init.d/functions.sh create mode 100755 bash/bashrc.d/init.d/variables.sh create mode 100755 bash/bashrc.d/programs.d/icons-in-terminal.sh create mode 100755 bash/bashrc.d/programs.d/node-version-manager.sh create mode 100755 bash/bashrc.d/programs.d/sdkman.sh create mode 100755 bash/bashrc.d/programs.d/starship.sh create mode 100755 bash/bashrc.d/startup.d/punktdateien-updatechecker.sh create mode 100755 bash/bashrc.d/startup.d/quote.sh create mode 100755 bash/bashrc.d/startup.sh diff --git a/bash/bashrc b/bash/bashrc index b9c6b361..a4901ec9 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -1,111 +1,2 @@ #!/bin/bash -# shellcheck disable=SC1091 - -export WINEDEBUG=-all -export SDKMAN_DIR="$HOME/.sdkman" -[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh" -source "/usr/share/icons-in-terminal/icons_bash.sh" -source /usr/share/nvm/init-nvm.sh -export PNPM_HOME="/home/jeremystartm/.local/share/pnpm" -case ":$PATH:" in - *":$PNPM_HOME:"*) ;; - *) export PATH="$PNPM_HOME:$PATH" ;; -esac -source "${HOME}/.jstmbash/init.source" -eval "$(starship init bash)" -alias "fireplace=$(which fireplace) -f 60 -t 13" -alias "quote=fortune -s linux debian|cowsay" -alias "besseretests=godot --headless -d -v -s --path . addons/besseretests/src/cmd.gd" -alias "besseretests-gui=godot -d -v -s --path . addons/besseretests/src/cmd.gd" -alias "rm=rm -ri" -alias "finfo=sudo cpupower frequency-info" -alias "fset=sudo cpupower frequency-set -g" -function osu-oszimport() { - if [ ! -f "${HOME}/.cache/osu.AppImage" ]; then - echo "--> Could not find ~/.cache/osu.AppImage" - echo " Please download and start osu! using osu!boot first." - else - for file in *.osz; do - if [ "${file}" == "*.osz" ]; then - echo "--> No .osz file has been found" - else - echo "--> Importing ${file}" - ~/.cache/osu.AppImage "${file}" - fi - done - fi -} -function godot-setup() { - ( - set -eo pipefail - if [ ! -f "project.godot" ]; then - echo ":: Error: No project.godot file was found." - exit - fi - - if [ -n "$HELP" ]; then - echo ":: Available environment variables:" - echo " \$CORE_BRANCH=" - echo " \$INSTALL_SUI=" - echo " \$INSTALL_VENUS=" - echo "" - echo ":: Note: The first listed value is the default" - echo " for that specific environment variable." - exit - fi - if [ -z "$CORE_BRANCH" ]; then CORE_BRANCH=develop; fi - if [ -z "$INSTALL_SUI" ]; then INSTALL_SUI=false; fi - if [ -z "$INSTALL_VENUS" ]; then INSTALL_VENUS=false; fi - - if [ ! -d ".git" ]; then - echo ":: Initializing git repository" - git init -b develop - fi - - echo ":: Creating files" - wget -q --show-progress "https://www.gnu.org/licenses/agpl-3.0.txt" -O LICENSE - cat << EOF >> README.md -# New project -You need to fill this README.md out. -EOF - - echo ":: Removing default icon" - rm -rf icon.png - - echo ":: Creating directories" - mkdir -p src scenesrc assets/{images,sprites,music,sfx,fonts,themes} dist/submodules addons - - echo ":: Installing CORE" - git submodule add https://git.staropensource.de/StarOpenSource/CORE-distrib-git.git dist/submodules/CORE - ( - cd dist/submodules/CORE - git checkout "$CORE_BRANCH" - ) - ln -s dist/submodules/CORE CORE - - if [ "$INSTALL_SUI" == "true" ]; then - echo ":: Installing StarOpenSource UI" - git submodule add https://git.staropensource.de/StarOpenSource/SUI-distrib.git dist/submodules/SUI - ln -s ../dist/submodules/SUI addons/SUI - fi - - if [ "$INSTALL_VENUS" == "true" ]; then - echo ":: Installing Venus" - git submodule add https://git.staropensource.de/StarOpenSource/venus.git dist/submodules/Venus - ln -s ../dist/submodules/Venus addons/venus - fi - ) -} -export "RUSTFLAGS=-Z threads=$(nproc)" -export "EDITOR=nano" -function cleanhome() { - echo ":: Cleaning ~" - rm -rf "${HOME}/.dotnet" "${HOME}/.fltk" "${HOME}/.gradle" "${HOME}/.hyprland" \ - "${HOME}/.java" "${HOME}/.npm" "${HOME}/.nuget" "${HOME}/.nvm" "${HOME}/.openjfx" \ - "${HOME}/.pki" "${HOME}/.vnc" "${HOME}/.yarn" "${HOME}/go" "${HOME}/.lesshst" \ - "${HOME}/.wget-hsts" "${HOME}/.yarnrc" "${HOME}/package-lock.json" "${HOME}/package.json" \ - "${HOME}/node_modules" "${HOME}/.npmrc" "${HOME}/.gtkrc-2.0" "${HOME}/.electron-gyp" \ - "${HOME}/.python_history" "${HOME}/.m2" "${HOME}/.mono" "${HOME}/.local/share/NuGet" -} -quote -env "BASHRC=true" dotfiles-updatechecker +source ${HOME}/.bashrc.d/startup.sh diff --git a/bash/bashrc.d/config.sh b/bash/bashrc.d/config.sh new file mode 100644 index 00000000..c9b196bd --- /dev/null +++ b/bash/bashrc.d/config.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +CONFIG_FLOW_CONTROL=0 +CONFIG_AUTOSAVE_HISTORY=1 +CONFIG_CUSTOM_PROMPT=1 +CONFIG_EDITOR=nano +CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman +CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru diff --git a/bash/bashrc.d/init.d/aliases.sh b/bash/bashrc.d/init.d/aliases.sh new file mode 100755 index 00000000..ce2cfdc0 --- /dev/null +++ b/bash/bashrc.d/init.d/aliases.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2139 + +# StarOpenSource Development +alias "besseretests=godot --headless -d -v -s --path . addons/besseretests/src/cmd.gd" +alias "besseretests-gui=godot -d -v -s --path . addons/besseretests/src/cmd.gd" + +# Safety +alias "rm=rm -ri" + +# CPU Governor +alias "finfo=sudo cpupower frequency-info" +alias "fset=sudo cpupower frequency-set -g" + +# Fun ;) +alias "fireplace=$(which fireplace) -f 60 -t 13" +alias "quote=fortune -s linux debian|cowsay" + +# Replacements +alias "ls=$(which eza) ${ARGS_EZA}" +alias "dir=$(which eza) ${ARGS_EZA}" +alias "eza=$(which eza) ${ARGS_EZA}" +alias "more=$(which moar) ${ARGS_MOAR}" +alias "less=$(which moar) ${ARGS_MOAR}" +alias "moar=$(which moar) ${ARGS_MOAR}" diff --git a/bash/bashrc.d/init.d/functions.sh b/bash/bashrc.d/init.d/functions.sh new file mode 100755 index 00000000..8bfca3e9 --- /dev/null +++ b/bash/bashrc.d/init.d/functions.sh @@ -0,0 +1,128 @@ +#!/usr/bin/env bash +function osu-oszimport() { + if [ ! -f "${HOME}/.cache/osu.AppImage" ]; then + echo "--> Could not find ~/.cache/osu.AppImage" + echo " Please download and start osu! using osu!boot first." + else + for file in *.osz; do + if [ "${file}" == "*.osz" ]; then + echo "--> No .osz file has been found" + else + echo "--> Importing ${file}" + ~/.cache/osu.AppImage "${file}" + fi + done + fi +} + +function godot-setup() { + ( + set -eo pipefail + if [ ! -f "project.godot" ]; then + echo ":: Error: No project.godot file was found." + exit + fi + + if [ -n "$HELP" ]; then + echo ":: Available environment variables:" + echo " \$CORE_BRANCH=" + echo " \$INSTALL_SUI=" + echo " \$INSTALL_VENUS=" + echo "" + echo ":: Note: The first listed value is the default" + echo " for that specific environment variable." + exit + fi + if [ -z "$CORE_BRANCH" ]; then CORE_BRANCH=develop; fi + if [ -z "$INSTALL_SUI" ]; then INSTALL_SUI=false; fi + if [ -z "$INSTALL_VENUS" ]; then INSTALL_VENUS=false; fi + + if [ ! -d ".git" ]; then + echo ":: Initializing git repository" + git init -b develop + fi + + echo ":: Creating files" + wget -q --show-progress "https://www.gnu.org/licenses/agpl-3.0.txt" -O LICENSE + cat << EOF >> README.md +# New project +You need to fill this README.md out. +EOF + + echo ":: Removing default icon" + rm -rf icon.png + + echo ":: Creating directories" + mkdir -p src scenesrc assets/{images,sprites,music,sfx,fonts,themes} dist/submodules addons + + echo ":: Installing CORE" + git submodule add https://git.staropensource.de/StarOpenSource/CORE-distrib-git.git dist/submodules/CORE + ( + cd dist/submodules/CORE + git checkout "$CORE_BRANCH" + ) + ln -s dist/submodules/CORE CORE + + if [ "$INSTALL_SUI" == "true" ]; then + echo ":: Installing StarOpenSource UI" + git submodule add https://git.staropensource.de/StarOpenSource/SUI-distrib.git dist/submodules/SUI + ln -s ../dist/submodules/SUI addons/SUI + fi + + if [ "$INSTALL_VENUS" == "true" ]; then + echo ":: Installing Venus" + git submodule add https://git.staropensource.de/StarOpenSource/venus.git dist/submodules/Venus + ln -s ../dist/submodules/Venus addons/venus + fi + ) +} + +function cleanhome() { + echo ":: Cleaning ~" + rm -rf "${HOME}/.dotnet" "${HOME}/.fltk" "${HOME}/.gradle" "${HOME}/.hyprland" \ + "${HOME}/.java" "${HOME}/.npm" "${HOME}/.nuget" "${HOME}/.nvm" "${HOME}/.openjfx" \ + "${HOME}/.pki" "${HOME}/.vnc" "${HOME}/.yarn" "${HOME}/go" "${HOME}/.lesshst" \ + "${HOME}/.wget-hsts" "${HOME}/.yarnrc" "${HOME}/package-lock.json" "${HOME}/package.json" \ + "${HOME}/node_modules" "${HOME}/.npmrc" "${HOME}/.gtkrc-2.0" "${HOME}/.electron-gyp" \ + "${HOME}/.python_history" "${HOME}/.m2" "${HOME}/.mono" "${HOME}/.local/share/NuGet" +} + +function extract(){ + if [ -z "${1}" ]; then + echo ":: Error: No file given." + return 1 + fi + if [ -f "${1}" ]; then + case "${1}" in + *.tar|*.tar.xz) tar xf "${1}" ;; + *.tar.bz2) tar xjf "${1}" ;; + *.tar.gz|*.tgz) tar xzf "${1}" ;; + *.tar.zst) unzstd "${1}" ;; + *.tbbz2) tar xjf "${1}" ;; + *.gz) gunzip "${1}" ;; + *.xz) xz -d "${1}" ;; + *.bz2) bunzip2 "${1}" ;; + *.rar) unrar x "${1}" ;; + *.zip|*.jar) unzip "${1}" ;; + *.7z) 7z x "${1}" ;; + *.Z) uncompress "${1}" ;; + *.deb) ar x "${1}" ;; + *) + echo ":: Error: Invalid archive" + return 1 + ;; + esac + elif [ -d "${1}" ]; then + ## is it a bird? is it a dir? + echo ":: Error: Is a directory" + return 1 + elif [ -a "${1}" ]; then + ## if block device or something + echo ":: Error: jeremystartm's bashrc implementation of the extract command only supports files." + return 1 + else + ## not found + echo ":: Error: No such file or directory" + return 1 + fi + } diff --git a/bash/bashrc.d/init.d/variables.sh b/bash/bashrc.d/init.d/variables.sh new file mode 100755 index 00000000..ad3fff3b --- /dev/null +++ b/bash/bashrc.d/init.d/variables.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Arguments for some programs +export "ARGS_EZA=--long --binary --mounts --no-git --color=always --color-scale=size --color-scale-mode=fixed --no-quotes --smart-group --almost-all --sort name" +export "ARGS_MOAR=-colors 16M -statusbar bold --style dracula" + +# General +export "PAGER=$(which moar) ${ARGS_MOAR}" + +# Wine +export "WINEDEBUG=-all" + +# Rust +export "RUSTFLAGS=-Z threads=$(nproc)" + +# PNPM +export PNPM_HOME="/home/jeremystartm/.local/share/pnpm" +case ":$PATH:" in + *":$PNPM_HOME:"*) ;; + *) export PATH="$PNPM_HOME:$PATH" ;; +esac diff --git a/bash/bashrc.d/programs.d/icons-in-terminal.sh b/bash/bashrc.d/programs.d/icons-in-terminal.sh new file mode 100755 index 00000000..2c37dcb1 --- /dev/null +++ b/bash/bashrc.d/programs.d/icons-in-terminal.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +source "/usr/share/icons-in-terminal/icons_bash.sh" diff --git a/bash/bashrc.d/programs.d/node-version-manager.sh b/bash/bashrc.d/programs.d/node-version-manager.sh new file mode 100755 index 00000000..b353a2d5 --- /dev/null +++ b/bash/bashrc.d/programs.d/node-version-manager.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +source /usr/share/nvm/init-nvm.sh diff --git a/bash/bashrc.d/programs.d/sdkman.sh b/bash/bashrc.d/programs.d/sdkman.sh new file mode 100755 index 00000000..2e6d0ca5 --- /dev/null +++ b/bash/bashrc.d/programs.d/sdkman.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +export SDKMAN_DIR="$HOME/.sdkman" +[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh" diff --git a/bash/bashrc.d/programs.d/starship.sh b/bash/bashrc.d/programs.d/starship.sh new file mode 100755 index 00000000..76f265b2 --- /dev/null +++ b/bash/bashrc.d/programs.d/starship.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +eval "$(starship init bash)" diff --git a/bash/bashrc.d/startup.d/punktdateien-updatechecker.sh b/bash/bashrc.d/startup.d/punktdateien-updatechecker.sh new file mode 100755 index 00000000..4160946e --- /dev/null +++ b/bash/bashrc.d/startup.d/punktdateien-updatechecker.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +env "BASHRC=true" dotfiles-updatechecker diff --git a/bash/bashrc.d/startup.d/quote.sh b/bash/bashrc.d/startup.d/quote.sh new file mode 100755 index 00000000..195cd469 --- /dev/null +++ b/bash/bashrc.d/startup.d/quote.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +quote diff --git a/bash/bashrc.d/startup.sh b/bash/bashrc.d/startup.sh new file mode 100755 index 00000000..0a383056 --- /dev/null +++ b/bash/bashrc.d/startup.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2154 + +cd "${HOME:?}/.bashrc.d" || ( + echo ":: Can't cd into ${HOME:?}/.bashrc.d" + exit 1 +) + +# Create new configuration file +[[ ! -f "config.sh" ]] && cat << EOF >> config.sh +#!/usr/bin/env bash +CONFIG_FLOW_CONTROL=0 +CONFIG_AUTOSAVE_HISTORY=1 +CONFIG_CUSTOM_PROMPT=1 +CONFIG_EDITOR=nano +CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman +CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru +EOF + +# Load configuration file +source "config.sh" + +# Initialize basic stuff +[[ -f "init.d/variables.sh" ]] && source "init.d/variables.sh" +[[ -f "init.d/aliases.sh" ]] && source "init.d/aliases.sh" +[[ -f "init.d/functions.sh" ]] && source "init.d/functions.sh" + +# Process configuration changes +# -> Flow control +[[ "${CONFIG_FLOW_CONTROl}" == "0" ]] && stty -ixon +[[ "${CONFIG_FLOW_CONTROL}" == "1" ]] && stty ixon + +# -> Autosave history +[[ "${CONFIG_AUTOSAVE_HISTORY}" == "1" ]] && export "PROMPT_COMMAND=history -a" + +# -> Custom prompt +if [[ "${CONFIG_CUSTOM_PROMPT}" == "1" ]]; then + export "PS1=\[\033[38;5;33m\][\[$(tput sgr0)\]\[\033[38;5;38m\]\u\[$(tput sgr0)\]\[\033[38;5;33m\]@\[$(tput sgr0)\]\[\033[38;5;38m\]\H\[$(tput sgr0)\]\[\033[38;5;33m\]:\[$(tput sgr0)\]\[\033[38;5;38m\]\W\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;214m\]\$?\[$(tput sgr0)\]\[\033[38;5;33m\]]\\$\[$(tput sgr0)\] " + export "PS2=\[\033[38;5;196m\][incomplete]: \033[0;10m" + export "PS4=\${0}:\${LINENO}+ " +fi + +# -> Editor +export "EDITOR=${CONFIG_EDITOR}" + +# -> Package manager replacement +if [ -n "${CONFIG_REPLACE_PKGMGR_ORIGINAL}" ] && [ -n "${CONFIG_REPLACE_PKGMGR_REPLACEMENT}" ]; then + # shellcheck disable=SC2139 + alias "${CONFIG_REPLACE_PKGMGR_ORIGINAL}=${CONFIG_REPLACE_PKGMGR_REPLACEMENT}" +fi + + +# Initialize shell programs +for file in programs.d/*; do + # shellcheck disable=SC1090 + source "${file}" +done + +# Run startup scripts +for file in startup.d/*; do + # shellcheck disable=SC1090 + source "${file}" +done diff --git a/install.sh b/install.sh index b90b6e3c..36a230f5 100755 --- a/install.sh +++ b/install.sh @@ -45,6 +45,7 @@ link "repositories/jstmbash" ".jstmbash" # bash link "bash/bashrc" ".bashrc" +link "bash/bashrc.d" ".bashrc.d" link "bash/bin/launch-menu" ".local/bin/launch-menu" link "bash/jobrunner/daemon.sh" ".local/bin/jobrunner" link "bash/jobrunner/runjob.sh" ".local/bin/jobrunner-runjob"