From 289efb71722f8b7e49e91b529cf0b6d9ab050269 Mon Sep 17 00:00:00 2001 From: lew Date: Thu, 30 Oct 2025 22:31:59 +0000 Subject: [PATCH] Add .local/bin/fishify_envs Add .local/bin/hyprtoggle Add .local/bin/localhost Add .local/bin/tmux-sessionizer --- private_dot_local/bin/executable_fishify_envs | 20 ++++++++ private_dot_local/bin/executable_hyprtoggle | 46 ++++++++++++++++++ private_dot_local/bin/executable_localhost | 13 +++++ .../bin/executable_tmux-sessionizer | 48 +++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 private_dot_local/bin/executable_fishify_envs create mode 100644 private_dot_local/bin/executable_hyprtoggle create mode 100644 private_dot_local/bin/executable_localhost create mode 100644 private_dot_local/bin/executable_tmux-sessionizer diff --git a/private_dot_local/bin/executable_fishify_envs b/private_dot_local/bin/executable_fishify_envs new file mode 100644 index 0000000..0d52a68 --- /dev/null +++ b/private_dot_local/bin/executable_fishify_envs @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +in="$1" + +if [[ -z "$in" ]]; then + echo "usage: $0 input_file" + exit 1 +fi + +while IFS= read -r line; do + [[ -z "$line" || "$line" =~ ^# ]] && continue + if [[ "$line" =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]]; then + var="${BASH_REMATCH[1]}" + val="${BASH_REMATCH[2]}" + val="${val%\"}" + val="${val#\"}" + echo "set -Ux $var \"$val\"" + fi +done < "$in" + diff --git a/private_dot_local/bin/executable_hyprtoggle b/private_dot_local/bin/executable_hyprtoggle new file mode 100644 index 0000000..193e025 --- /dev/null +++ b/private_dot_local/bin/executable_hyprtoggle @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Toggle a specific optional Hyprland config in ~/.config/hypr/hyprland.conf + +RESET="\033[0m" +RED="\033[1m\033[031m" +GREEN="\033[1m\033[032m" + +CONFIG="$HOME/.config/hypr/hyprland.conf" + +hyprtoggle_list() { + grep -E "^[[:space:]#]*source = .*opts/.*\.conf" "$CONFIG" | while read -r line; do + name=$(basename "$(echo "$line" | grep -oE "[^/]+\.conf$")" .conf) + if [[ "$line" =~ ^# ]]; then + echo -e " ${RED}✗${RESET} $name" + else + echo -e " ${GREEN}✓${RESET} $name" + fi + done +} + +if [ ! -f "$CONFIG" ]; then + echo -e "${RED}✗${RESET}config not found at $CONFIG" + exit 1 +fi + +if [ -z "$1" ]; then + echo "usage: hyprtoggle " + hyprtoggle_list + exit 1 +fi + +OPT="$1" + +# Check if the line is currently active or commented +if grep -qE "^[[:space:]]*source = .*${OPT}\.conf" "$CONFIG"; then + echo -e "${RED}disabling${RESET} $OPT..." + sed -i "s|^[[:space:]]*source = \(.*${OPT}\.conf\)|# source = \1|" "$CONFIG" +elif grep -qE "^#\s*source = .*${OPT}\.conf" "$CONFIG"; then + echo -e "${GREEN}enabling${RESET} $OPT..." + sed -i "s|^#\s*source = \(.*${OPT}\.conf\)|source = \1|" "$CONFIG" +else + echo -e "${RED}✗ no matching source${RESET} for '$OPT'" + exit 1 +fi + +hyprtoggle_list diff --git a/private_dot_local/bin/executable_localhost b/private_dot_local/bin/executable_localhost new file mode 100644 index 0000000..70617fc --- /dev/null +++ b/private_dot_local/bin/executable_localhost @@ -0,0 +1,13 @@ +#!/bin/bash + +IP=$(hostname -i | awk '{print $1}') +PORT=8000 + +YELLOW=$(tput setaf 3) +BLUE=$(tput setaf 4) +BOLD=$(tput bold) +RESET=$(tput sgr0) + +echo "Serving ${YELLOW}${BOLD}$(pwd)${RESET} at ${BLUE}${BOLD}http://$IP:$PORT${RESET}" + +python3 -m http.server "$PORT" diff --git a/private_dot_local/bin/executable_tmux-sessionizer b/private_dot_local/bin/executable_tmux-sessionizer new file mode 100644 index 0000000..3afa4f4 --- /dev/null +++ b/private_dot_local/bin/executable_tmux-sessionizer @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# Adapted tmux sessionizer for ~/src/github/username/reponame layout + +SEARCH_PATHS=( + "$HOME/src/github" +) + +if [[ $# -eq 1 ]]; then + selected=$1 +else + # Find all directories two levels deep under ~/src/github (username/repo) + selected=$(find "${SEARCH_PATHS[@]}" -mindepth 2 -maxdepth 2 -type d | fzf) +fi + +# Exit if nothing selected +[[ -z $selected ]] && exit 0 + +selected_name=$(basename "$selected" | tr . _) +tmux_running=$(pgrep tmux) + +# Start tmux if not running +if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then + tmux new-session -s "$selected_name" -c "$selected" + exit 0 +fi + +if ! tmux has-session -t="$selected_name" 2> /dev/null; then + # Create a new session and rename the first window to Shell. + tmux new-session -ds "$selected_name" -c "$selected" + tmux rename-window -t "$selected_name:" "shell" + # Create a second window for Neovim. + tmux new-window -t "$selected_name:" -c "$selected" -n "neovim" + tmux send-keys -t "$selected_name:neovim" "nvim" Enter + # Create a window for git only if this is a git repository. + if [[ -d "$selected/.git" ]]; then + tmux new-window -t "$selected_name:" -c "$selected" -n "git" + tmux send-keys -t "$selected_name:git" "lazygit" Enter + fi + # Start with the Shell window selected. + tmux select-window -t "$selected_name:shell" +fi + +if [[ -z $TMUX ]]; then + tmux attach -t "$selected_name" +else + tmux switch-client -t "$selected_name" +fi