8 changed files with 193 additions and 44 deletions
@ -1 +1,35 @@ |
|||||||
return { "sindrets/diffview.nvim" } |
return { |
||||||
|
"sindrets/diffview.nvim", |
||||||
|
cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewFileHistory" }, |
||||||
|
keys = { |
||||||
|
{ "<leader>gvv", "<cmd>DiffviewOpen<cr>", desc = "Diffview Open" }, |
||||||
|
{ "<leader>gvq", "<cmd>DiffviewClose<cr>", desc = "Diffview Close" }, |
||||||
|
{ "<leader>gvf", "<cmd>DiffviewFileHistory %<cr>", desc = "Browse current file history" }, |
||||||
|
{ "<leader>gvr", "<cmd>DiffviewFileHistory<cr>", desc = "Browse repo history" }, |
||||||
|
{ "<leader>gvh", "<cmd>DiffviewOpen HEAD~1<cr>", desc = "Diff vs last commit" }, |
||||||
|
{ "<leader>gvm", "<cmd>DiffviewOpen master...HEAD<cr>", desc = "Diff branch vs master" }, |
||||||
|
}, |
||||||
|
opts = { |
||||||
|
enhanced_diff_hl = true, |
||||||
|
view = { |
||||||
|
merge_tool = { |
||||||
|
layout = "diff3_mixed", |
||||||
|
}, |
||||||
|
}, |
||||||
|
file_history_panel = { |
||||||
|
log_options = { |
||||||
|
git = { |
||||||
|
all = false, |
||||||
|
}, |
||||||
|
}, |
||||||
|
win_config = { |
||||||
|
position = "bottom", |
||||||
|
height = 16, |
||||||
|
}, |
||||||
|
}, |
||||||
|
file_panel = { |
||||||
|
listing_style = "tree", |
||||||
|
win_config = { width = 35 }, |
||||||
|
}, |
||||||
|
}, |
||||||
|
} |
||||||
|
|||||||
@ -0,0 +1,7 @@ |
|||||||
|
return { |
||||||
|
"3rd/image.nvim", |
||||||
|
build = false, -- so that it doesn't build the rock https://github.com/3rd/image.nvim/issues/91#issuecomment-2453430239 |
||||||
|
opts = { |
||||||
|
processor = "magick_cli", |
||||||
|
}, |
||||||
|
} |
||||||
@ -1,26 +1,130 @@ |
|||||||
#!/bin/bash |
#!/bin/bash |
||||||
|
|
||||||
# Usage examples: |
set -euo pipefail |
||||||
# ./cat-md file1.txt file2.txt # Output multiple files as markdown |
|
||||||
# ./cat-md directory/ # Output all files in a directory |
# --- Defaults --- |
||||||
# ./cat-md file.txt | xclip -selection clipboard # Copy output to X11 clipboard |
COPY=true |
||||||
# ./cat-md file.txt | xsel --clipboard --input # Alternative using xsel |
CLIP_CMD=() |
||||||
|
|
||||||
for path in "$@"; do |
# --- Detect clipboard tool --- |
||||||
if [ -d "$path" ]; then |
detect_clipboard() { |
||||||
# If it's a directory, call ourselves with each file in it (non-recursively) |
# Pick the right tool for the session: |
||||||
for file in "$path"/*; do |
# wl-copy on Wayland, xclip/xsel on X11. Fall back to whatever exists. |
||||||
if [ -f "$file" ]; then |
if [[ "${XDG_SESSION_TYPE:-}" == "wayland" || -n "${WAYLAND_DISPLAY:-}" ]]; then |
||||||
"$0" "$file" |
if command -v wl-copy &> /dev/null; then |
||||||
fi |
CLIP_CMD=(wl-copy) |
||||||
done |
elif command -v xclip &> /dev/null; then |
||||||
elif [ -f "$path" ]; then |
CLIP_CMD=(xclip -selection clipboard) |
||||||
# If it's a file, output the path and content |
elif command -v xsel &> /dev/null; then |
||||||
echo "$path:" |
CLIP_CMD=(xsel --clipboard --input) |
||||||
echo '```' |
fi |
||||||
cat "$path" |
else |
||||||
echo |
if command -v xclip &> /dev/null; then |
||||||
echo '```' |
CLIP_CMD=(xclip -selection clipboard) |
||||||
echo |
elif command -v xsel &> /dev/null; then |
||||||
|
CLIP_CMD=(xsel --clipboard --input) |
||||||
|
elif command -v wl-copy &> /dev/null; then |
||||||
|
CLIP_CMD=(wl-copy) |
||||||
fi |
fi |
||||||
|
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: |
||||||
|
``` |
||||||
|
<contents> |
||||||
|
``` |
||||||
|
|
||||||
|
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 -n file.txt | less # pipe manually |
||||||
|
|
||||||
|
Requirements (one of): |
||||||
|
wl-copy — Wayland clipboard (from wl-clipboard) |
||||||
|
xclip — X11 clipboard (preferred on X11) |
||||||
|
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 |
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 && [[ ${#CLIP_CMD[@]} -eq 0 ]]; then |
||||||
|
echo "Warning: no clipboard tool found (tried wl-copy, xclip, xsel). 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 |
||||||
|
} |
||||||
|
|
||||||
|
if $COPY; then |
||||||
|
generate "${ARGS[@]}" | "${CLIP_CMD[@]}" |
||||||
|
echo "Copied to clipboard." >&2 |
||||||
|
else |
||||||
|
generate "${ARGS[@]}" |
||||||
|
fi |
||||||
|
|||||||
Loading…
Reference in new issue