handle zone file comments
[cedit] / cedit
diff --git a/cedit b/cedit
index 9b21969b4ce204a518fd125f961af14a5c5881fb..09d7b824df54f2c29075d7feb248804e70b34e64 100755 (executable)
--- a/cedit
+++ b/cedit
@@ -24,18 +24,24 @@ The section is #comment delimited. Reads STDIN for the contents of the
 section. Without SECTION_NAME, it acts on a global unnamed
 section. cedit is short for config edit.
 
+-q         Quiet
+-s         Silent. Quiet and exit 0 on modified file.
 -v         Verbose
 -b         Keep backup file
 -h|--help  Help"
-  local s diff name init
-  local file_dir="$(dirname "$file")"
-  local exists=true
-  local verbose=false
-  local backup=false
+  local s diff name init file_dir exists verbose backup quiet silent
+  file_dir="$(dirname "$file")"
+  exists=true
+  verbose=false
+  backup=false
+  quiet=false
+  silent=false
 
   case $1 in
     -b) backup=true; shift ;;
     -v) verbose=true; shift ;;
+    -q) quiet=true; shift ;;
+    -s) quiet=true; silent=true; shift ;;
     -h|--help) echo "$help"; return ;;
   esac
 
@@ -47,8 +53,15 @@ section. cedit is short for config edit.
   local file="$1"
   local file_name="${file##*/}"
 
-  local begin="#_#_# start delimiter of cedit section$name. do not modify. #_#_#"
-  local end="#_#_# end delimiter of cedit section$name. do not modify. #_#_#"
+  local comment
+  comment="#_#_#"
+
+  # bind zone files use ; for comments yes, a little hacky detection.
+  if [[ $file_name == db.* ]]; then
+    comment=";;_;_;"
+  fi
+  local begin="$comment start delimiter of cedit section$name. do not modify. $comment"
+  local end="$comment end delimiter of cedit section$name. do not modify. $comment"
 
   if [[ ! -e $file_dir ]]; then
     if ! mkdir -p $file_dir; then
@@ -115,7 +128,7 @@ section. cedit is short for config edit.
   elif type -t diff &>/dev/null; then
     diff=$(diff -u "$temp" "$file")
     ret=$?
-    if (( $ret )); then
+    if (( $ret )) && ! $quiet; then
       echo "backup of original at $temp"
       echo diff -u "$temp" "$file":
       echo "$diff"
@@ -133,6 +146,13 @@ section. cedit is short for config edit.
   if ! $backup && $exists; then
     rm -r "$temp"
   fi
-  return $ret
+  if $silent; then
+    case $ret in
+      0|1) return 0 ;;
+      *) return $ret ;;
+    esac
+  else
+    return $ret
+  fi
 }
 cedit "$@"