From owner-svn-ports-all@freebsd.org Mon Nov 16 01:15:04 2020 Return-Path: Delivered-To: svn-ports-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BDD2046E80C; Mon, 16 Nov 2020 01:15:04 +0000 (UTC) (envelope-from bofh@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CZB2J4kFHz3vmx; Mon, 16 Nov 2020 01:15:04 +0000 (UTC) (envelope-from bofh@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 945232569F; Mon, 16 Nov 2020 01:15:04 +0000 (UTC) (envelope-from bofh@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AG1F4Da097974; Mon, 16 Nov 2020 01:15:04 GMT (envelope-from bofh@FreeBSD.org) Received: (from bofh@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AG1F3N8097966; Mon, 16 Nov 2020 01:15:03 GMT (envelope-from bofh@FreeBSD.org) Message-Id: <202011160115.0AG1F3N8097966@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bofh set sender to bofh@FreeBSD.org using -f From: Muhammad Moinur Rahman Date: Mon, 16 Nov 2020 01:15:03 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r555439 - in head/sysutils: . gitwatch gitwatch/files X-SVN-Group: ports-head X-SVN-Commit-Author: bofh X-SVN-Commit-Paths: in head/sysutils: . gitwatch gitwatch/files X-SVN-Commit-Revision: 555439 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Nov 2020 01:15:04 -0000 Author: bofh Date: Mon Nov 16 01:15:03 2020 New Revision: 555439 URL: https://svnweb.freebsd.org/changeset/ports/555439 Log: [NEW] sysutils/gitwatch: Bash script to watch a file or folder and commit changes to a git repo A bash script to watch a file or folder and commit changes to a git repo What to use it for? * config files: some programs auto-write their config files, without waiting for you to click an 'Apply' button; or even if there is such a button, most programs offer you no way of going back to an earlier version of your settings. If you commit your config file(s) to a git repo, you can track changes and go back to older versions. This script makes it convenient, to have all changes recorded automatically. * document files: if you use an editor that does not have built-in git support (or maybe if you don't like the git support it has), you can use gitwatch to automatically commit your files when you save them, or combine it with the editor's auto-save feature to fully automatically and regularly track your changes. WWW: https://github.com/gitwatch/gitwatch Sponsored by: Bounce Experts Added: head/sysutils/gitwatch/ head/sysutils/gitwatch/Makefile (contents, props changed) head/sysutils/gitwatch/distinfo (contents, props changed) head/sysutils/gitwatch/files/ head/sysutils/gitwatch/files/gitwatch.in (contents, props changed) head/sysutils/gitwatch/files/patch-gitwatch.sh (contents, props changed) head/sysutils/gitwatch/pkg-descr (contents, props changed) Modified: head/sysutils/Makefile Modified: head/sysutils/Makefile ============================================================================== --- head/sysutils/Makefile Sun Nov 15 23:44:32 2020 (r555438) +++ head/sysutils/Makefile Mon Nov 16 01:15:03 2020 (r555439) @@ -430,6 +430,7 @@ SUBDIR += geteltorito SUBDIR += getssl SUBDIR += gigolo + SUBDIR += gitwatch SUBDIR += gkfreq SUBDIR += gkleds2 SUBDIR += gkrellflynn Added: head/sysutils/gitwatch/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sysutils/gitwatch/Makefile Mon Nov 16 01:15:03 2020 (r555439) @@ -0,0 +1,33 @@ +# Created by: Muhammad Moinur Rahman +# $FreeBSD$ + +PORTNAME= gitwatch +DISTVERSION= 0.1.a.20200814 +CATEGORIES= sysutils + +MAINTAINER= bofh@FreeBSD.org +COMMENT= Bash script to watch a file or folder and commit changes to a git repo + +LICENSE= GPLv3 +LICENSE_FILE= ${WRKSRC}/LICENSE + +RUN_DEPENDS= bash>0:shells/bash \ + git:devel/git@lite \ + inotifywait:sysutils/inotify-tools + +USES= shebangfix +USE_GITHUB= yes +USE_RC_SUBR= ${PORTNAME} + +GH_TAGNAME= e62df74 + +SHEBANG_FILES= ${WRKSRC}/${PORTNAME}.sh + +NO_ARCH= yes +NO_BUILD= yes +PLIST_FILES= bin/${PORTNAME} + +do-install: + ${INSTALL_SCRIPT} ${WRKSRC}/${PORTNAME}.sh ${STAGEDIR}${PREFIX}/bin/${PORTNAME} + +.include Added: head/sysutils/gitwatch/distinfo ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sysutils/gitwatch/distinfo Mon Nov 16 01:15:03 2020 (r555439) @@ -0,0 +1,3 @@ +TIMESTAMP = 1605403644 +SHA256 (gitwatch-gitwatch-0.1.a.20200814-e62df74_GH0.tar.gz) = d66d9fa89619a693c3441dbf59ddd11fa4048f85f63194452a68024d75aa3b8a +SIZE (gitwatch-gitwatch-0.1.a.20200814-e62df74_GH0.tar.gz) = 21889 Added: head/sysutils/gitwatch/files/gitwatch.in ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sysutils/gitwatch/files/gitwatch.in Mon Nov 16 01:15:03 2020 (r555439) @@ -0,0 +1,43 @@ +#!/bin/sh +# +# $FreeBSD:$ +# +# PROVIDE: gitwatch +# REQUIRE: DAEMON +# KEYWORD: shutdown +# +# gitwatch_enable (bool): Set it to "YES" to enable gitwatch +# Default is "NO". +# +# gitwatch_targets (path): Set the path to the target directory +# Default is %%PREFIX%%/etc. Multiple targets can be separated by spaces +# + +. /etc/rc.subr + +name="gitwatch" +rcvar="gitwatch_enable" + +start_cmd="${name}_start" + +load_rc_config $name + +: ${gitwatch_enable:=NO} +: ${gitwatch_targets:="%%PREFIX%%/etc"} +: ${gitwatch_args:="-l 10"} + +command="%%PREFIX%%/bin/${name}" +command_interpreter="%%PREFIX%%/bin/bash" +command_args="${gitwatch_args}" + +PATH="${PATH}:%%PREFIX%%/bin" + +gitwatch_start() { + + # Start a gitwatch for each target + for TARGET in ${gitwatch_targets}; do + ${command} ${command_args} "${TARGET}" >/dev/null & + done +} + +run_rc_command "$1" Added: head/sysutils/gitwatch/files/patch-gitwatch.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sysutils/gitwatch/files/patch-gitwatch.sh Mon Nov 16 01:15:03 2020 (r555439) @@ -0,0 +1,127 @@ +--- gitwatch.sh.orig 2020-11-15 05:05:21 UTC ++++ gitwatch.sh +@@ -43,6 +43,9 @@ COMMITMSG="Scripted auto-commit on change (%d) by gitw + LISTCHANGES=-1 + LISTCHANGES_COLOR="--color=always" + GIT_DIR="" ++GIT="$(which git)" ++INW="$(which inotifywait)"; ++EVENTS="${EVENTS:-close_write,move,move_self,delete,create,modify}" + + # Print a message about how to use this script + shelp () { +@@ -97,12 +100,6 @@ shelp () { + echo "It is therefore recommended to terminate the script before changing the repo's" + echo "config and restarting it afterwards." + echo "" +- echo "By default, gitwatch tries to use the binaries \"git\" and \"inotifywait\"," +- echo "expecting to find them in the PATH (it uses 'which' to check this and will" +- echo "abort with an error if they cannot be found). If you want to use binaries" +- echo "that are named differently and/or located outside of your PATH, you can define" +- echo "replacements in the environment variables GW_GIT_BIN and GW_INW_BIN for git" +- echo "and inotifywait, respectively." + } + + # print all arguments to stderr +@@ -118,11 +115,6 @@ cleanup () { + exit 0 + } + +-# Tests for the availability of a command +-is_command () { +- hash "$1" 2>/dev/null +-} +- + ############################################################################### + + while getopts b:d:h:g:L:l:m:p:r:s:e: option # Process command line options +@@ -149,65 +141,20 @@ if [ $# -ne 1 ]; then # If no command line arguments a + exit # and exit + fi + +-# if custom bin names are given for git or inotifywait, use those; otherwise fall back to "git" and "inotifywait" +-if [ -z "$GW_GIT_BIN" ]; then GIT="git"; else GIT="$GW_GIT_BIN"; fi +- +-if [ -z "$GW_INW_BIN" ]; then +- # if Mac, use fswatch +- if [ "$(uname)" != "Darwin" ]; then +- INW="inotifywait"; +- EVENTS="${EVENTS:-close_write,move,move_self,delete,create,modify}" +- else +- INW="fswatch"; +- # default events specified via a mask, see +- # https://emcrisostomo.github.io/fswatch/doc/1.14.0/fswatch.html/Invoking-fswatch.html#Numeric-Event-Flags +- # default of 414 = MovedTo + MovedFrom + Renamed + Removed + Updated + Created +- # = 256 + 128+ 16 + 8 + 4 + 2 +- EVENTS="${EVENTS:---event=414}" +- fi; +-else +- INW="$GW_INW_BIN"; +-fi +- +-# Check availability of selected binaries and die if not met +-for cmd in "$GIT" "$INW"; do +- is_command "$cmd" || { stderr "Error: Required command '$cmd' not found." ; exit 1; } +-done +-unset cmd +- + ############################################################################### + + SLEEP_PID="" # pid of timeout subprocess + + trap "cleanup" EXIT # make sure the timeout is killed when exiting script + +- + # Expand the path to the target to absolute path +-if [ "$(uname)" != "Darwin" ]; then +- IN=$(readlink -f "$1") +-else +- if is_command "greadlink"; then +- IN=$(greadlink -f "$1") +- else +- IN=$(readlink -f "$1") +- if [ $? -eq 1 ]; then +- echo "Seems like your readlink doesn't support '-f'. Running without. Please 'brew install coreutils'." +- IN=$(readlink "$1") +- fi +- fi; +-fi; ++IN=$(readlink -f "$1") + +- + if [ -d "$1" ]; then # if the target is a directory + + TARGETDIR=$(sed -e "s/\/*$//" <<<"$IN") # dir to CD into before using git commands: trim trailing slash, if any + # construct inotifywait-commandline +- if [ "$(uname)" != "Darwin" ]; then +- INW_ARGS=("-qmr" "-e" "$EVENTS" "--exclude" "'(\.git/|\.git$)'" "\"$TARGETDIR\"") +- else +- # still need to fix EVENTS since it wants them listed one-by-one +- INW_ARGS=("--recursive" "$EVENTS" "--exclude" "'(\.git/|\.git$)'" "\"$TARGETDIR\"") +- fi; ++ INW_ARGS=("-qmr" "-e" "$EVENTS" "--exclude" "'(\.git/|\.git$)'" "\"$TARGETDIR\"") + GIT_ADD_ARGS="--all ." # add "." (CWD) recursively to index + GIT_COMMIT_ARGS="" # add -a switch to "commit" call just to be sure + +@@ -215,11 +162,7 @@ elif [ -f "$1" ]; then # if the target is a single fil + + TARGETDIR=$(dirname "$IN") # dir to CD into before using git commands: extract from file name + # construct inotifywait-commandline +- if [ "$(uname)" != "Darwin" ]; then +- INW_ARGS=("-qm" "-e" "$EVENTS" "$IN") +- else +- INW_ARGS=("$EVENTS" "$IN") +- fi ++ INW_ARGS=("-qm" "-e" "$EVENTS" "$IN") + + GIT_ADD_ARGS="$IN" # add only the selected file to index + GIT_COMMIT_ARGS="" # no need to add anything more to "commit" call +@@ -260,6 +203,8 @@ if [ -n "$REMOTE" ]; then # are we pushing to a remote + PUSH_CMD="$GIT push $REMOTE $BRANCH" + fi + fi ++elif [ -n $($GIT config --get remote.origin.url) ] ; then ++ PUSH_CMD="$GIT push" + else + PUSH_CMD="" # if not remote is selected, make sure push command is empty + fi Added: head/sysutils/gitwatch/pkg-descr ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sysutils/gitwatch/pkg-descr Mon Nov 16 01:15:03 2020 (r555439) @@ -0,0 +1,17 @@ +A bash script to watch a file or folder and commit changes to a git repo + +What to use it for? + +* config files: some programs auto-write their config files, without waiting +for you to click an 'Apply' button; or even if there is such a button, most +programs offer you no way of going back to an earlier version of your settings. +If you commit your config file(s) to a git repo, you can track changes and go +back to older versions. This script makes it convenient, to have all changes +recorded automatically. +* document files: if you use an editor that does not have built-in git support +(or maybe if you don't like the git support it has), you can use gitwatch to +automatically commit your files when you save them, or combine it with the +editor's auto-save feature to fully automatically and regularly track your +changes. + +WWW: https://github.com/gitwatch/gitwatch