madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

add git & systemd
authormartin f. krafft <madduck@madduck.net>
Mon, 8 Apr 2019 13:28:22 +0000 (15:28 +0200)
committermartin f. krafft <madduck@madduck.net>
Mon, 8 Apr 2019 13:28:22 +0000 (15:28 +0200)
.gitignore.d/zsh
.zsh/zshrc/85-git [new file with mode: 0644]
.zsh/zshrc/85-git-annex [new file with mode: 0644]
.zsh/zshrc/85-systemd [new file with mode: 0644]

index 54fe9b9c4f04c375b39cfe3061cfbc3d7a57a7c0..17dd22384ffd51d4dd48bce39f28c0e37410cbe0 100644 (file)
 !/.zsh/zshrc/82-load_dirhashes-d
 !/.zsh/zshrc/83-reporttime
 !/.zsh/zshrc/85-direnv
+!/.zsh/zshrc/85-git
+!/.zsh/zshrc/85-git-annex
 !/.zsh/zshrc/85-mime-integration
+!/.zsh/zshrc/85-systemd
 !/.zsh/zshrc/90-ls_on_chdir
 !/.zsh/zshrc/90-run-help
 !/.zsh/zshrc/95-watch-users
diff --git a/.zsh/zshrc/85-git b/.zsh/zshrc/85-git
new file mode 100644 (file)
index 0000000..d60ce99
--- /dev/null
@@ -0,0 +1,30 @@
+#
+# set up git aliases and functions
+#
+# Copyright © 2018 martin f. krafft <madduck@madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+# Source repository: http://git.madduck.net/v/etc/zsh.git
+#
+
+alias g=git
+alias g\?='alias -rm g g[a-z]'
+alias gi='g init'
+alias gl='g clone'
+alias ga='g add'
+alias gc='g commit'
+alias gs='g status'
+alias gd='g diff'
+alias gg='g pull'
+alias gr='g rebase'
+alias gp='g push'
+
+function gtestfile() {
+  local fname="${1:-$(tempfile -d ${PWD})}"
+  local fname="${fname##*/}"
+  echo "${(%):-"%D{%c}"}" >| "$fname"
+  ga "$fname"
+  gc -m"add test file $fname"
+}
+
+# vim:ft=zsh
diff --git a/.zsh/zshrc/85-git-annex b/.zsh/zshrc/85-git-annex
new file mode 100644 (file)
index 0000000..8cdb15b
--- /dev/null
@@ -0,0 +1,106 @@
+#
+# set up git-annex aliases and functions
+#
+# Copyright © 2018 martin f. krafft <madduck@madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+# Source repository: http://git.madduck.net/v/etc/zsh.git
+#
+
+alias gx='git annex'
+alias gx\?='alias -rm gx gx[a-z]'
+alias gxa='gx add'
+alias gxg='gx get'
+alias gxs='gx sync'
+alias gxd='gx drop'
+alias gxj='gx adjust'
+alias gxu='gx unlock'
+alias gxk='gx lock'
+
+function gxi() {
+  local cdup=$(git rev-parse --show-cdup 2>/dev/null || git init --quiet)
+  [[ -n $cdup ]] && builtin cd "$cdup"
+  gx init
+}
+
+function gxe() {
+  setopt localoptions xtrace
+  [[ -z "$1" ]] && { echo >&2 E: missing file; return 1; }
+  local -A files
+  for f; do
+    if [[ -f "$f" ]]; then
+      gxu "$f" || return 1
+      files[$f]=$(md5sum "$f")
+    fi
+  done
+  ${EDITOR:-editor} "$@"
+  for f; do
+    [[ -f "$f" ]] || continue
+    [[ $files[$f] == "$(md5sum "$f")" ]] || gxa "$f"
+    gxk "$f"
+  done
+}
+compdef -a _files gxe
+
+function gxtestfile() {
+  local fname="${1:-$(tempfile -d ${PWD})}"
+  local fname="${fname##*/}"
+  echo "${(%):-"%D{%c}"}" >| "$fname"
+  gxa "$fname"
+  gc -m"add test file $fname"
+}
+
+function gxl() {
+  setopt localoptions xtrace
+  local rloc="$1"
+  local dest="${2:-.}"
+
+  if [[ -z $rloc ]]; then
+    echo >&2 "E: missing remote location."
+    return 1
+  fi
+
+  local host="${rloc%%:*}"
+  local rdest="${rloc#*:}"
+  local origin="${host%%.*}"
+  local localhost="${(%):-%m}"
+  git clone --origin "$origin" "$rloc" "$dest"
+  builtin cd "$dest"
+  git annex --quiet init
+  ssh "$host" "builtin cd '$rdest' && git remote add $localhost $localhost:${PWD#${HOME}/} && git annex --quiet sync"
+  git annex sync
+}
+compdef gxl=scp
+
+function gxx() {
+  #setopt localoptions xtrace
+  local mode
+  [[ $1 =~ (start|stop|q) ]] && { mode=$1; shift; }
+
+  local dir="${${1:a}:-${PWD}}"
+  if [[ ! -d $dir ]]; then
+    echo >&2 "E: directory does not exist: $dir"
+    return 1
+  elif [[ ! -d $dir/.git ]]; then
+    echo >&2 "E: not a Git repository: $dir"
+    return 1
+  fi
+
+  local escaped="$(systemd-escape "$dir")"
+  local service="git-annex-assistant@${escaped}.service"
+  local function sc() { systemctl --quiet --user "$@" "$service"; }
+  case "${mode:-start}" in
+    (start)
+      sc enable
+      sc start
+      ;;
+    (*)
+      sc is-failed && sc reset-failed
+      sc stop
+      sc disable
+      ;;
+  esac
+  sc --no-pager status
+}
+
+# vim:ft=zsh
diff --git a/.zsh/zshrc/85-systemd b/.zsh/zshrc/85-systemd
new file mode 100644 (file)
index 0000000..34be874
--- /dev/null
@@ -0,0 +1,13 @@
+#
+# set up git aliases and functions
+#
+# Copyright © 2018 martin f. krafft <madduck@madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+# Source repository: http://git.madduck.net/v/etc/zsh.git
+#
+
+alias sc=systemctl
+alias scu='sc --user'
+
+# vim:ft=zsh