diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-12-20 10:53:14 -0500 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-12-20 10:54:02 -0500 |
| commit | 7b6dbb921650e2a52929f025b67be57609fda6d4 (patch) | |
| tree | 895416312698cfe4ac61d4eed0f071d7743c0214 /.local | |
| parent | Remove openbsd conditional in zsh (diff) | |
| download | dotfiles-7b6dbb921650e2a52929f025b67be57609fda6d4.zip | |
Rework dotfiles to *only* contain dotfiles
Diffstat (limited to '.local')
| -rwxr-xr-x | .local/bin/django-test | 52 | ||||
| -rwxr-xr-x | .local/bin/get-password | 36 | ||||
| -rwxr-xr-x | .local/bin/gh-clone-all | 102 | ||||
| -rwxr-xr-x | .local/bin/migrate-to-sourcehut | 76 | ||||
| -rwxr-xr-x | .local/bin/optimize-image | 83 | ||||
| -rwxr-xr-x | .local/bin/sct-daemon | 18 | ||||
| -rwxr-xr-x | .local/bin/start-tmux | 12 | ||||
| -rwxr-xr-x | .local/bin/tree-sitter | bin | 0 -> 12489088 bytes |
8 files changed, 379 insertions, 0 deletions
diff --git a/.local/bin/django-test b/.local/bin/django-test new file mode 100755 index 0000000..f5081cf --- /dev/null +++ b/.local/bin/django-test @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +import ast +import subprocess +import sys +from pathlib import Path +from typing import override + +if len(sys.argv) < 2: + raise SystemExit("usage: django-test [--list] <func_name>") + +list_only = sys.argv[1] == "--list" +func_name = sys.argv[2] if list_only else sys.argv[1] + +repo_root = Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip()) +files = subprocess.check_output(["git", "ls-files", "*.py"], text=True, cwd=repo_root).splitlines() +hits: list[str] = [] + +for rel_path in files: + path = repo_root / rel_path + s = path.read_text(encoding="utf-8") + + if func_name not in s: + continue + t = ast.parse(s, filename=str(rel_path)) + mod = rel_path[:-3].replace("/", ".").replace("\\", ".") + + class V(ast.NodeVisitor): + cls: str | None = None + + @override + def visit_ClassDef(self, node: ast.ClassDef) -> None: + old = self.cls + self.cls = node.name + self.generic_visit(node) + self.cls = old + + @override + def visit_FunctionDef(self, node: ast.FunctionDef) -> None: + if node.name == func_name: + hits.append(f"{sys.executable} manage.py test {mod}.{self.cls+'.' if self.cls else ''}{func_name}") + self.generic_visit(node) + + V().visit(t) + +hits = sorted(set(hits)) + +if list_only or len(hits) != 1: + [print(h) for h in hits] +else: + cmd = hits[0] + print(cmd) + _ = subprocess.run(cmd, shell=True, check=True, cwd=repo_root) diff --git a/.local/bin/get-password b/.local/bin/get-password new file mode 100755 index 0000000..3b83bb7 --- /dev/null +++ b/.local/bin/get-password @@ -0,0 +1,36 @@ +#!/bin/sh +set -e + +VAULT="Private" +CREDENTIAL="" + +main() { + parse_args "$@" + op read "op://$VAULT/$CREDENTIAL/password" +} + +parse_args() { + while [ $# -gt 0 ]; do + case "$1" in + --vault) + VAULT="$2" + shift 2 + ;; + --credential) + CREDENTIAL="$2" + shift 2 + ;; + *) + echo "Usage: $0 [--vault <name>] --credential <name>" + exit 1 + ;; + esac + done + + if [ -z "$CREDENTIAL" ]; then + echo "Invalid or empty CREDENTIAL" >&2 + exit 1 + fi +} + +main "$@" diff --git a/.local/bin/gh-clone-all b/.local/bin/gh-clone-all new file mode 100755 index 0000000..77de93a --- /dev/null +++ b/.local/bin/gh-clone-all @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +# Clone all repositories from a GitHub user or organization using the gh CLI. +# +# Usage: +# gh-clone-all [--exclude-archived] [--exclude-forks] [--pull] <github-entity> [target-directory] +# +# Args: +# --exclude-archived: If set, skip archived repos (default: include all) +# --exclude-forks: If set, skip forked repos +# --pull: If set, pull latest changes in existing repos +# --limit: The maximum number of repos to clone (default: 10000) +# <github-entity>: The GitHub username or org (e.g. eugenetriguba) +# [target-directory]: Optional directory to clone repos into +set -euo pipefail + +EXCLUDE_ARCHIVED=0 +EXCLUDE_FORKS=0 +PULL_EXISTING=0 +ENTITY="" +TARGET_DIR="." +LIMIT=10000 + +main() { + parse_args "$@" + clone_all_repos +} + +parse_args() { + while [[ $# -gt 0 ]]; do + case "$1" in + --exclude-archived) + EXCLUDE_ARCHIVED=1 + shift + ;; + --exclude-forks) + EXCLUDE_FORKS=1 + shift + ;; + --pull) + PULL_EXISTING=1 + shift + ;; + --limit) + LIMIT="$2" + shift 2 + ;; + -*) + usage + ;; + *) + if [[ -z "$ENTITY" ]]; then + ENTITY="$1" + elif [[ "$TARGET_DIR" == "." ]]; then + TARGET_DIR="$1" + else + usage + fi + shift + ;; + esac + done + if [[ -z "$ENTITY" ]]; then + usage + fi + mkdir -p "$TARGET_DIR" +} + +usage() { + echo "Usage: $0 [--exclude-archived] [--exclude-forks] [--pull] [--limit] <github-entity> [target-directory]" + exit 1 +} + +clone_all_repos() { + gh repo list "$ENTITY" --limit "$LIMIT" --json name,sshUrl,archivedAt,isFork | + jq -c '.[]' | while read -r repo; do + NAME=$(echo "$repo" | jq -r '.name') + CLONE_URL=$(echo "$repo" | jq -r '.sshUrl') + ARCHIVED_AT=$(echo "$repo" | jq -r '.archivedAt') + IS_FORK=$(echo "$repo" | jq -r '.isFork') + DEST="$TARGET_DIR/$NAME" + if [[ "$EXCLUDE_ARCHIVED" -eq 1 && "$ARCHIVED_AT" != "null" ]]; then + continue + fi + if [[ "$EXCLUDE_FORKS" -eq 1 && "$IS_FORK" == "true" ]]; then + continue + fi + if [[ -d "$DEST" ]]; then + echo "Repo $NAME already exists." + if [[ "$PULL_EXISTING" -eq 1 ]]; then + echo "Pulling latest changes in $DEST" + git -C "$DEST" pull --ff-only || echo "Warning: git pull failed in $DEST, continuing..." + else + echo "Skipping $NAME (already exists)" + fi + continue + fi + echo "Cloning $CLONE_URL into $DEST" + git clone "$CLONE_URL" "$DEST" + done +} + +main "$@" diff --git a/.local/bin/migrate-to-sourcehut b/.local/bin/migrate-to-sourcehut new file mode 100755 index 0000000..d7e471a --- /dev/null +++ b/.local/bin/migrate-to-sourcehut @@ -0,0 +1,76 @@ +#!/bin/bash +set -euo pipefail +set -x + +REPOS_DIR="$HOME/src/" +SOURCEHUT_USER="eugenetriguba" + +main() { + parse_args "$@" + + cd "$REPOS_DIR" + for repo in */; do + if [ -d "$repo/.git" ]; then + echo "Processing $repo..." + cd "$repo" + + if ! git remote | grep -q "^origin$"; then + echo "No origin remote found for $repo, skipping..." + cd .. + continue + fi + + if ! git remote get-url origin | grep -q "git.sr.ht"; then + echo "Migrating $repo to SourceHut..." + + local repo_name + repo_name=$(git remote get-url origin | cut -d '/' -f 2 | cut -d '.' -f 1) + git remote remove origin + git remote add origin "git@git.sr.ht:~${SOURCEHUT_USER}/${repo_name}" + + local current_branch + current_branch=$(git branch --show-current) + if [ "$current_branch" = "master" ]; then + echo "Renaming master branch to main..." + git branch -m master main + fi + + git push --push-option visiblity="private" -u origin main + git push origin main --tags + fi + + cd .. + fi + done +} + +parse_args() { + while [[ $# -gt 0 ]]; do + case "$1" in + --repos-dir) + REPOS_DIR="$2" + shift 2 + ;; + --sourcehut-user) + SOURCEHUT_USER="$2" + shift 2 + ;; + *) + echo "Usage: $0 [--repos-dir <path>] [--sourcehut-user <username>]" + exit 1 + ;; + esac + + if [[ -z "$REPOS_DIR" || ! -d "$REPOS_DIR" ]]; then + echo "Invalid or empty REPOS_DIR: $REPOS_DIR" + exit 1 + fi + + if [[ -z "$SOURCEHUT_USER" ]]; then + echo "SOURCEHUT_USER must be specified." + exit 1 + fi + done +} + +main "$@" diff --git a/.local/bin/optimize-image b/.local/bin/optimize-image new file mode 100755 index 0000000..075684b --- /dev/null +++ b/.local/bin/optimize-image @@ -0,0 +1,83 @@ +#!/bin/sh +set -e + +quality=85 +source_img_path="" +result_img_path="" + +main() { + parse_args "$@" + + original_size=$(get_file_size "$source_img_path") + echo "Optimizing: $source_img_path -> $result_img_path (quality: $quality%)" + magick "$source_img_path" -strip -quality "${quality}%" "$result_img_path" + new_size=$(get_file_size "$result_img_path") + echo "File size: $original_size -> $new_size" +} + +parse_args() { + while [ $# -gt 0 ]; do + case $1 in + --quality) + if [ -n "$2" ] && [ "$2" -ge 1 ] && [ "$2" -le 100 ] 2>/dev/null; then + quality="$2" + shift 2 + else + echo "Error: --quality requires a number between 1 and 100" + exit 1 + fi + ;; + -h | --help) + print_usage + exit 0 + ;; + -*) + echo "Error: Unknown option $1" + print_usage + exit 1 + ;; + *) + if [ -z "$source_img_path" ]; then + source_img_path="$1" + else + echo "Error: Too many arguments" + print_usage + exit 1 + fi + shift + ;; + esac + done + + if [ -z "$source_img_path" ]; then + echo "Error: source image path is required" + print_usage + exit 1 + fi + + if [ ! -f "$source_img_path" ]; then + echo "Error: Source file '$source_img_path' does not exist" + exit 1 + fi + + result_img_path="${source_img_path%.*}.webp" +} + +print_usage() { + echo "Usage: $0 [OPTIONS] <source-img-path>" + echo "" + echo "Options:" + echo " --quality <value> Set quality (1-100, default: 85)" + echo " -h, --help Show this help message" + echo "" + echo "Examples:" + echo " $0 input.jpg" + echo " $0 --quality 90 input.jpg" + echo " $0 --quality 80 input.png" +} + +get_file_size() { + du -h "$1" | awk '{ print $1 }' +} + +main "$@" diff --git a/.local/bin/sct-daemon b/.local/bin/sct-daemon new file mode 100755 index 0000000..b16a67e --- /dev/null +++ b/.local/bin/sct-daemon @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +while true; do + hour=$(date +%H) + + if [ "$hour" -ge 6 ] && [ "$hour" -lt 18 ]; then + sct 6500 # day + elif [ "$hour" -ge 18 ] && [ "$hour" -lt 20 ]; then + sct 4500 # evening + elif [ "$hour" -ge 20 ] && [ "$hour" -lt 22 ]; then + sct 3500 # night + else + sct 3000 # late night/early morning + fi + + sleep 600 # check every 10 minutes +done diff --git a/.local/bin/start-tmux b/.local/bin/start-tmux new file mode 100755 index 0000000..fa0e110 --- /dev/null +++ b/.local/bin/start-tmux @@ -0,0 +1,12 @@ +#!/bin/sh + +readonly SESSION_NAME="$USER" + +main() { + if ! tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + tmux new-session -A -s "$SESSION_NAME" -d + fi + exec tmux attach-session -t "$SESSION_NAME" +} + +main diff --git a/.local/bin/tree-sitter b/.local/bin/tree-sitter Binary files differnew file mode 100755 index 0000000..05ed7f3 --- /dev/null +++ b/.local/bin/tree-sitter |