From 1073e803f71e186a2ac0bf8e70016ba1a9a966ce Mon Sep 17 00:00:00 2001 From: David Neumaier Date: Wed, 1 Apr 2026 13:52:31 +0200 Subject: [PATCH] stuff --- .gitignore | 1 + install.sh | 12 ++++++++++++ .bashrc => library/aliases.sh | 28 +++++++++++++++++++--------- library/deadline.check.sh | 10 ++++++++++ library/deadline.listen.sh | 2 ++ library/deadline.sh | 34 ++++++++++++++++++++++++++++++++++ library/getdir.sh | 3 +++ library/getdt.sh | 21 +++++++++++++++++++++ library/hooks/pre-commit | 2 ++ library/load.sh | 22 ++++++++++++++++++++++ library/qash.sh | 6 ++++++ library/stressuser.sh | 21 +++++++++++++++++++++ 12 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 install.sh rename .bashrc => library/aliases.sh (60%) create mode 100644 library/deadline.check.sh create mode 100644 library/deadline.listen.sh create mode 100644 library/deadline.sh create mode 100644 library/getdir.sh create mode 100644 library/getdt.sh create mode 100644 library/hooks/pre-commit create mode 100644 library/load.sh create mode 100644 library/qash.sh create mode 100644 library/stressuser.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e45d6e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.local \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..f75bda4 --- /dev/null +++ b/install.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +read -p "Do you want to install Qash? This will move your old .bashrc and replace it with Qash. y/N " + +if [[ $REPLY -eq 'y' ]]; then + mv ~/.bashrc ~/.bashrc.old + dir=./library/getdir.sh + echo "#!/bin/bash" >> ~/.bashrc + echo "$dir/load.sh" >> ~/.bashrc + ~/.bashrc + echo "Qash $QASH_VERSION successfully installed!" +fi \ No newline at end of file diff --git a/.bashrc b/library/aliases.sh similarity index 60% rename from .bashrc rename to library/aliases.sh index 65febf2..9f07b9b 100644 --- a/.bashrc +++ b/library/aliases.sh @@ -1,16 +1,25 @@ -echo "Uptime: $(uptime)" - # use bash completion -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion +if [[ $QASH_USE_BASH_COMPLETION ]]; then + if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi fi fi +# helper functions +isroot() { + if [[ "$EUID" -eq 0 ]]; then + echo 1 + elif + echo 0 + fi +} + # conditional root aliases -if [ "$EUID" -eq 0 ]; then +if [[ $isroot ]]; then alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' @@ -31,6 +40,7 @@ alias gc='git checkout' alias gp='git push' alias gpr='git pull origin --rebase' alias cmt='git commit -m' +alias gap="git add -p" # docker compose alias dc='docker compose' @@ -44,4 +54,4 @@ alias syst='systemctl status' alias sysr='systemctl restart' alias sysk='systemctl stop' alias syss='systemctl start' -alias syse='systemctl enable --now' \ No newline at end of file +alias syse='systemctl enable --now' diff --git a/library/deadline.check.sh b/library/deadline.check.sh new file mode 100644 index 0000000..4c58d9e --- /dev/null +++ b/library/deadline.check.sh @@ -0,0 +1,10 @@ +#!/bin/bash +if [[ "$PWD" != "$__QASH_LAST_DEADLINE_DIR" ]]; then + if [[ -f ".deadline" ]]; then + deadline=$(cat .deadline) + now=$(date) + left=$(getdt $deadline $now) + echo -e "\e[5;33mDEADLINE:\e[0m $(cat .deadline), left: $left" + fi + export __QASH_LAST_DEADLINE_DIR="$PWD" +fi \ No newline at end of file diff --git a/library/deadline.listen.sh b/library/deadline.listen.sh new file mode 100644 index 0000000..aab4271 --- /dev/null +++ b/library/deadline.listen.sh @@ -0,0 +1,2 @@ +#!/bin/bash +export PROMPT_COMMAND="$QASH_LIBRARY_DIR/check_deadline; $PROMPT_COMMAND" \ No newline at end of file diff --git a/library/deadline.sh b/library/deadline.sh new file mode 100644 index 0000000..3fe781c --- /dev/null +++ b/library/deadline.sh @@ -0,0 +1,34 @@ +#!/bin/bash +if [[ $# -lt 2 ]]; then + echo "Usage: deadline " + return -1 +fi +deadline_name=${1:-"THE DEADLINE"} +target_date=${2:-"2048-01-01 00:08:00"} +stress_below=${3:-14} +target_epoch=$(date -d "$target_date" +%s) +now_epoch=$(date +%s) +remaining_seconds=$((target_epoch - now_epoch)) + +if [[ $remaining_seconds -lt 0 ]]; then + echo "\033[33mDeadline has passed. Rest in peace.\033[0m" +else + days=$((remaining_seconds / 86400)) + hours=$(((remaining_seconds % 86400) / 3600)) + minutes=$(((remaining_seconds % 3600) / 60)) + seconds=$((remaining_seconds % 60)) + + color="33" + if [[ $days -le $stress_below ]]; then + color="31" + #flash=$((100 - ((days * 100 + 1) / $stress_below))) + fi + + if [[ days -le $stress_below ]]; then + printf "\e[${color}m ! DEADLINE SET FOR <%s> (%s)\e[0m\n" "$deadline_name" "$target_date" + $QASH_LIBRARY_DIR/stressuser.sh "\e[${color}m ! --- $days:$hours:$minutes:$seconds REMAINING --- \n" $color .48 + else + printf "\e[${color}m\e[5m ! DEADLINE SET FOR <%s> (%s)\e[0m\n" "$deadline_name" "$target_date" + printf "\e[0m ! --- roughly $days days remaining, no biggie --- \e[0m\n" + fi +fi diff --git a/library/getdir.sh b/library/getdir.sh new file mode 100644 index 0000000..15512e7 --- /dev/null +++ b/library/getdir.sh @@ -0,0 +1,3 @@ +#!/bin/bash +dir=$(cd "$(dirname "${BASH_SOURCE}")" && pwd) +echo "$dir" diff --git a/library/getdt.sh b/library/getdt.sh new file mode 100644 index 0000000..61b464d --- /dev/null +++ b/library/getdt.sh @@ -0,0 +1,21 @@ +#!/bin/bash +if [[ $# -lt 3 ]]; then + echo "Usage: getdt (format)" + return -1 +fi +from_date=$1 +to_date=$2 +format="%02d days, %02d:%02d:%02d" +if [[ $# -gt 3 ]]; then + format=$3 +fi +target_epoch=$(date -d "$from_date" +%s) +now_epoch=$(date -d "$to_date" +%s) +remaining_seconds=$((target_epoch - now_epoch)) + +days=$((remaining_seconds / 86400)) +hours=$(((remaining_seconds % 86400) / 3600)) +minutes=$(((remaining_seconds % 3600) / 60)) +seconds=$((remaining_seconds % 60)) + +printf "%02d days, %02d:%02d:%02d" $days $hours $minutes $seconds diff --git a/library/hooks/pre-commit b/library/hooks/pre-commit new file mode 100644 index 0000000..39187c2 --- /dev/null +++ b/library/hooks/pre-commit @@ -0,0 +1,2 @@ +#!/bin/bash +$QASH_LIBRARY_DIR/deadline.sh "$(cat $PWD/.git/description)" "$(cat "$PWD"/.deadline)" \ No newline at end of file diff --git a/library/load.sh b/library/load.sh new file mode 100644 index 0000000..25f5755 --- /dev/null +++ b/library/load.sh @@ -0,0 +1,22 @@ +#!/bin/bash +LIBRARY_DIR=$(./getdir.sh) + +export QASH_VERSION='v0.2.1' +export QASH_ENABLE_DEADLINE_CHECK=1 +export QASH_USE_BASH_COMPLETION=1 +export QASH_LIBRARY_DIR="$LIBRARY_DIR" + +source "$LIBRARY_DIR/aliases.sh" +source "$LIBRARY_DIR/qash.sh" + +if [[ $QASH_ENABLE_DEADLINE_CHECK ]]; then + $LIBRARY_DIR/check_deadline.sh + echo "Enabled deadline check." +fi + +if [[ -f "~/.bashrc.local" ]]; then + source ~/.bashrc.local +fi + +echo "\e[22mUptime: $(uptime)" +echo "\e[16mQrakhen's QASH $QASH_VERSION loaded.\e[0m" \ No newline at end of file diff --git a/library/qash.sh b/library/qash.sh new file mode 100644 index 0000000..00a74aa --- /dev/null +++ b/library/qash.sh @@ -0,0 +1,6 @@ +#!/bin/bash +qash() { + if [[ " $@ " == *" --help "* ]]; then + echo "There is no helping you." + fi +} \ No newline at end of file diff --git a/library/stressuser.sh b/library/stressuser.sh new file mode 100644 index 0000000..1cf6180 --- /dev/null +++ b/library/stressuser.sh @@ -0,0 +1,21 @@ +#!/bin/bash +__cleanup_terminal() { + printf '\e[?5l' + printf '\e[0m' + return -1 +} + +trap "__cleanup_terminal; return 1" INT +text=${1:-"PANIC IS ADVISED"} +color=${2:-33} +delay=${3:-.48} +printf "\e[${color}m$text"; +while true; +do + printf '\e[?5h'; + sleep $delay; + printf '\e[?5l'; + read -s -n1 -t1 && break; +done; +__cleanup_terminal +