Replaced pfiles.rb with shell equiv

This commit is contained in:
Atlas Cove 2024-11-10 11:49:53 +00:00
parent 2aa5d0625c
commit 777ae63d66
Signed by: Atlas48
GPG Key ID: 499B8E567BAB93C3
4 changed files with 76 additions and 59 deletions

2
in

@ -1 +1 @@
Subproject commit 5e986a96496f262929d217e8bac60a51d643da83
Subproject commit 4b8538e2edcae4f4b90da9de9138da62317c2223

View File

@ -1,55 +0,0 @@
#!/usr/bin/ruby
# pfiles.rb
# v1.1-p1
abort "\x1B[1;31mERR\x1B[0m: No arguments supplied" if ARGV.length == 0
require 'find'
ignore=!File.file?('dat/ignore.txt') ? [] : File.readlines('dat/ignore.txt')
if ignore != []
ignore.map! { |i| "in/#{i}" }
end
class Enumerator
def collect
out=Array.new
for i in self
out.push(i)
end
return out
end
end
l=Find.find('in').collect
case ARGV.first
when "doc"
for i in l do
next if ignore.include?(i) or /(?<!\.e)\.html$/.match?(i)
if /\.(txti|org|md|e.html)$/.match?(i)
print i
print ' ' unless i==l.last
end
end
when "sass"
for i in l do
next if ignore.include?(i)
if /\.s[ac]ss$/.match?(i)
print i
print ' ' unless i==l.last
end
end
when "dir"
for i in l do
next if ignore.include?(i) or i == ".git"
if File.directory?(i)
print i
print ' ' unless i==l.last
end
end
when "rest"
for i in l do
next if ignore.include?(i)
unless /\.(s[ac]ss|txti|org|md|html)$/.match?(i) or File.directory?(i)
print i
print ' ' unless i==l.last
end
end
else
abort "\x1B[1;31mERR\x1B[0m: Unknown option: #{ARGV.first}"
end

72
pfiles.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/bash
# Exit if no arguments provided
if [ $# -eq 0 ]; then
echo -e "\033[1;31mERR\033[0m: No arguments supplied"
exit 1
fi
# Initialize ignore patterns if ignore.txt exists
if [ -f "dat/ignore.txt" ]; then
# Create array of ignore patterns with 'in/' prefix
mapfile -t ignore < "dat/ignore.txt"
ignore_patterns=$(printf "\\|in/%s" "${ignore[@]}" | sed 's/^\\|//')
else
ignore_patterns=""
fi
# Function to check if path should be ignored
should_ignore() {
if [ -n "$ignore_patterns" ]; then
echo "$1" | grep -q "$ignore_patterns" && return 0
fi
return 1
}
case "$1" in
"doc")
# Find documentation files (.txti, .org, .md, .e.html)
find "in" -type f \( -name "*.txti" -o -name "*.org" -o -name "*.md" -o -name "*.e.html" \) \
| grep -v "\.html$" \
| while read -r file; do
[ -n "$ignore_patterns" ] && should_ignore "$file" && continue
printf "%s " "$file"
done
;;
"sass")
# Find SASS/SCSS files
find "in" -type f \( -name "*.sass" -o -name "*.scss" \) \
| while read -r file; do
[ -n "$ignore_patterns" ] && should_ignore "$file" && continue
printf "%s " "$file"
done
;;
"dir")
# Find directories
find "in" -type d ! -name ".*" \
| while read -r dir; do
[ -n "$ignore_patterns" ] && should_ignore "$dir" && continue
printf "%s " "$dir"
done
;;
"rest")
# Find all other files
find "in" -type f ! -name "*.sass" ! -name "*.scss" \
! -name "*.txti" ! -name "*.org" ! -name "*.md" ! -name "*.html" \
| while read -r file; do
[ -n "$ignore_patterns" ] && should_ignore "$file" && continue
printf "%s " "$file"
done
;;
*)
echo -e "\033[1;31mERR\033[0m: Unknown option: $1"
exit 1
;;
esac
# Print newline at the end
echo

View File

@ -15,7 +15,7 @@ function dirs {
return 0
fi
local i o dir
dir=(`./pfiles.rb dir`)
dir=(`./pfiles.sh dir`)
inf "Creating directory structure..."
echo ${dir[@]}
for i in ${dir[@]}; do
@ -30,7 +30,7 @@ function docs {
return 1
fi
local i o doc
doc=(`./pfiles.rb doc`)
doc=(`./pfiles.sh doc`)
inf "Rendering document files..."
for i in ${doc[@]}; do
o="${i/in/out}"
@ -52,7 +52,7 @@ function sassfn {
sass --no-source-map in/css:out/css
}
function other {
local o other=`./pfiles.rb rest`
local o other=`./pfiles.sh rest`
for i in $other; do
o=${i/in/out}
if test -f $o; then