summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2021-03-29 08:53:34 +0200
committerErich Eckner <git@eckner.net>2021-03-29 08:53:34 +0200
commit522c8cb129904ec9d5098a880fcc1d2bc942b846 (patch)
tree0517b430101fd4ea8676e54caf6acf343e9992b7
downloadeven-more-utils-0.0.tar.xz
initial commit: make-permanently, pdiff, screen-rv0.0
-rw-r--r--.gitignore3
-rw-r--r--Makefile55
-rwxr-xr-xmake-permanently.in86
-rwxr-xr-xpdiff.in24
-rwxr-xr-xscreen-r.in16
5 files changed, 184 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4b04d5c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+make-permanently
+pdiff
+screen-r
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9cf3be2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,55 @@
+#
+# even-more-utils - utils even missing from moreutils
+#
+# Copyright (c) 2021 Erich Eckner <opensource at eckner dot net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+#
+
+DESTDIR =
+BINDIR = /usr/bin
+
+VERSION = 0.0
+BINS=make-permanently pdiff screen-r
+
+all: $(BINS)
+
+%: %.in
+ sed " \
+ s/#VERSION#/$(VERSION)/; \
+ s@#BINDIR#@$(BINDIR)@; \
+ s@#HELPTEXT#\(\s\+\)#@ --help \1display this help and exit\n --version\1display version and exit@; \
+ " $< > $@
+ [ -z "${@%%*.*}" ] || chmod +x "$@"
+
+.PHONY: install dist clean
+
+install: all
+ install -D -m0755 -t $(DESTDIR)$(BINDIR) $(BINS)
+
+clean:
+ ls -A | \
+ grep "^\($(shell sed 's|\.|\\.|; s|\*|.*|; s|$$|\\|' .gitignore | tr '\n' '\|')\)\$$" | \
+ xargs -r rm
+
+dist: clean
+ git status --porcelain 2> /dev/null | grep -q "\S" && (git add .; git commit -m"neue Version: $(VERSION)") || true
+ ! git tag -d v$(VERSION) 2> /dev/null
+ git tag v$(VERSION)
+ git push
+ git push --tags
+
+# End of file
diff --git a/make-permanently.in b/make-permanently.in
new file mode 100755
index 0000000..659517a
--- /dev/null
+++ b/make-permanently.in
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# part of even-more-utils, version #VERSION#
+
+# run make as soon as needed
+
+if [ "x$1" = 'x-r' ]; then
+ recursive=true
+ shift
+else
+ recursive=false
+fi
+
+make "$@"
+
+while true; do
+ if ${recursive}; then
+ inotifywait -e DELETE_SELF,CLOSE_WRITE -r * || break
+ else
+ make_content=$(
+ sed '
+ :a
+ \/\\$/ {
+ N
+ s/\\\n//
+ ta
+ }
+ /^\(\s\|$\)/d
+ ' 'Makefile' \
+ | while read -r line; do
+ if [ -z "${line##\$(foreach *,*,*)*}" ]; then
+ line="${line#\$(foreach }"
+ var="${line%%,*}"
+ line="${line#${var}*,}"
+ runs="${line%,*}"
+ line="${line#${runs},}"
+ body="${line%%)*}"
+ line="${line#${body})}"
+ while [ $(printf '%s\n' "${body}" | tr -d '\n' | tr ')' '\n' | wc -l) -lt $(printf '%s\n' "${body}" | tr -d '\n' | tr '(' '\n' | wc -l) ] \
+ && [ -z "${line##*)*}" ]; do
+ new_body="${line%%)*}"
+ body="${body})${new_body}"
+ line="${line#${new_body})}"
+ done
+ for s in ${runs}; do
+ printf '%s' "${body}" \
+ | sed '
+ s#\$('"${var}"')#'"${s}"'#g
+ '
+ done \
+ | sed '
+ s/^\s\+//
+ s/\s\+$//
+ '
+ fi
+ printf '%s\n' "${line}"
+ done
+ )
+ substs=$(
+ printf '%s\n' "${make_content}" \
+ | sed '
+ s/^\([^[:space:]=]\+\)=\(.*\)$/s@\1@ \2 @g;\n/
+ t
+ d
+ '
+ )
+ watch_files=$(
+ printf '%s\n' "${make_content}" \
+ | sed "${substs}" \
+ | sed -n '
+ s/^\S.*: //
+ T
+ y/ /\n/
+ p
+ ' \
+ | sed '
+ /^\s*$/d
+ y/%/*/
+ ' \
+ | xargs -r readlink -f \
+ | sort -u
+ )
+ inotifywait -e DELETE_SELF,CLOSE_WRITE $(find ${watch_files} -type f) || break
+ fi
+ make "$@"
+done
diff --git a/pdiff.in b/pdiff.in
new file mode 100755
index 0000000..0483d2c
--- /dev/null
+++ b/pdiff.in
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# part of even-more-utils, version #VERSION#
+
+# diff with pipes
+
+if [ $# -lt 3 ]; then
+ >&2 echo 'usage:'
+ >&2 echo 'pdiff file1 file2 pipe_command [options to diff]'
+ exit 1
+fi
+
+file_one="$1";
+file_two="$2";
+pipe_cmd="$3";
+shift 3
+
+diff "$@" <(
+ cat "${file_one}" \
+ | bash -c "${pipe_cmd}"
+) <(
+ cat "${file_two}" \
+ | bash -c "${pipe_cmd}"
+)
diff --git a/screen-r.in b/screen-r.in
new file mode 100755
index 0000000..4306949
--- /dev/null
+++ b/screen-r.in
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# part of even-more-utils, version #VERSION#
+
+# iterate `screen -r` through all screen sessions
+
+for s in $(
+ screen -list "$@" \
+ | sed '
+ s/^\s\+\(\S\+\)\s.*$/\1/
+ t
+ d
+ '
+); do
+ screen -r "$s"
+done