few fixes, mostly x related improvements
[distro-setup] / brc
diff --git a/brc b/brc
index 17fcfd83fe36747a94cb1c60157a5942140f74ab..f9c039d58aac21cb069c27721c9ac1032f2ec1c5 100644 (file)
--- a/brc
+++ b/brc
@@ -3514,6 +3514,34 @@ v() {
   fi
 }
 
+# Combine files $@ into a single file with comments between them which
+# allow splitting them back with fsplit.
+#
+# Assumes file names do not have newlines in them.
+fcomb() {
+  local f comment out
+  # generated with cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c8
+  comment='# jvvuyUsq '
+  out=~/fcomb
+  rm -f $out
+  for f; do
+    echo "$comment$f" >>$out
+    cat "$f" >>$out
+  done
+}
+fsplit() {
+  local f fin line fin_lines
+  fin=~/fcomb
+  line=1
+  fin_lines=$(wc -l "$fin" | awk '{print $1}')
+  comment='# jvvuyUsq '
+  while (( line <= fin_lines )); do
+    f=$(sed -n "${line}s/^$comment//p" "$fin")
+    sed -n "$line,/^$comment/{/^$comment/d;p}" "$fin" >"$f"
+    line=$(( line + 1 + $(wc -l "$f" | awk '{print $1}') ))
+  done
+}
+
 # * stuff that makes sense to be at the end