summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/common/gt116
-rwxr-xr-xbin/common/gt-cmd18
-rwxr-xr-xbin/common/gt-st24
-rwxr-xr-xbin/common/gt-sync21
-rwxr-xr-xbin/extra/wd5
-rw-r--r--config/essentials/vis/visrc.lua3
6 files changed, 114 insertions, 73 deletions
diff --git a/bin/common/gt b/bin/common/gt
index 7609e90..48321af 100755
--- a/bin/common/gt
+++ b/bin/common/gt
@@ -5,21 +5,26 @@
# dependencies:
# - git
# - $EDITOR: -e
+# - parallel: optional, if installed will run the commands on all repos with parallel
repos=$HOME/sync/share/git-track.txt
# prevent file not found errors
touch "$repos" || exit 1
+which parallel >/dev/null 2>&1 && parallel=1
+
help() {
cat >&2 <<EOF
usage: gt [OPTION]
-a PATH add repo
--s update and show status of each repo
+-y show sync status
-c COMMAND run 'git COMMAND' in each repo
-h show this help
-l list repos
-e edit repos in \$EDITOR
-f FILE use FILE as list of repos
+-u pull in repos out of sync
+-s show status of files and remotes
EOF
}
@@ -31,53 +36,15 @@ fetch() {
done
}
-# Print repositories prettily
-# This function function prints animations (eg. clearing the line)
-# to stderr and the final status line is outputted to stdout.
-status() {
- while read -r repo; do
- repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")"
-
- if [ ! -d "$repo" ]; then
- printf '%s missing\n' "$repo_pretty"
- continue
- fi
-
- # absolute path
- cd "$repo"
-
- # replace line with status
- printf >&2 '\r\033[0K'
-
- status="$(git status --porcelain 2>/dev/null |
- awk '{print $1}' |
- sort | uniq | tr -s '?' |
- tr -d '\n')"
- remote="$(git branch -v 2>/dev/null |
- sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')"
-
- printf '%s %s %s\n' "$repo_pretty" "$status" "$remote"
- done <"$repos"
-}
-
-# run git command in each repo
-# $1: command
-repos_cmd() {
- while read -r repo; do
- if [ ! -d "$repo" ]; then
- printf '%s missing\n' "$repo_pretty"
- continue
- fi
-
- repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")"
- printf ''\''%s'\'' in %s' "$1" "$repo_pretty"
- (
- cd "$repo"
- git "$1" >/dev/null 2>&1
- [ $? -gt 0 ] && s="x" || s="o"
- printf '\r\033[0K%s: %s\n' "$repo_pretty" "$s"
- )
- done <"$repos"
+sync_status() {
+ if [ "$parallel" ]; then
+ parallel --colsep ' ' gt-sync {1} {2} <"$repos"
+ else
+ IFS=' '
+ while read -r repo remote_url; do
+ gt-sync "$repo" "$remote_url"
+ done <"$repos"
+ fi
}
# no options
@@ -86,30 +53,49 @@ if [ -z "$1" ]; then
exit 1
fi
-while getopts ":a:c:f:lshe" opt; do
+[ "$(wc -l <"$repos")" -gt 0 ] || exit 0
+
+while getopts ":a:c:f:lsheuy" opt; do
case "$opt" in
a)
- cd "$OPTARG" || exit 1
- r="$(git rev-parse --show-toplevel)"
- [ "$r" ] || exit 2
+ if ! cd "$OPTARG" 2>/dev/null; then
+ >&2 printf 'Not a directory.\n'
+ exit 1
+ fi
+
+ repo="$(git rev-parse --show-toplevel)"
+ remote_url="$(git remote show -n origin | awk '/^ Fetch/ {print $NF}')"
- if grep "$r" "$repos" >/dev/null 2>&1; then
+ if grep "^$repo " "$repos" >/dev/null 2>&1; then
printf >&2 'added already.\n'
- exit 2
+ exit 3
fi
- printf '%s\n' "$r" >>"$repos"
+ printf '%s %s\n' "$repo" "$remote_url" >>"$repos"
printf >&2 'added.\n'
;;
c)
- f_command=1
- f_arg="$OPTARG"
+ cut -f 1 -d ' ' "$repos" |
+ if [ "$parallel" ]; then
+ parallel gt-cmd "{}" "$OPTARG"
+ else
+ xargs -I{} gt-cmd "{}" "$OPTARG"
+ fi
;;
- s) f_status=1 ;;
- l) cat "$repos" ;;
+ s) cut -f 1 -d ' ' "$repos" | xargs -I{} gt-st {} ;;
+ y) sync_status ;;
+ l) cut -f 1 -d ' ' "$repos" ;;
e) $EDITOR "$repos" ;;
f) repos="$OPTARG" ;;
+ u)
+ sync_status | awk -F ':' '/x$/ {print $1}' |
+ if [ "$parallel" ]; then
+ parallel gt-cmd {} pull
+ else
+ xargs -I{} gt-cmd {} pull
+ fi
+ ;;
h) help ;;
:)
printf >&2 -- '-%s requires argument\n' "$OPTARG"
@@ -122,16 +108,4 @@ while getopts ":a:c:f:lshe" opt; do
esac
done
-# commands hereafter must happen in order
-
-[ "$(wc -l <"$repos")" -gt 0 ] || exit 0
-
-if [ "$f_command" ]; then
- repos_cmd "$f_arg"
-fi
-
-if [ "$f_status" ]; then
- status
-fi
-
# eval "herbe $(status | sed 's/"/\"/g;s/.*/"&"/' | tr '\n' ' ')"
diff --git a/bin/common/gt-cmd b/bin/common/gt-cmd
new file mode 100755
index 0000000..66efd50
--- /dev/null
+++ b/bin/common/gt-cmd
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# path to repo
+repo="$1"
+# git command
+command="$2"
+[ "$#" -lt 2 ] && exit 1
+
+repo_pretty="$(printf '%s' "$repo" | sed "s@^$HOME@~@")"
+
+if [ ! -d "$repo" ]; then
+ printf '%s missing\n' "$repo_pretty"
+ exit 1
+fi
+
+git -C "$repo" "$command" >/dev/null 2>&1
+[ $? -gt 0 ] && s="x" || s="o"
+printf '%s: %s\n' "$repo_pretty" "$s"
diff --git a/bin/common/gt-st b/bin/common/gt-st
new file mode 100755
index 0000000..98184b9
--- /dev/null
+++ b/bin/common/gt-st
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Print status of the repo locally
+
+# path to repo
+repo="$1"
+[ "$1" ] || exit 1
+
+repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")"
+
+if [ ! -d "$repo" ]; then
+ printf '%s missing\n' "$repo_pretty"
+ exit 1
+fi
+
+# replace line with status
+status="$(git -C "$repo" status --porcelain 2>/dev/null |
+ awk '{print $1}' |
+ sort | uniq | tr -s '?' |
+ tr -d '\n')"
+remote="$(git -C "$repo" branch -v 2>/dev/null |
+ sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')"
+
+printf '%s %s %s\n' "$repo_pretty" "$status" "$remote"
diff --git a/bin/common/gt-sync b/bin/common/gt-sync
new file mode 100755
index 0000000..0dc986c
--- /dev/null
+++ b/bin/common/gt-sync
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Print if repo is out of sync or not
+
+# path to repo
+repo="$1"
+# remote for repo
+remote="$2"
+[ "$#" -lt 2 ] && exit 1
+
+repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")"
+
+ref="$(git -C "$repo" symbolic-ref HEAD)"
+local_hash="$(git -C "$repo" rev-parse "$ref")"
+remote_hash="$(git ls-remote "$remote" "$ref" | cut -f 1)"
+
+if [ "$remote_hash" != "$local_hash" ]; then
+ printf '%s: x\n' "$repo_pretty"
+else
+ printf '%s: o\n' "$repo_pretty"
+fi
diff --git a/bin/extra/wd b/bin/extra/wd
index 1b56aa6..b0e91a0 100755
--- a/bin/extra/wd
+++ b/bin/extra/wd
@@ -1,6 +1,7 @@
#!/bin/sh
-[ "$1" ] || exit 1
-dict "$1" |
+[ "$1" ] && word="$1" || exit 1
+shift
+dict "$word" $@ |
sed -e '/^ /!d;s/^ //' |
sed -e '/^$/d;s/^[^ ].*$/\o033[1;4;34m&\o033[0m/' |
diff --git a/config/essentials/vis/visrc.lua b/config/essentials/vis/visrc.lua
index 3bfe594..577712a 100644
--- a/config/essentials/vis/visrc.lua
+++ b/config/essentials/vis/visrc.lua
@@ -134,6 +134,9 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) -- luacheck: no unused a
-- FILETYPE OPTIONS
if win.syntax == "bash" then
+ vis:command_register("curl", function()
+ vis:command("x/ -H/ c/\\\n\t-H/")
+ end, "Split curl command on multiple lines")
map_keys(
m.NORMAL,
"\\p",