From 2203d6075f04c572eb4ecb7b1bcad867d1ddde74 Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Thu, 18 Sep 2025 11:35:56 +0200 Subject: [PATCH] Init --- README.md | 3 ++ data/projects | 5 +++ other/yaz.zsh | 8 ++++ python/extract_mail.py | 81 +++++++++++++++++++++++++++++++++++++++ shell/autostart.sh | 11 ++++++ shell/autostart_server.sh | 64 +++++++++++++++++++++++++++++++ shell/battery_shutdown.sh | 13 +++++++ shell/cabalmod.sh | 49 +++++++++++++++++++++++ shell/check_git.sh | 67 ++++++++++++++++++++++++++++++++ shell/check_language.sh | 54 ++++++++++++++++++++++++++ shell/clipsend.sh | 22 +++++++++++ shell/deltmp.sh | 3 ++ shell/diffv_wrap.sh | 37 ++++++++++++++++++ shell/find_gits.sh | 46 ++++++++++++++++++++++ shell/get_vol.sh | 17 ++++++++ shell/ghci_wrapper.sh | 13 +++++++ shell/giter.sh | 9 +++++ shell/hitcc.sh | 3 ++ shell/hyprfix.sh | 7 ++++ shell/initer.sh | 23 +++++++++++ shell/lowervolume.sh | 3 ++ shell/mount_ssd.sh | 40 +++++++++++++++++++ shell/mousecenter1.sh | 3 ++ shell/mousecenter2.sh | 3 ++ shell/mp4.sh | 15 ++++++++ shell/nix_conf.sh | 39 +++++++++++++++++++ shell/oathi.sh | 5 +++ shell/pgadmin_run.sh | 5 +++ shell/pomodoro_wrapper.sh | 10 +++++ shell/raisevolume.sh | 5 +++ shell/rnote_mapper.sh | 12 ++++++ shell/run_kitty.sh | 13 +++++++ shell/run_unison.sh | 15 ++++++++ shell/screenshot.sh | 39 +++++++++++++++++++ shell/search.sh | 8 ++++ shell/set_res.sh | 30 +++++++++++++++ shell/start_typst.sh | 22 +++++++++++ shell/stop_typst.sh | 2 + shell/sync_all.sh | 24 ++++++++++++ shell/sync_manage.sh | 37 ++++++++++++++++++ shell/tmp_note.sh | 12 ++++++ shell/toggle_wifi.sh | 19 +++++++++ shell/togglesink.sh | 15 ++++++++ shell/unison_sync.sh | 10 +++++ shell/update_stud.sh | 14 +++++++ 45 files changed, 935 insertions(+) create mode 100644 README.md create mode 100644 data/projects create mode 100755 other/yaz.zsh create mode 100644 python/extract_mail.py create mode 100755 shell/autostart.sh create mode 100755 shell/autostart_server.sh create mode 100755 shell/battery_shutdown.sh create mode 100755 shell/cabalmod.sh create mode 100755 shell/check_git.sh create mode 100755 shell/check_language.sh create mode 100755 shell/clipsend.sh create mode 100755 shell/deltmp.sh create mode 100755 shell/diffv_wrap.sh create mode 100755 shell/find_gits.sh create mode 100755 shell/get_vol.sh create mode 100755 shell/ghci_wrapper.sh create mode 100755 shell/giter.sh create mode 100755 shell/hitcc.sh create mode 100755 shell/hyprfix.sh create mode 100755 shell/initer.sh create mode 100755 shell/lowervolume.sh create mode 100755 shell/mount_ssd.sh create mode 100755 shell/mousecenter1.sh create mode 100755 shell/mousecenter2.sh create mode 100755 shell/mp4.sh create mode 100755 shell/nix_conf.sh create mode 100755 shell/oathi.sh create mode 100755 shell/pgadmin_run.sh create mode 100755 shell/pomodoro_wrapper.sh create mode 100755 shell/raisevolume.sh create mode 100755 shell/rnote_mapper.sh create mode 100755 shell/run_kitty.sh create mode 100755 shell/run_unison.sh create mode 100755 shell/screenshot.sh create mode 100755 shell/search.sh create mode 100755 shell/set_res.sh create mode 100755 shell/start_typst.sh create mode 100755 shell/stop_typst.sh create mode 100755 shell/sync_all.sh create mode 100755 shell/sync_manage.sh create mode 100755 shell/tmp_note.sh create mode 100755 shell/toggle_wifi.sh create mode 100755 shell/togglesink.sh create mode 100755 shell/unison_sync.sh create mode 100755 shell/update_stud.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..2756432 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# General purpose scripts + +Different scripts to automate workflow to be used with cron as a clock. Some configurations depend on those scripts to be present in `~/projects/scripts`. diff --git a/data/projects b/data/projects new file mode 100644 index 0000000..57f82dc --- /dev/null +++ b/data/projects @@ -0,0 +1,5 @@ +.config +.config/nvim +~/ +vault +management/office diff --git a/other/yaz.zsh b/other/yaz.zsh new file mode 100755 index 0000000..f14abeb --- /dev/null +++ b/other/yaz.zsh @@ -0,0 +1,8 @@ +function y() { + local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd + yazi "$@" --cwd-file="$tmp" + if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then + builtin cd -- "$cwd" + fi + rm -f -- "$tmp" +} diff --git a/python/extract_mail.py b/python/extract_mail.py new file mode 100644 index 0000000..fe29f37 --- /dev/null +++ b/python/extract_mail.py @@ -0,0 +1,81 @@ +import os +import email +from email import policy +from email.parser import BytesParser +import re +from datetime import datetime + +# Path to the email file +input_file = "/home/jonas/mail/saved-messages" + +# Output folder +output_dir = "/home/jonas/mail/plain_emails" +os.makedirs(output_dir, exist_ok=True) + +def sanitize_filename(name): + """Remove problematic characters for filenames""" + return re.sub(r'[\\/*?:"<>|]', "", name) + +def parse_email_datetime(date_str): + """Try to parse the Date header into YYYY-MM-DD_HH-MM format""" + try: + parsed_date = email.utils.parsedate_to_datetime(date_str) + return parsed_date.strftime('%Y-%m-%d_%H-%M') + except Exception: + return "unknown-date" + +# Read the whole file +with open(input_file, "rb") as f: + raw_data = f.read() + +# Split raw emails (assuming mbox format with "From " separator) +emails = raw_data.split(b'\nFrom ') + +# If first email doesn't start with "From ", fix it +if emails and not emails[0].startswith(b'From '): + emails[0] = b'From ' + emails[0] + +# Save the first email to keep +first_email = emails[0] + +# Process the rest, ignoring the first +for raw_email in emails[1:]: + if not raw_email.strip(): + continue + + raw_email = b'From ' + raw_email # Add back separator if missing + msg = BytesParser(policy=policy.default).parsebytes(raw_email) + + subject = msg['subject'] or "No Subject" + sender = msg['from'] or "Unknown Sender" + receiver = msg['to'] or "Unknown Receiver" + date = msg['date'] or "Unknown Date" + + subject_clean = sanitize_filename(subject.strip()) + date_clean = parse_email_datetime(date) + + # Get the plain text part + if msg.is_multipart(): + for part in msg.walk(): + if part.get_content_type() == "text/plain": + body = part.get_payload(decode=True).decode(part.get_content_charset() or 'utf-8', errors='replace') + break + else: + body = "(No plain text part found)" + else: + body = msg.get_payload(decode=True).decode(msg.get_content_charset() or 'utf-8', errors='replace') + + # Create the filename: Date_Time_Subject.txt + filename = f"{date_clean}_{subject_clean}.txt" + output_path = os.path.join(output_dir, filename) + + # Write to file + with open(output_path, "w", encoding="utf-8") as out_f: + out_f.write(f"Date: {date}\n") + out_f.write(f"From: {sender}\n") + out_f.write(f"To: {receiver}\n\n") + out_f.write(body) + +# After processing, overwrite the mailbox with only the first email +with open(input_file, "wb") as f: + f.write(first_email) diff --git a/shell/autostart.sh b/shell/autostart.sh new file mode 100755 index 0000000..66ca002 --- /dev/null +++ b/shell/autostart.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Doing some default configurations +#/home/johah/scripts/mousecenter2.sh +#xdotool key Super+b +#/home/johah/scripts/mousecenter1.sh +#xdotool key Super+b + +# Launching the st terminal with neofetch and spacing on startup +st -t "FocusDone" -e bash -c 'echo " " && echo " " && echo -e " Workstation\033[0m is\033[1;92m ready\033[0m!" && echo " " && echo " " && neofetch && echo " " && cd; bash' +xsetroot -name "ZeroSum" diff --git a/shell/autostart_server.sh b/shell/autostart_server.sh new file mode 100755 index 0000000..0988e29 --- /dev/null +++ b/shell/autostart_server.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +SESSION_NAME="services" +PROJECTS_DIR="$HOME/projects" + +################################ + +# autoscan for start.sh in the projects dir + +# Array of [dirname startscript] +# Ony extra +entries=( + "djangowebtrack" "./run.sh host" +) + +################################################### + +# Scan folders +for dir in "$PROJECTS_DIR"/*/; do + dirname="$(basename "$dir")" + + if [[ -x "$dir/start.sh" ]]; then + entries+=("$dirname" "./autostart.sh") + fi +done + +# No entries found +if [[ ${#entries[@]} -eq 0 ]]; then + echo "No start scripts found in $PROJECTS_DIR." + exit 1 +fi + +# Start tmux session if it does not exist +if ! tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + tmux new-session -d -s "$SESSION_NAME" +fi + +# Get list of already existing windows +existing_windows=$(tmux list-windows -t "$SESSION_NAME" -F "#{window_name}") + +# Create new windows only if they don't already exist +for ((i = 0; i < ${#entries[@]}; i += 2)); do + dirname="${entries[i]}" + startcmd="${entries[i + 1]}" + + if echo "$existing_windows" | grep -Fxq "$dirname"; then + echo "Window '$dirname' already exists, skipping..." + else + echo "Starting '$dirname'..." + tmux new-window -t "$SESSION_NAME" -n "$dirname" "cd \"$PROJECTS_DIR/$dirname\" && $startcmd" + fi +done + +# Kill default window if empty +if tmux list-windows -t "$SESSION_NAME" | grep -q "^1: bash"; then + tmux kill-window -t "$SESSION_NAME:1" 2>/dev/null +fi + +# Attach if not inside tmux +if [[ -z "$TMUX" ]]; then + tmux attach-session -t "$SESSION_NAME" +else + echo "Already inside tmux. Session '$SESSION_NAME' updated." +fi diff --git a/shell/battery_shutdown.sh b/shell/battery_shutdown.sh new file mode 100755 index 0000000..06e0b9d --- /dev/null +++ b/shell/battery_shutdown.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Get battery percentage from /sys/class/power_supply/BAT0/capacity +BATTERY=$(cat /sys/class/power_supply/BAT0/capacity) +STATUS=$(cat /sys/class/power_supply/BAT0/status) + +echo $BATTERY +echo $STATUS + +# Only shutdown if on battery (discharging) and low +if [ "$STATUS" = "Discharging" ] && [ "$BATTERY" -lt 15 ]; then + systemctl poweroff +fi diff --git a/shell/cabalmod.sh b/shell/cabalmod.sh new file mode 100755 index 0000000..de718a0 --- /dev/null +++ b/shell/cabalmod.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Check if filename argument is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi +# Get the current directory +current_dir=$(pwd) +# Find the nearest Cabal file +cabal_file=$(find . -maxdepth 1 -type f -name "*.cabal" | head -n 1) +if [ -z "$cabal_file" ]; then + echo "Error: No Cabal file found in the current directory." + exit 1 +fi +# Extract module name from the provided filename +module_name=$(basename "$1" .hs) + +# Check if required variables are set +if [ -z "$cabal_file" ] || [ -z "$module_name" ]; then + echo "Error: cabal_file and module_name variables are not set." + exit 1 +fi + +# Find the line with "other-modules:" +other_modules_line=$(rg -e 'other-modules:' "$cabal_file") +line_number=$(rg -n -e 'other-modules:' "$cabal_file" | cut -d: -f1) + +if [[ -z "$other_modules_line" ]]; then + echo "other-modules: not found in $cabal_file" + exit 1 +fi + +# Check if the line is commented +if [[ $other_modules_line == " -- "* ]]; then + # Remove the comment "-- " + sed -i "${line_number}s/ -- other-modules:/ other-modules:/" "$cabal_file" +fi + +# Append module_name with comma +sed -i "s/ other-modules:/ other-modules: $module_name,/" "$cabal_file" +# Create the .hs file in the app directory +hs_file="./app/$1.hs" +touch "$hs_file" +# Add boilerplate code to the .hs file +echo "module $module_name where" >"$hs_file" +echo "" >>"$hs_file" +# Open the file with neovim +nvim "$hs_file" diff --git a/shell/check_git.sh b/shell/check_git.sh new file mode 100755 index 0000000..cb67788 --- /dev/null +++ b/shell/check_git.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# Read the list of Git repositories from /tmp/all_git_projects +repos=$(cat /tmp/all_git_projects) + +# Function to handle each repository +sync_repo() { + repo=$1 + if [ -d "$HOME/$repo" ]; then + cd "$HOME/$repo" || return + + if [ -d ".git" ]; then + git add . + remote_count=$(git remote -v | wc -l) + status_output=$(git status --short) + + if [ -n "$status_output" ]; then + echo "Status for: $repo" + echo "$status_output" + + if git rev-parse --verify HEAD >/dev/null 2>&1; then + last_msg=$(git log -1 --pretty=%B) + + # Use rg to check for `+ auto` at the end + if printf "%s" "$last_msg" | rg '\+ auto$' >/dev/null; then + amend_output=$(git commit --amend --no-edit 2>&1) + else + new_msg="${last_msg} + auto" + amend_output=$(git commit --amend -m "$new_msg" 2>&1) + fi + + echo "Amended last commit for $repo: $amend_output" + else + commit_output=$(git commit -m 'auto + auto' 2>&1) + echo "Initial commit for $repo: $commit_output" + fi + fi + + if [ "$remote_count" -gt 0 ]; then + fetch_output=$(git fetch --all 2>&1) + pull_output=$(git pull 2>&1) + push_output=$(git push 2>&1) + if [ -n "$fetch_output" ]; then + echo "Fetching updates for $repo: $fetch_output" + fi + if [ "$pull_output" != "Already up to date." ]; then + echo "Pulling changes for $repo: $pull_output" + fi + if [ "$push_output" != "Everything up-to-date" ]; then + echo "Pushing changes to remote for $repo: $push_output" + fi + fi + fi + fi +} + +for repo in $repos; do + basename_repo=$(basename "$repo") + case "$basename_repo" in + r_*) continue ;; + esac + sync_repo "$repo" & +done + +wait + +echo "Sync completed for all repositories." diff --git a/shell/check_language.sh b/shell/check_language.sh new file mode 100755 index 0000000..a79ee85 --- /dev/null +++ b/shell/check_language.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# List programming languages based on common installation paths + +echo "Programming languages installed on your system:" + +# Check if Python is installed +if command -v python3 &>/dev/null; then + echo "- Python" +fi + +# Check if Ruby is installed +if command -v ruby &>/dev/null; then + echo "- Ruby" +fi + +# Check if Node.js is installed +if command -v node &>/dev/null; then + echo "- Node.js" +fi + +# Check if Java is installed +if command -v java &>/dev/null; then + echo "- Java" +fi + +# Check if Go is installed +if command -v go &>/dev/null; then + echo "- Go" +fi + +# Check if PHP is installed +if command -v php &>/dev/null; then + echo "- PHP" +fi + +# Check if Rust is installed +if command -v rustc &>/dev/null; then + echo "- Rust" +fi + +# Check if C compiler is installed (GCC) +if command -v gcc &>/dev/null; then + echo "- C" +fi + +# Check if C++ compiler is installed (g++) +if command -v g++ &>/dev/null; then + echo "- C++" +fi + +# Add more checks for other languages as needed + +echo "End of list." diff --git a/shell/clipsend.sh b/shell/clipsend.sh new file mode 100755 index 0000000..61681b7 --- /dev/null +++ b/shell/clipsend.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +REMOTE_FILE="~/clip" +SEPARATOR='---xx---' + +case "$1" in +append) + clipboard_content=$(wl-paste) + formatted_content="$SEPARATOR\n$clipboard_content\n" + echo -e "$formatted_content" | ssh bi "cat >> $REMOTE_FILE" + echo "Clipboard contents appended to remote file." + ;; +retrieve) + lines=$(ssh bi "tac $REMOTE_FILE | awk '/$SEPARATOR/ {exit} {print}' | tac") + echo -e "$lines" | wl-copy + echo "Last entry copied to clipboard." + wtype $lines + ;; +*) + echo "Usage: $0 {append|retrieve}" + ;; +esac diff --git a/shell/deltmp.sh b/shell/deltmp.sh new file mode 100755 index 0000000..85a1464 --- /dev/null +++ b/shell/deltmp.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +find ~ -name ".bash_history-*.tmp" -type f -delete diff --git a/shell/diffv_wrap.sh b/shell/diffv_wrap.sh new file mode 100755 index 0000000..431ea97 --- /dev/null +++ b/shell/diffv_wrap.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +OLD="$1" +NEW="$2" +MERGED="$3" # Optional +BASE="$4" # Optional + +#shift 4 # Shift all four known arguments +PATHS="$@" # Everything left are additional paths/options + +# Quoting and checking empty variables safely +if [ -d "$OLD" ]; then + # Directory diff + nvim -d -c "DiffviewFileHistory" + if [ -z "$PATHS" ]; then + # nvim -d "$OLD" "$NEW" -c "DiffviewFileHistory" + echo "starting diff view wrapper with no paths" + + else + #nvim -d "$OLD" "$NEW" -c "DiffviewFileHistory $PATHS" + echo "starting diff view wrapper with paths" + fi +else + # File diff + if [ -z "$MERGED" ]; then + nvim -d "$OLD" "$NEW" + else + nvim -d -c "DiffviewOpen" + if [ -z "$PATHS" ]; then + #nvim -d "$OLD" "$NEW" -c "DiffviewOpen" + echo "starting diff view wrapper with no paths" + else + #nvim -d "$OLD" "$NEW" -c "DiffviewOpen $PATHS" + echo "starting diff view wrapper with paths" + fi + fi +fi diff --git a/shell/find_gits.sh b/shell/find_gits.sh new file mode 100755 index 0000000..2fe6c22 --- /dev/null +++ b/shell/find_gits.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# Global vars +file_n="all_git_projects" + +# First get the project dirs +project_dirs=$(cat ../data/projects) + +# Get the folder name of a git project and store it in a variable +cd ~ +if [ -e "/tmp/$file_n" ]; then + folder=$(fzf <"/tmp/$file_n") +else + # Store the result + # #################### Exclusion + git_repos=$(find . -type d \( -path ./.cache -o -path ./.local -o -path ./SCRATCH -o -path ./BACKUP_YESTERDAY \) -prune -o -name '.git' -print | sed 's|^\./||; s|/.git||') + combined_repos=$(echo -e "$git_repos\n$project_dirs") + echo "$combined_repos" >"/tmp/$file_n" + folder=$(echo "$combined_repos" | fzf) +fi + +# Ensure folder is not empty +if [ -n "$folder" ]; then + #session_name=$(basename "$folder") # Use only the last part of the path as session name + session_name=$(echo "$folder" | sed 's/\.\([^ ]*\)/_\1/g') + + if tmux has-session -t "$session_name" 2>/dev/null; then + if [ -n "$TMUX" ]; then + tmux switch-client -t "$session_name" # If inside tmux, switch session + else + tmux attach-session -t "$session_name" # If outside tmux, attach session + fi + else + cd $folder + tmux new-session -d -s "$session_name" + if [ -n "$TMUX" ]; then + tmux switch-client -t "$session_name" # If inside tmux, switch session + else + tmux attach-session -t "$session_name" # If outside tmux, attach session + fi + fi +else + echo "No selection made." +fi + +exit diff --git a/shell/get_vol.sh b/shell/get_vol.sh new file mode 100755 index 0000000..981ba9e --- /dev/null +++ b/shell/get_vol.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Get the current active sink +active_sink=$(pactl info | grep 'Default Sink:' | awk '{print $3}') + +# Check which sink is active and get its volume +if [ "$active_sink" == "alsa_output.pci-0000_01_00.1.hdmi-stereo" ] || [ "$active_sink" == "alsa_output.pci-0000_00_1f.3.analog-stereo" ]; then + volume=$(pactl list sinks | grep -A 10 "Name: $active_sink" | grep -m 1 'Volume:' | awk '{print $5}') + + pre='' + if [ "$active_sink" == "alsa_output.pci-0000_01_00.1.hdmi-stereo" ]; then pre='M'; elif [ "$active_sink" == "alsa_output.pci-0000_00_1f.3.analog-stereo" ]; then pre='H'; fi + + if [ $(pulsemixer --get-mute) -eq 0 ]; then echo "($pre) $volume"; else echo "($pre) Muted"; fi + +else + echo "Active sink not recognized." +fi diff --git a/shell/ghci_wrapper.sh b/shell/ghci_wrapper.sh new file mode 100755 index 0000000..317411b --- /dev/null +++ b/shell/ghci_wrapper.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Set the directory path +dir_path="app/" + +# Check if the directory exists and contains at least one .hs file +if [ -d "$dir_path" ] && [ "$(ls -A $dir_path/*.hs 2>/dev/null)" ]; then + # If the directory exists and contains .hs files, execute ghci with them + ghci "$dir_path"*.hs +else + # If the directory doesn't exist or doesn't contain .hs files, execute ghci without them + ghci +fi diff --git a/shell/giter.sh b/shell/giter.sh new file mode 100755 index 0000000..b07f90c --- /dev/null +++ b/shell/giter.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +git add . +git commit -a -m 'auto commit' + +git fetch -a +git pull + +git push diff --git a/shell/hitcc.sh b/shell/hitcc.sh new file mode 100755 index 0000000..097665a --- /dev/null +++ b/shell/hitcc.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +xdotool key Super+b & diff --git a/shell/hyprfix.sh b/shell/hyprfix.sh new file mode 100755 index 0000000..4e7bd54 --- /dev/null +++ b/shell/hyprfix.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +file=~/configuration/dotfiles/.config/hypr/hyprland.conf + +echo "#" >>file & +sleep 1 +sed -i '$ d' file & diff --git a/shell/initer.sh b/shell/initer.sh new file mode 100755 index 0000000..82d749f --- /dev/null +++ b/shell/initer.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +echo "WARNING THIS COULD BREAK THINGS. CONFIRM BY C-C!" +cat + +mkdir -p $HOME/projects +mkdir -p $HOME/configuration + +git clone git@gitlab.gwdg.de:j.hahn02/scripts.git $HOME/projects/scripts +git clone git@gitlab.gwdg.de:j.hahn02/nixos.git $HOME/configuration/nixos +git clone git@gitlab.gwdg.de:j.hahn02/dotfiles.git $HOME/configuration/dotfiles +git clone git@gitlab.gwdg.de:j.hahn02/brainstore.git $HOME/management/brainstore + +cd $HOME/configuration/dotfiles +bash $HOME/configuration/dotfiles/install.sh + +cd + +#scp -r syncer:sync/office $HOME/management + +# optional insta reabiuld when on nix +echo 'rebuilding nix - if there' +sudo nixos-rebuild switch --flake '/home/jonas/configuration/nixos#' diff --git a/shell/lowervolume.sh b/shell/lowervolume.sh new file mode 100755 index 0000000..6fb2aa7 --- /dev/null +++ b/shell/lowervolume.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +pulsemixer --unmute --change-volume -1 diff --git a/shell/mount_ssd.sh b/shell/mount_ssd.sh new file mode 100755 index 0000000..e4a090e --- /dev/null +++ b/shell/mount_ssd.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Configuration +SSD_LABEL="Pass500" # Replace this with the label of your SSD +MOUNT_POINT="$HOME/ExternalSSD" # Directory to mount the SSD + +# Check if the SSD is connected +SSD_DEVICE=$(lsblk -l -o LABEL,NAME | grep "$SSD_LABEL" | awk '{print $2}') +if [ -z "$SSD_DEVICE" ]; then + echo "The external SSD ($SSD_LABEL) is not connected." + exit 1 +fi + +SSD_DEVICE="/dev/$SSD_DEVICE" + +# Check if the directory exists; if not, create it +if [ ! -d "$MOUNT_POINT" ]; then + mkdir -p "$MOUNT_POINT" + echo "Created mount point at $MOUNT_POINT." +fi + +# Mount the SSD +sudo mount "$SSD_DEVICE" "$MOUNT_POINT" +if [ $? -ne 0 ]; then + echo "Failed to mount $SSD_DEVICE to $MOUNT_POINT." + exit 1 +fi + +# Change ownership to the current user +sudo chown -R "$(id -u):$(id -g)" "$MOUNT_POINT" +if [ $? -ne 0 ]; then + echo "Failed to set ownership for $MOUNT_POINT." + exit 1 +fi + +echo "Successfully mounted $SSD_LABEL at $MOUNT_POINT." + +# Change to the mounted directory and open a shell +cd "$MOUNT_POINT" || exit +exec $SHELL diff --git a/shell/mousecenter1.sh b/shell/mousecenter1.sh new file mode 100755 index 0000000..b60bcb0 --- /dev/null +++ b/shell/mousecenter1.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +xdotool mousemove 50 1030 diff --git a/shell/mousecenter2.sh b/shell/mousecenter2.sh new file mode 100755 index 0000000..b07829e --- /dev/null +++ b/shell/mousecenter2.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +xdotool mousemove 2970 540 diff --git a/shell/mp4.sh b/shell/mp4.sh new file mode 100755 index 0000000..da0b21f --- /dev/null +++ b/shell/mp4.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Find all .mp4 files in the current directory and subdirectories +media_files=$(find . -type f \( -name "*.mp4" -o -name "*.mp3" \)) + +# Use fzf to allow the user to select a file +selected_file=$(echo "$media_files" | fzf) + +# Check if a file was selected +if [[ -n $selected_file ]]; then + # Play the selected file with mpv + mpv "$selected_file" --save-position-on-quit +else + echo "No file selected." +fi diff --git a/shell/nix_conf.sh b/shell/nix_conf.sh new file mode 100755 index 0000000..139cc24 --- /dev/null +++ b/shell/nix_conf.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# Ensure we are in the correct directory +cd ~/configuration/nixos || { + echo "Failed to find ~/configuration/nixos" + exit 1 +} + +# Get the current generation for naming the commit later +GENERATION=$(nix-env --list-generations | tail -n 1 | awk '{print $1}') + +# Open the configuration in Neovim +nvim configuration.nix + +# Check if there are any changes to the configuration file +if git diff --quiet hosts/asus-vivo/configuration.nix; then + echo "No changes made to configuration.nix." + exit 0 +fi + +# Show the updated diff +echo -e "\n--- Changes Detected ---\n" +git diff configuration.nix + +# Build the NixOS configuration +echo -e "\n--- Building NixOS Configuration ---" +if sudo nixos-rebuild switch; then + echo -e "\n--- Build Successful ---" +else + echo -e "\n--- Build Failed ---" + exit 1 +fi + +# Commit the changes to the repo with the generation name +echo -e "\n--- Committing Changes ---" +git add configuration.nix +git commit -m "Update to generation $GENERATION" + +echo -e "\nChanges committed with message: 'Update to generation $GENERATION'" diff --git a/shell/oathi.sh b/shell/oathi.sh new file mode 100755 index 0000000..2c66e43 --- /dev/null +++ b/shell/oathi.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +KEY=LSDKFJ9879SDF98 + +oathtool --totp -b $KEY diff --git a/shell/pgadmin_run.sh b/shell/pgadmin_run.sh new file mode 100755 index 0000000..b618572 --- /dev/null +++ b/shell/pgadmin_run.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source ~/pgadmin4/bin/activate +firefox "http://127.0.0.1:5050" & +pgadmin4 diff --git a/shell/pomodoro_wrapper.sh b/shell/pomodoro_wrapper.sh new file mode 100755 index 0000000..adb30ed --- /dev/null +++ b/shell/pomodoro_wrapper.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Starting pomodoro timer +~/bin/tomatoshell $1 + +# When started without argument, then clear the console (make it visible again) +if [ "$#" -eq 0 ]; then + tput reset +fi + diff --git a/shell/raisevolume.sh b/shell/raisevolume.sh new file mode 100755 index 0000000..81a2c75 --- /dev/null +++ b/shell/raisevolume.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +pulsemixer --unmute --change-volume +1 + +pulsemixer --max-volume 80 diff --git a/shell/rnote_mapper.sh b/shell/rnote_mapper.sh new file mode 100755 index 0000000..e68cec4 --- /dev/null +++ b/shell/rnote_mapper.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +echo "okay" + +libinput debug-events | while read -r line; do + if echo "$line" | grep -q 'TABLET_PAD_BUTTON.*10 pressed'; then + echo "Tablet Button 6 pressed. Launching Rnote..." + rnote & + # optional: add `disown` if you don't want it tied to terminal + fi +done + diff --git a/shell/run_kitty.sh b/shell/run_kitty.sh new file mode 100755 index 0000000..5d6d4c4 --- /dev/null +++ b/shell/run_kitty.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# This is a script to always have only one instance of kitty running +# You can run another one if you wish if you use the menu manager +# Use tmux or the + +if hyprctl clients | grep -q 'class: kitty'; then + # Focus existing kitty + hyprctl dispatch focuswindow class:kitty +else + # No kitty window found, launch kitty + kitty & +fi diff --git a/shell/run_unison.sh b/shell/run_unison.sh new file mode 100755 index 0000000..b2e5597 --- /dev/null +++ b/shell/run_unison.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +## wrapper to make unison dynamic +#net=$(ping -c 1 hahn1.one) +#echo $net +# +#if [ $net = "" ]; then +# echo "cannot reach cloud" +#else +#fi + +# TODO: implement net logic + +unison MainAll -root "$HOME/synced" -root "ssh://jonas@hahn1.one/synced" + diff --git a/shell/screenshot.sh b/shell/screenshot.sh new file mode 100755 index 0000000..25bb4be --- /dev/null +++ b/shell/screenshot.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# Take a screenshot on wayland with swaymsg, jq, grim, slurp, and swappy +# +# Make sure the script is executable (chmod +x ./screenshot.sh) +# +# If you don't use sway, replace `swaymsg` with whatever your window manager +# gives you to query window information. +# +# Example sway configuration +# +# bindsym Print exec ~/.local/bin/screenshot.sh region +# bindsym Shift+Print exec ~/.local/bin/screenshot.sh window +# bindsym Ctrl+Print exec ~/.local/bin/screenshot.sh output +# bindsym Ctrl+Shift+Print exec ~/.local/bin/screenshot.sh all + +# region|window|output|all +mode="$1" + +case $mode in +"region") + grim -g "$(slurp)" - | swappy -f - + ;; +"window") + grim -g "$(swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"')" - | swappy -f - + ;; +"output") + grim -o $(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') - | swappy -f - + ;; +"all") + grim - | swappy -f - + ;; +*) + echo >&2 "unsupported command \"$mode\"" + echo >&2 "Usage:" + echo >&2 "screenshot.sh " + exit 1 + ;; +esac diff --git a/shell/search.sh b/shell/search.sh new file mode 100755 index 0000000..f09334d --- /dev/null +++ b/shell/search.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Usage: rgnvim KEYWORD +rg --vimgrep "$@" | + fzf --delimiter : --nth 1,2,3,4 \ + --preview 'bat --style=numbers --color=always --highlight-line {2} {1}' | + awk -F: '{print $1, $2}' | + xargs -r sh -c 'nvim +"$1" "$0"' diff --git a/shell/set_res.sh b/shell/set_res.sh new file mode 100755 index 0000000..809747f --- /dev/null +++ b/shell/set_res.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Get the list of connected displays with their modes +connected_displays=$(xrandr | grep " connected" | awk '{print $1}') + +# Extract the primary display (first in the list) +primary_display=$(echo "$connected_displays" | sed -n '1p') + +# Extract the secondary display (second in the list, if it exists) +secondary_display=$(echo "$connected_displays" | sed -n '2p') + +# Extract the highest resolution for the primary display +primary_resolution=$(xrandr | grep -A1 "^$primary_display connected" | tail -n1 | awk '{print $1}') +echo $primary_display $secondary_display $primary_resolution + +# If there's a secondary display, extract its highest resolution +if [ -n "$secondary_display" ]; then + secondary_resolution=$(xrandr | grep -A1 "^$secondary_display connected" | tail -n1 | awk '{print $1}') + + # Extract the width of the primary display to calculate the correct offset + primary_width=$(echo "$primary_resolution" | cut -d'x' -f1) + echo $primary_width + + # Set up xrandr with the detected displays, resolutions, and correct positioning + xrandr --output "$primary_display" --primary --mode "$primary_resolution" --pos 0x0 --rotate normal \ + --output "$secondary_display" --mode "$secondary_resolution" --pos "${primary_width}x0" --rotate normal +else + # If there's only one display, just set it as primary with the highest resolution + xrandr --output "$primary_display" --primary --mode "$primary_resolution" --pos 0x0 --rotate normal +fi diff --git a/shell/start_typst.sh b/shell/start_typst.sh new file mode 100755 index 0000000..cbcae78 --- /dev/null +++ b/shell/start_typst.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Get the directory and file of the current Typst file +FILE="$1" +echo $FILE +DIR=$(dirname "$FILE") +echo $DIR +PDF_FILE="${DIR}/$(basename "$FILE" .typ).pdf" + +#swaymsg workspace 2 + +# Start typst watch in the background +typst watch "$FILE" --root ../ &>/dev/null & + +sleep 1 +#swaymsg workspace 1 +sioyek --new-window "$PDF_FILE" &>/dev/null & +# Open a new workspace in Sway (workspace number 2 in this example) +# Change this workspace number as needed + +# Print process information for debugging +echo "Started typst watch and opened PDF in sioyek on workspace 2." diff --git a/shell/stop_typst.sh b/shell/stop_typst.sh new file mode 100755 index 0000000..3123a66 --- /dev/null +++ b/shell/stop_typst.sh @@ -0,0 +1,2 @@ +killall typst +killall sioyek diff --git a/shell/sync_all.sh b/shell/sync_all.sh new file mode 100755 index 0000000..e25bfcc --- /dev/null +++ b/shell/sync_all.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Path to the file containing the list of paths +file="$HOME/.syncs" + +# Iterate over each line in the file +while IFS= read -r path; do + # Process each path + cd ~/$path + # Check arguments + if [ "$1" = "out" ]; then + echo "Syncing OUT to $path ..." + bash ./sync.sh out + elif [ "$1" = "in" ]; then + echo "Syncing OUT to $path ..." + bash ./sync.sh out + else + echo "Usage: $0 [out|in]" + exit 1 + fi + + cd ~ + +done <"$file" diff --git a/shell/sync_manage.sh b/shell/sync_manage.sh new file mode 100755 index 0000000..6ca4a1c --- /dev/null +++ b/shell/sync_manage.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +#set -eu + +# need a way to use curl and rsync here +exit + +# Try to fetch a webpage +curl -Is https://www.duckduckgo.com | head -n 1 &> /dev/null + +# Check if the request was successful +if [ $? -eq 0 ]; then + # Define the local and remote directories + LOCAL_DIR="$HOME/management" + REMOTE_USER="gui" # Replace with the remote username + REMOTE_SERVER="localhost" # Replace with the remote server address + REMOTE_DIR="management" # Replace with the remote directory path + + # Log the current date and time + echo "Sync started at $(date)" + + # Use rsync to sync the local directory to the remote server + rsync -adt --update "$LOCAL_DIR/" "$REMOTE_USER@$REMOTE_SERVER:$REMOTE_DIR" + + # Check if rsync succeeded + if [ $? -eq 0 ]; then + echo "Sync completed successfully at $(date)" + else + echo "Sync failed at $(date)" + exit 1 + fi +else + echo "No internet connection." +fi + + + diff --git a/shell/tmp_note.sh b/shell/tmp_note.sh new file mode 100755 index 0000000..5d5c037 --- /dev/null +++ b/shell/tmp_note.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env zsh +# This is for nixos specific + +# simple script to create and use a temporary note file + +# Create new temporary file if not already exists for this date +if [ ! -f /tmp/notes.md ]; then + echo -e "# $(date)\n\n" >/tmp/notes.md +fi + +# Instantly enter the insert mode at the bottom for less friction +nvim -c "e /tmp/notes.md" -c "normal G" -c "normal k" -c "normal o" -c "startinsert" diff --git a/shell/toggle_wifi.sh b/shell/toggle_wifi.sh new file mode 100755 index 0000000..6ccc8b8 --- /dev/null +++ b/shell/toggle_wifi.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Check if an interface name is provided +#if [ -z "$1" ]; then +# echo "Usage: $0 " +# exit 1 +#fi + +INTERFACE="wlo1" + +# Parse the interface state from `ip a` +STATE=$(ip a show "$INTERFACE" 2>/dev/null | grep -oP '(?<=state )\w+') + +# Check if the interface exists +if [ $STATE = "UP" ]; then + sudo ip link set $INTERFACE down +else + sudo ip link set $INTERFACE up +fi diff --git a/shell/togglesink.sh b/shell/togglesink.sh new file mode 100755 index 0000000..a083dca --- /dev/null +++ b/shell/togglesink.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Execute the initial command and capture the output +sink_output=$(pacmd list-sinks | awk '/\*/ {getline; print $2}') + +# Check the output and set the default sink accordingly +if [ "$sink_output" == "" ]; then + pacmd set-default-sink 0 + echo "Default sink set to 0" +elif [ "$sink_output" == "" ]; then + pacmd set-default-sink 1 + echo "Default sink set to 1" +else + echo "Unknown sink output: $sink_output" +fi diff --git a/shell/unison_sync.sh b/shell/unison_sync.sh new file mode 100755 index 0000000..417a5ad --- /dev/null +++ b/shell/unison_sync.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +dunstify 'Sync Start' "Started to sync this to ⭐ hub" + +# Capture Unison output +OUTPUT=$(~/projects/scripts/run_unison.sh 2>&1) +LAST_LINE=$(echo "$OUTPUT" | tail -n 1) + +# Notify with last line +dunstify 'Sync Finished ✅' "$LAST_LINE" diff --git a/shell/update_stud.sh b/shell/update_stud.sh new file mode 100755 index 0000000..0e6f670 --- /dev/null +++ b/shell/update_stud.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +cd ~/projects/studCrawl + +# List your dependencies here (space-separated, Nix/Nixpkgs attribute names) +PYTHON_DEPS="requests beautifulsoup4" + +# Optional: set path to your main script +SCRIPT="src/just_update.py" + +# Call nix-shell with your dependencies; -p means "with these packages in environment" +nix-shell -p "python3.withPackages (ps: with ps; [ $PYTHON_DEPS ])" --run "python3 $SCRIPT"