diff --git a/config/shared/addpaths b/config/shared/addpaths new file mode 100755 index 0000000..30f26bd --- /dev/null +++ b/config/shared/addpaths @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +set -euo pipefail + +usage() { + echo "Usage: $0 -c COMMENT_SYMBOL [-e EXCLUDE_PATTERN]... TARGET" + echo " -c Comment symbol (e.g., '#' or '//')" + echo " -e Exclude pattern (can be specified multiple times)" + echo " TARGET File or directory to process" + exit 1 +} + +comment_sym="" +excludes=() + +while getopts "c:e:h" opt; do + case $opt in + c) comment_sym="$OPTARG" ;; + e) excludes+=("$OPTARG") ;; + h) usage ;; + *) usage ;; + esac +done + +shift $((OPTIND - 1)) +[[ $# -ne 1 ]] && usage +[[ -z "$comment_sym" ]] && usage + +target="$(realpath "$1")" +base_dir="$(pwd)" + +should_exclude() { + local path="$1" + for pattern in "${excludes[@]}"; do + if [[ "$path" == *"$pattern"* ]]; then + return 0 + fi + done + return 1 +} + +process_file() { + local file="$1" + local rel_path="${file#"$base_dir"/}" + + should_exclude "$rel_path" && return + + local path_comment="$comment_sym path: $rel_path" + + # Read first two lines + local line1 line2 + IFS= read -r line1 <"$file" 2>/dev/null || line1="" + IFS= read -r line2 < <(tail -n +2 "$file") 2>/dev/null || line2="" + + # Check if path comment exists in first or second line + [[ "$line1" == *"path: "* ]] && return + [[ "$line2" == *"path: "* ]] && return + + # Insert after shebang if present, otherwise at top + if [[ "$line1" =~ ^#! ]]; then + { + echo "$line1" + echo "$path_comment" + tail -n +2 "$file" + } >"$file.tmp" + else + { + echo "$path_comment" + cat "$file" + } >"$file.tmp" + fi + + mv "$file.tmp" "$file" +} + +if [[ -f "$target" ]]; then + process_file "$target" +elif [[ -d "$target" ]]; then + while IFS= read -r -d '' file; do + process_file "$file" + done < <(find "$target" -type f -print0) +else + echo "Error: $target is not a file or directory" >&2 + exit 1 +fi diff --git a/config/shared/nvim b/config/shared/nvim index 65680cb..b84e46b 160000 --- a/config/shared/nvim +++ b/config/shared/nvim @@ -1 +1 @@ -Subproject commit 65680cb255938fe90b95737ab88a2c9089f0c599 +Subproject commit b84e46bda1d9671b7b0589e42c522a6a5cd02397 diff --git a/config/shared/zsh b/config/shared/zsh index a772d18..bfb4639 100644 --- a/config/shared/zsh +++ b/config/shared/zsh @@ -54,4 +54,4 @@ alias gcm='git commit -m' alias gp='git push' alias gst='git status' alias gd='git diff --patience --color-moved=dimmed-zebra --word-diff=plain --function-context --ignore-space-change -U3' -alias gl='git log --oneline --graph --decorate --all' +alias glg='git log --oneline --graph --decorate --all' diff --git a/manifest.json b/manifest.json index 70585d0..922ed2d 100644 --- a/manifest.json +++ b/manifest.json @@ -12,6 +12,12 @@ "to": "~/.local/bin/barg" } }, + "addpaths": { + "link": { + "from": "shared/addpaths", + "to": "~/.local/bin/addpaths" + } + }, "htop": { "link": { "from": "shared/htop", @@ -131,6 +137,7 @@ "linux-vm": [ "bin", "barg", + "addpaths", "gitignore", { "package": "htop",