master uint/magnolia / scripts / copy-files-to-clipboard.sh
 1#!/usr/bin/env sh
 2set -eu
 3
 4if ! command -v xclip >/dev/null 2>&1; then
 5	printf '%s\n' 'copy-files-to-clipboard: xclip was not found in PATH' >&2
 6	exit 1
 7fi
 8
 9repo_root=~/programming/c/magnolia
10file_list=$(mktemp)
11
12cleanup()
13{
14	rm -f "$file_list"
15}
16
17trap cleanup EXIT HUP INT TERM
18
19cd "$repo_root"
20
21find . \
22	\( \
23		-path './.git' -o \
24		-path './.cache' -o \
25		-path './build' -o \
26		-path './build-*' -o \
27		-path './vendor/sokol_gfx.h' -o \
28		-path './vendor/stb_image_c89.h' -o \
29		-path './vendor/small3dlib.h' -o \
30		-path './vendor/HandmadeMath.h' -o \
31		-path './subprojects/*' -o \
32	\) -prune -o \
33	-type f \
34	\( \
35		-name 'meson.build' -o \
36		-name 'meson.options' -o \
37		-name 'meson_options.txt' -o \
38		-name '*.c' -o \
39		-name '*.h' \
40	\) -print \
41	| LC_ALL=C sort > "$file_list"
42
43if [ ! -s "$file_list" ]; then
44	printf '%s\n' 'copy-files-to-clipboard: no files found' >&2
45	exit 1
46fi
47
48{
49	while IFS= read -r path; do
50		path=${path#./}
51		printf '===== %s =====\n' "$path"
52		cat -- "$path"
53		printf '\n\n'
54	done < "$file_list"
55} | xclip -selection clipboard
56
57count=$(wc -l < "$file_list" | tr -d ' ')
58printf 'Copied %s files to the clipboard.\n' "$count"