]> git.madduck.net Git - etc/zsh.git/blobdiff - .zsh/zshrc/85-git-annex

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
[etc/zsh.git] / .zsh / zshrc / 85-git-annex
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