This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
jstmbash/init.source

296 lines
No EOL
10 KiB
Bash

#!/bin/bash
# shellcheck disable=SC1091
# jeremystartm's bashrc
# check for $TERM
if [[ ! "${TERM}" ]]; then
echo ":: Error: \$TERM is not set. Please ensure your terminal"
echo " (emulator) sets this environment variable."
env --ignore-environment bash --norc --noprofile
exit ${?}
fi
# source configuration file
if [ -f "${HOME}/.jstmbash/config.env" ] && [ "${JSTMBASH_LOCAL_CONFIG}" != "true" ]; then
source "${HOME}/.jstmbash/config.env"
elif [ -f "/etc/jstmbash/config.env" ] && [ "${JSTMBASH_LOCAL_CONFIG}" != "true" ]; then
source "/etc/jstmbash/config.env"
elif [ -f "$(pwd)/config.env" ]; then
source "$(pwd)/config.env"
else
echo ":: Error: Configuration file not found."
env --ignore-environment bash --norc --noprofile
exit ${?}
fi
# check configuration version
case "${JSTMBASH_VERSION}" in
"")
echo ":: Error: Invalid configuration file."
env --ignore-environment bash --norc --noprofile
exit ${?}
;;
"1") ;;
*)
echo ":: Error: Unsupported configuration version \"${JSTMBASH_VERSION}\"."
echo " Please migrate your configuration file to the latest version."
env --ignore-environment bash --norc --noprofile
exit ${?}
esac
# create directories
mkdir -p "/tmp/${UID}/"
# export xdg variables (because we can)
export "XDG_CONFIG_HOME=${HOME}/.config"
export "XDG_CACHE_HOME=${HOME}/.cache"
export "XDG_DATA_HOME=${HOME}/.local/share"
export "XDG_STATE_HOME=${HOME}/.local/state"
export "XDG_RUNTIME_DIR=/tmp/${UID}/"
export "XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/flatpak/exports/share:${HOME}/.local/share/flatpak/exports/share"
export "XDG_CONFIG_DIRS=/etc/xdg"
# globals
## enable or disable flow control
if [ "${JSTMBASH_GLOBAL_FLOW_CONTROL}" == "true" ]; then
stty ixon
else
stty -ixon
fi
## set prompt aka. $PS1 and replace "$(tput sgr0)" with ansi escape sequence
export "PS1=${JSTMBASH_GLOBAL_PROMPT}"
export "PROMPT_COMMAND=${JSTMBASH_GLOBAL_PROMPT_COMMAND}"
## set "incomplete prompt" aka. $PS2
if [ "${JSTMBASH_GLOBAL_PROMPT_INCOMPLETE}" == "true" ]; then
export "PS2=\[\033[38;5;196m\][incomplete]: \033[0;10m"
fi
export "PS4=\${0}:\${LINENO}+ "
## set default $EDITOR
if ! which "${JSTMBASH_GLOBAL_EDITOR}" &> /dev/null; then
echo ":: Error: Invalid editor \"${JSTMBASH_GLOBAL_EDITOR}\""
env --ignore-environment bash --norc --noprofile
exit ${?}
fi
# manipulate $PATH
if [ "${JSTMBASH_PATH_ENFORCE_CLEAN}" == "true" ]; then
## $PATH for system-wide binaries
PATH_SYSTEM="/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/local/games:/usr/lib/flatpak/exports/bin"
## $PATH for user-wide binaries
PATH_USER="${HOME}/.local/bin:${HOME}/.local/share/flatpak/exports/bin:${HOME}/.cargo/bin"
export "PATH=${PATH_SYSTEM}:${PATH_USER}"
unset PATH_SYSTEM
unset PATH_USER
fi
if [[ "${JSTM_PATH_APPENDS}" ]]; then
export "PATH=${PATH}:${JSTM_PATH_APPENDS}"
fi
# add goodies
## extract command, very useful
if [ "${JSTMBASH_GOODIES_EXTRACT}" == "true" ]; then
function extract(){
if [ -n "${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}" ;;
*.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
}
fi
# aliases
## replace package manager
if [ "${JSTMBASH_ALIASES_PKGMGR_REPLACE}" == "true" ]; then
## check if original pkgmgr exists
if ! which "${JSTMBASH_ALIASES_PKGMGR_REPLACE_FROM}" &> /dev/null; then
echo ":: Error: Invalid package manager \"${JSTMBASH_ALIASES_PKGMGR_REPLACE_FROM}\"."
echo " Please specify a valid one in \"JSTMBASH_ALIASES_PKGMGR_REPLACE_FROM\"."
env --ignore-environment bash --norc --noprofile
exit ${?}
fi
## check if new pkgmgr exists
if ! which "${JSTMBASH_ALIASES_PKGMGR_REPLACE_TO}" &> /dev/null; then
echo ":: Error: Invalid package manager \"${JSTMBASH_ALIASES_PKGMGR_REPLACE_TO}\"."
echo " Please specify a valid one in \"JSTMBASH_ALIASES_PKGMGR_REPLACE_TO\"."
env --ignore-environment bash --norc --noprofile
exit ${?}
fi
## replace pkgmgr
# shellcheck disable=SC2139
alias "${JSTMBASH_ALIASES_PKGMGR_REPLACE_FROM}=${JSTMBASH_ALIASES_PKGMGR_REPLACE_TO}"
## make alias to old pkgmgr, just in case
# shellcheck disable=SC2139
alias "${JSTMBASH_ALIASES_PKGMGR_REPLACE_FROM}-real=$(which "${JSTMBASH_ALIASES_PKGMGR_REPLACE_FROM}")"
fi
## use eza instead of ls and dir
if [ "${JSTMBASH_ALIASES_USE_EZA}" == "true" ] && which eza &> /dev/null; then
alias "ls=eza"
alias "dir=eza"
fi
## use bat instead of cat
if [ "${JSTMBASH_ALIASES_USE_BAT}" == "true" ] && which bat &> /dev/null; then
alias "cat=bat"
fi
## use moar instead of less and more
if [ "${JSTMBASH_ALIASES_USE_MOAR}" == "true" ] && which moar &> /dev/null; then
alias "more=moar"
alias "less=moar"
export "PAGER=moar"
fi
# make programs fancier
## makes eza fancier
if [ "${JSTMBASH_FANCIER_EZA}" == "true" ] && which eza &> /dev/null; then
if [ "${JSTMBASH_FANCIER_EZA_LONG}" == "true" ]; then
export "LONGGRID=--long"
else
export "LONGGRID=--grid"
fi
if [ "${JSTMBASH_FANCIER_EZA_DIRECTORIES_BEFORE_FILES}" == "true" ]; then
export "DIRS_BEFORE_FILES= --group-directories-first"
else
unset DIRS_BEFORE_FILES
fi
if [ "${JSTMBASH_FANCIER_EZA_SIZE1000}" == "true" ]; then
unset SIZE1000
else
export "SIZE1000= --binary"
fi
if [ "${JSTMBASH_FANCIER_EZA_DISPLAY_MOUNTS}" == "true" ]; then
unset DISPLAYMOUNTS
else
export "DISPLAYMOUNTS= --mounts"
fi
if [ "${JSTMBASH_FANCIER_EZA_OCTAL_PERMISSIONS}" == "true" ]; then
export "OCTALPERMS= --octal-permissions --no-permissions"
else
unset OCTALPERMS
fi
if [ "${JSTMBASH_FANCIER_EZA_GITINFO}" == "true" ]; then
export "GITINFO= --git"
else
export "GITINFO= --no-git"
fi
## arguments to avoid redundancy
EZA_ARGUMENTS="${LONGGRID} --color=always --color-scale=size --color-scale-mode=fixed --no-quotes --smart-group --almost-all --sort name${DIRS_BEFORE_FILES}${SIZE1000}${DISPLAY_MOUNTS}${OCTALPERMS}"
# shellcheck disable=SC2139
alias "eza=$(which eza) ${EZA_ARGUMENTS}"
if [ "${JSTMBASH_ALIASES_USE_EZA}" == "true" ]; then
# shellcheck disable=SC2139
alias "ls=$(which eza) ${EZA_ARGUMENTS}"
# shellcheck disable=SC2139
alias "dir=$(which eza) ${EZA_ARGUMENTS}"
fi
unset LONGGRID
unset DIRS_BEFORE_FILES
unset SIZE1000
unset DISPLAYMOUNTS
unset GITINFO
unset EZA_ARGUMENTS
fi
## makes bat fancier
if [ "${JSTMBASH_FANCIER_BAT}" == "true" ] && which bat &> /dev/null; then
## check if moar should be bat's pager
if [ "${JSTMBASH_FANCIER_BAT_USE_MOAR}" == "true" ] && which moar &> /dev/null; then
export "PAGER=--pager=\"moar -colors 16M --no-linenumbers --statusbar bold\""
fi
BAT_ARGUMENTS="--decorations=always --color=always --theme=Dracula --italic-text=always --wrap=never --nonprintable-notation=caret --paging=auto --style full ${PAGER}"
# shellcheck disable=SC2139
alias "bat=$(which bat) ${BAT_ARGUMENTS}"
if [ "${JSTMBASH_ALIASES_USE_BAT}" == "true" ]; then
# shellcheck disable=SC2139
alias "cat=$(which bat) ${BAT_ARGUMENTS}"
fi
unset PAGER
unset BAT_ARGUMENTS
fi
## makes moar fancier
if [ "${JSTMBASH_FANCIER_MOAR}" == "true" ] && which moar &> /dev/null; then
## arguments to avoid redundancy
MOAR_ARGUMENTS="-colors 16M -statusbar bold --style ${JSTMBASH_FANCIER_MOAR_STYLE}"
# shellcheck disable=SC2139
alias "moar=$(which moar) ${MOAR_ARGUMENTS}"
if [ "${JSTMBASH_ALIASES_USE_MOAR}" == "true" ]; then
# shellcheck disable=SC2139
alias "more=moar ${MOAR_ARGUMENTS}"
# shellcheck disable=SC2139
alias "less=moar ${MOAR_ARGUMENTS}"
export "PAGER=moar ${MOAR_ARGUMENTS}"
fi
unset MOAR_ARGUMENTS
fi
## makes ytfzf fancier
if [ "${JSTMBASH_FANCIER_YTFZF}" == "true" ] && which ytfzf &> /dev/null; then
## check for valid thumbnail viewer
case "${JSTMBASH_FANCIER_YTFZF_THUMBVIEWER}" in
"chafa") ;;
"catimg") ;;
"imv") ;;
"mpv") ;;
"swayimg") ;;
"swayimg-hyprland") ;;
*)
echo ":: Error: Invalid ytfzf thumbnail viewer \"${JSTMBASH_FANCIER_YTFZF_THUMBVIEWER}\""
env --ignore-environment bash --norc --noprofile
exit ${?}
;;
esac
## *bonk*
if [ "${JSTMBASH_FANCIER_YTFZF_NSFW}" == "true" ]; then
export "NSFW=--nsfw"
else
unset NSFW
fi
## subtitles
if [ "${JSTMBASH_FANCIER_YTFZF_SUBTITLES}" == "true" ]; then
export "SUBTITLES=--features=subtitles"
else
unset SUBTITLES
fi
# shellcheck disable=SC2139
alias "ytfzf=ytfzf --formats --format-selection=normal --search-again --show-thumbnails --async-thumbnails --thumb-viewer=${JSTMBASH_FANCIER_YTFZF_THUMBVIEWER} --scrape=youtube,invidious-channel,url --force-invidious --pages=5 --max-threads=${JSTMBASH_GLOBAL_THREADS} ${NSFW} --sort-by=relevance --video-duration=short --thumbnail-quality=maxres ${SUBTITLES} --rii --search-source=prompt"
unset NSFW
unset SUBTITLES
fi
# display warnings
if [ "${JSTMBASH_WARNINGS_NO_TRUECOLOR}" == "true" ] && [ "${COLORTERM}" != "truecolor" ]; then
echo ":: Warning: Your terminal (emulator) does not provide truecolor support."
echo " Things may break! If you think this is an false-positive set"
echo " \"JSTMBASH_WARNINGS_NO_TRUECOLOR\" to false to avoid seeing this message."
fi
if [ "${JSTMBASH_WARNINGS_EXA_UNMAINTAINED}" == "true" ] && which exa &> /dev/null; then
echo ":: Warning: exa is unmaintained software and should be avoided."
echo " Use eza (https://eza.rocks) as a replacement."
fi