From d8d779781705fe2c585ce0c0b1218b4c21137db1 Mon Sep 17 00:00:00 2001 From: Minz Date: Thu, 25 Sep 2025 13:32:25 +0200 Subject: [PATCH] Add auto apply scripts --- interactive.sh | 62 ++++++++++++++++++++++++++++++++++ aliases.sh => shell/aliases.sh | 3 +- shell/apply.sh | 15 ++++++++ bashrc.sh => shell/bashrc.sh | 0 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 interactive.sh rename aliases.sh => shell/aliases.sh (55%) create mode 100644 shell/apply.sh rename bashrc.sh => shell/bashrc.sh (100%) diff --git a/interactive.sh b/interactive.sh new file mode 100755 index 0000000..ab39921 --- /dev/null +++ b/interactive.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +dirs=() +for d in */ ; do + dirs+=("${d%/}") +done + +selected=() +for ((i=0; i<${#dirs[@]}; i++)); do + selected[i]=0 +done + +stty -echo -icanon time 0 min 0 + +current=0 +while true; do + clear + echo "Use ↑/↓ to move, space to select, Enter to confirm." + for ((i=0; i<${#dirs[@]}; i++)); do + mark="[ ]" + [[ ${selected[i]} -eq 1 ]] && mark="[x]" + if [[ $i -eq $current ]]; then + echo -e "> \e[7m$mark ${dirs[i]}\e[0m" + else + echo " $mark ${dirs[i]}" + fi + done + + IFS= read -rsn1 key + if [[ $key == $'\x1b' ]]; then + read -rsn2 -t 0.1 key2 + key+=$key2 + fi + + case "$key" in + $'\x1b[A') ((current--)) ;; # Up + $'\x1b[B') ((current++)) ;; # Down + " ") + selected[$current]=$((1 - selected[$current])) + ;; + "") + break + ;; + esac + + ((current<0)) && current=$((${#dirs[@]}-1)) + ((current>=${#dirs[@]})) && current=0 +done + +stty sane + +for ((i=0; i<${#dirs[@]}; i++)); do + if [[ ${selected[i]} -eq 1 ]]; then + dir="${dirs[i]}" + if [[ -f "$dir/apply.sh" ]]; then + echo "Running apply.sh in $dir" + (cd "$dir" && bash apply.sh) + else + echo "No apply.sh found in $dir" + fi + fi +done diff --git a/aliases.sh b/shell/aliases.sh similarity index 55% rename from aliases.sh rename to shell/aliases.sh index 6f7a210..e9431dc 100644 --- a/aliases.sh +++ b/shell/aliases.sh @@ -1,2 +1,3 @@ -alias dotenv='set -o allexport && source .env && echo "Applied variables from .env" && grep -v "^\s*#" .env | cut -d "=" -f 1' +alias uplog='sudo docker compose up -d && sudo docker compose logs -f' alias downup='sudo docker compose down && sudo docker compose up -d && sudo docker compose logs -f' +alias dotenv='set -o allexport && source .env && echo "Applied variables from .env" && grep -v "^\s*#" .env | cut -d "=" -f 1' \ No newline at end of file diff --git a/shell/apply.sh b/shell/apply.sh new file mode 100644 index 0000000..7d4378e --- /dev/null +++ b/shell/apply.sh @@ -0,0 +1,15 @@ + +append_to_bashrc() { + local bashrc="$HOME/.bashrc" + for file in "$@"; do + while IFS= read -r line; do + [[ -z "$line" ]] && continue + if ! grep -Fxq "$line" "$bashrc"; then + echo "$line" >> "$bashrc" + echo "Add: $line to bashrc" + fi + done < "$file" + done +} + +append_to_bashrc aliases.sh bashrc.sh \ No newline at end of file diff --git a/bashrc.sh b/shell/bashrc.sh similarity index 100% rename from bashrc.sh rename to shell/bashrc.sh