-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc.fish
More file actions
28 lines (24 loc) · 962 Bytes
/
rpc.fish
File metadata and controls
28 lines (24 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function rpc --description 'Recursively print file contents in a formatted manner'
set dir (pwd) # Default to current directory
if test (count $argv) -gt 0
set dir $argv[1]
end
set -l tmpfile (mktemp)
# find and process files
find $dir -type d \( -name '.*' -prune \) -o -type f -print | while read -l file
# Check if the file contains human-readable text
if file --mime-type "$file" | grep -q 'text'
set -l relative_path (string replace -- "$dir/" "" $file)
set -l extension (string split -r . $file | tail -n1)
echo "$relative_path:" >> $tmpfile
echo '```'"$extension" >> $tmpfile
cat "$file" >> $tmpfile
echo >> $tmpfile # Add a newline
echo '```' >> $tmpfile
echo >> $tmpfile # Add another newline
end
end
# copy contents to clipboard and clean up
wl-copy < $tmpfile
rm $tmpfile
end