From f61518bd8d656341a5f989dd7082fa57143ded1b Mon Sep 17 00:00:00 2001 From: chodylal Date: Thu, 23 Jul 2026 06:48:49 +0200 Subject: [PATCH] trb update --- .config/i3/config | 11 +++- .local/bin/cat-md | 138 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 124 insertions(+), 25 deletions(-) diff --git a/.config/i3/config b/.config/i3/config index e7aa91f..9f2e11c 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -94,8 +94,8 @@ bindsym $mod+Control+Right move workspace to output right #------------------------------------------------ # monitors - use "xrandr --listmonitors" to obtain your output names -set $leftOutput HDMI-1 -set $rightOutput eDP-1 +set $leftOutput eDP-1 +set $rightOutput HDMI-1 # setup monitors exec --no-startup-id xrandr --output $rightOutput --primary exec --no-startup-id xrandr --output $leftOutput --left-of $rightOutput @@ -162,6 +162,13 @@ bindsym $mod+d exec --no-startup-id "PATH=$PATH:/home/chodylal/.cargo/bin:/home/ for_window [title="^launcher$"] floating enable, resize set width 500 height 430, border none +# Define the script path +set $screencast bash $scriptDir/screencast + +# Bind Mod+Shift+S to start/stop recording +bindsym $mod+Shift+s exec $screencast + + # run app assigned to current workspace bindsym $mod+Shift+a exec $scriptsDir/autoapp ################################################################# diff --git a/.local/bin/cat-md b/.local/bin/cat-md index 8e99e55..abeaa9a 100755 --- a/.local/bin/cat-md +++ b/.local/bin/cat-md @@ -1,26 +1,118 @@ #!/bin/bash -# Usage examples: -# ./cat-md file1.txt file2.txt # Output multiple files as markdown -# ./cat-md directory/ # Output all files in a directory -# ./cat-md file.txt | xclip -selection clipboard # Copy output to X11 clipboard -# ./cat-md file.txt | xsel --clipboard --input # Alternative using xsel - -for path in "$@"; do - if [ -d "$path" ]; then - # If it's a directory, call ourselves with each file in it (non-recursively) - for file in "$path"/*; do - if [ -f "$file" ]; then - "$0" "$file" - fi - done - elif [ -f "$path" ]; then - # If it's a file, output the path and content - echo "$path:" - echo '```' - cat "$path" - echo - echo '```' - echo +set -euo pipefail + +# --- Defaults --- +COPY=true +CLIP_CMD="" + +# --- Detect clipboard tool --- +detect_clipboard() { + if command -v xclip &> /dev/null; then + CLIP_CMD="xclip -selection clipboard" + elif command -v xsel &> /dev/null; then + CLIP_CMD="xsel --clipboard --input" + else + CLIP_CMD="" + fi +} + +# --- Help --- +usage() { + cat << 'EOF' +cat-md — concatenate files as a Markdown code block, copy to clipboard. + +Usage: + cat-md [OPTIONS] [FILE|DIR]... + + Each file is printed as: + path/to/file: + `` ` + + `` ` + + Directories are expanded non-recursively (all files inside). + +Options: + -n, --no-copy Print to stdout only, skip clipboard copy + -h, --help Show this help and exit + +Examples: + cat-md file1.txt file2.txt + cat-md src/ + cat-md -n file.txt # no clipboard + cat-md file.txt | wl-copy # Wayland clipboard (manual override) + +Requirements (one of): + xclip — X11 clipboard (preferred) + xsel — alternative X11 clipboard tool +EOF + exit 0 +} + +# --- Parse arguments --- +ARGS=() +while [[ $# -gt 0 ]]; do + case "$1" in + -n | --no-copy) + COPY=false + shift + ;; + -h | --help) usage ;; + --) + shift + ARGS+=("$@") + break + ;; + -*) + echo "Unknown option: $1" >&2 + echo "Try -h for help." >&2 + exit 1 + ;; + *) + ARGS+=("$1") + shift + ;; + esac +done + +# --- Validate --- +if [[ ${#ARGS[@]} -eq 0 ]]; then + echo "Error: no files or directories provided. Try -h for help." >&2 + exit 1 +fi + +detect_clipboard + +if $COPY && [[ -z "$CLIP_CMD" ]]; then + echo "Warning: neither xclip nor xsel found. Output will go to stdout only." >&2 + COPY=false +fi + +# --- Generate output --- +generate() { + for path in "$@"; do + if [[ -d "$path" ]]; then + for file in "$path"/*; do + if [[ -f "$file" ]]; then + generate "$file" + fi + done + elif [[ -f "$path" ]]; then + echo "$path:" + echo '```' + cat "$path" + echo + echo '```' + echo fi -done \ No newline at end of file + done +} + +if $COPY; then + generate "${ARGS[@]}" | $CLIP_CMD + echo "Copied to clipboard." >&2 +else + generate "${ARGS[@]}" +fi +