iankelling.org
/
git
/
cedit
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a6992c8
)
make section placement stable. slightly less verbose output
author
Ian Kelling
<iank@fsf.org>
Tue, 1 Jun 2021 01:39:00 +0000
(21:39 -0400)
committer
Ian Kelling
<iank@fsf.org>
Tue, 1 Jun 2021 01:39:00 +0000
(21:39 -0400)
cedit
patch
|
blob
|
history
diff --git
a/cedit
b/cedit
index 60bb4719aebf9729230b8b05a08ca8b30bb70667..dfee11d592c78d1e64b7442fa8a003161c621922 100755
(executable)
--- a/
cedit
+++ b/
cedit
@@
-67,21
+67,19
@@
section. cedit is short for config edit.
[[ -w $file ]] || s=sudo
[[ -w $file ]] || s=sudo
+ local in_section=false
if $exists; then
if $exists; then
+ local tailn=1
local temp="$(mktemp -d)/$file_name"
cp "$file" "$temp"
cp /dev/null "$file"
local temp="$(mktemp -d)/$file_name"
cp "$file" "$temp"
cp /dev/null "$file"
- local in_section=false
while IFS= read -r line; do
while IFS= read -r line; do
- if [[ $line == $begin ]]; then
+ tailn=$(( tailn + 1 ))
+ if [[ $line == "$begin" ]]; then
in_section=true;
in_section=true;
+ break
fi
fi
- if ! $in_section; then
- printf '%s\n' "$line" >> $file
- fi
- if [[ $line == $end ]]; then
- in_section=false;
- fi
+ printf '%s\n' "$line" >> $file
done < "$temp"
fi
done < "$temp"
fi
@@
-93,6
+91,21
@@
section. cedit is short for config edit.
$s tee -a "$file" >/dev/null <<<"$end"
fi
$s tee -a "$file" >/dev/null <<<"$end"
fi
+ if $exists && $in_section; then
+ while IFS= read -r line; do
+ if [[ $line == "$begin" ]]; then
+ in_section=true;
+ fi
+ if ! $in_section; then
+ printf '%s\n' "$line" >> $file
+ fi
+ if [[ $line == $end ]]; then
+ in_section=false;
+ fi
+ done < <(tail -n +$tailn "$temp")
+ fi
+
+
if ! $exists; then
ret=1
if $verbose; then
if ! $exists; then
ret=1
if $verbose; then
@@
-106,8
+119,8
@@
section. cedit is short for config edit.
echo "backup of original at $temp"
echo diff -u "$temp" "$file":
echo "$diff"
echo "backup of original at $temp"
echo diff -u "$temp" "$file":
echo "$diff"
-
elif $verbose
; then
- echo "No changes made to $file"
+
#elif $debug
; then
+
#
echo "No changes made to $file"
fi
else
# for systems like openwrt which don't have diff
fi
else
# for systems like openwrt which don't have diff