Explorar el Código

Merge branch 'master' of git.galthub.com:gmj/home.public.bin

George Jones hace 6 meses
padre
commit
e99325f2df
Se han modificado 7 ficheros con 120 adiciones y 1 borrados
  1. 0 0
      README.org
  2. 53 0
      bin/autocommit.sh
  3. 0 0
      bin/obsolete/.link2home.ignore
  4. 0 0
      bin/obsolete/.link2home.ignore.default
  5. 53 0
      bin/orglinks.sh
  6. 13 0
      bin/orgwatch.sh
  7. 1 1
      rc.local/l.sh

+ 0 - 0
README.org


+ 53 - 0
bin/autocommit.sh

@@ -0,0 +1,53 @@
+#! /bin/bash
+# Do automatic git-commit to any changes in a diredtory
+#
+# This is intended to be used with "orglinks.sh" which creates
+# hard links for all *.org files under, e.g., $HOME to a
+# parcicular directory, e.g. ~/orgfiles
+#
+# Usage: autocommit DIR
+
+# This is bash, be safe
+set -u
+set -e
+
+# pull in my error, warning, etc.
+source ~/lib/bash/bashutils.sh
+
+# Directory provided as an argument
+dir="${1:-$HOME/orgfiles}"
+
+# Check if the provided directory exists
+if [ ! -d "$dir" ]; then
+  error "Error: Directory '$dir' does not exist."
+fi
+
+cd $dir
+
+# make sure it is a git root dir
+
+if [ -d $dir/.git ]; then
+    :
+else
+    info initializing git in $dir
+    git init .
+fi
+
+# Git commit changes if any
+if [[ $(git status --porcelain) ]]; then
+    # Changes exist, so commit them
+    info files to be added:
+    git ls-files -o *.org
+    info files changed:
+    git ls-files -m *.org
+    # Add all org files
+    info adding all .org files
+    git add *.org
+    # # get rid of anytthing that's not an .org file
+    # git clean -f
+    git commit -am "Autocommit `date`"
+    info "Changes committed."
+else
+    # No changes to commit
+    info "No changes to commit."
+fi

+ 0 - 0
bin/obsolete/.link2home.ignore


+ 0 - 0
bin/obsolete/.link2home.ignore.default


+ 53 - 0
bin/orglinks.sh

@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# ChatGPT Promt:
+#
+# write me a bash script that finds all the .org files under $HOME and
+# hard links them to ~/orgfiles/, changing the "/" in paths to "__"
+
+# This is bash, be safe
+set -u
+set -e
+
+# use my info,warn,error aliases
+source ~/lib/bash/bashutils.sh
+
+# Define source and destination directories
+source_dir="$HOME"
+destination_dir="$HOME/orgfiles"
+
+# Max hard links to make.  If I have more than 10k org files, there are problems.
+MAXFILES=10000
+
+# Create the destination directory if it doesn't exist
+mkdir -p "$destination_dir"
+
+# Find all .org files under $HOME and loop through them
+find "$source_dir" -type f -name "*.org" | grep -v "$destination_dir" | head -$MAXFILES | while read -r org_file; do
+    # Get the relative path by removing the source directory part
+    relative_path="${org_file#$source_dir/}"
+
+    # Replace "/" in paths with "__"
+    modified_relative_path1="${relative_path//\//__}"
+
+    # Replace " " in paths with "_"
+    modified_relative_path="${modified_relative_path1// /_}"
+
+
+    # Construct the destination path
+    destination_path="$destination_dir/$modified_relative_path"
+
+    # if the target file exists, continue
+
+    if [ -f $destination_path ] ; then
+        continue
+    fi
+
+    # Attempt to create a hard link to the destination
+    if ln "$org_file" "$destination_path" 2>/dev/null; then
+        info "Linked file: $org_file -> $destination_path"
+    else
+        warn "Failed to create a hard link for $org_file to $destination_path"
+    fi
+
+done

+ 13 - 0
bin/orgwatch.sh

@@ -0,0 +1,13 @@
+#! /bin/bash
+# link new .org files to ~/orgfiles and do git commint
+#
+# This should be run out of cron periodically
+#
+# Logs to /dev/tty and $LOGFILE
+
+LOGFILE=/home/gmj/var/log/orgwatch.log
+
+echo "--- Orgwatch `date` ---" |& tee /dev/tty >> ${LOGFILE}
+/home/gmj/bin/orglinks.sh |& tee /dev/tty >> ${LOGFILE}
+/home/gmj/bin/autocommit.sh |& tee /dev/tty >> ${LOGFILE}
+echo |& tee /dev/tty >> ${LOGFILE}

+ 1 - 1
rc.local/l.sh

@@ -31,7 +31,7 @@ fi
 # For good measure "sudo chattr +a $LOGTO"
 
 function l() (
-    NOW=`date +%Y-%M-%d:%H:%m:%S`
+    NOW=`date +%Y-%m-%d:%H:%M:%S`
 
     if  [  $# == 0 ]; then
         warn Nothing to log