]> git.madduck.net Git - etc/zsh.git/blob - .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:

simplify tty in xterm title
[etc/zsh.git] / .zsh / zshrc / 85-git-annex
1 #
2 # set up git-annex aliases and functions
3 #
4 # Copyright © 2018 martin f. krafft <madduck@madduck.net>
5 # Released under the terms of the Artistic Licence 2.0
6 #
7 # Source repository: http://git.madduck.net/v/etc/zsh.git
8 #
9
10 alias gx='git annex'
11 alias gx\?='alias -rm gx gx[a-z]'
12 alias gxa='gx add'
13 alias gxg='gx get'
14 alias gxs='gx sync'
15 alias gxd='gx drop'
16 alias gxj='gx adjust'
17 alias gxu='gx unlock'
18 alias gxk='gx lock'
19
20 function gxi() {
21   local cdup=$(git rev-parse --show-cdup 2>/dev/null || git init --quiet)
22   [[ -n $cdup ]] && builtin cd "$cdup"
23   gx init
24 }
25
26 function gxe() {
27   setopt localoptions xtrace
28   [[ -z "$1" ]] && { echo >&2 E: missing file; return 1; }
29   local -A files
30   for f; do
31     if [[ -f "$f" ]]; then
32       gxu "$f" || return 1
33       files[$f]=$(md5sum "$f")
34     fi
35   done
36   ${EDITOR:-editor} "$@"
37   for f; do
38     [[ -f "$f" ]] || continue
39     [[ $files[$f] == "$(md5sum "$f")" ]] || gxa "$f"
40     gxk "$f"
41   done
42 }
43 compdef -a _files gxe
44
45 function gxtestfile() {
46   local fname="${1:-$(tempfile -d ${PWD})}"
47   local fname="${fname##*/}"
48   echo "${(%):-"%D{%c}"}" >| "$fname"
49   gxa "$fname"
50   gc -m"add test file $fname"
51 }
52
53 function gxl() {
54   setopt localoptions xtrace
55   local rloc="$1"
56   local dest="${2:-.}"
57
58   if [[ -z $rloc ]]; then
59     echo >&2 "E: missing remote location."
60     return 1
61   fi
62
63   local host="${rloc%%:*}"
64   local rdest="${rloc#*:}"
65   local origin="${host%%.*}"
66   local localhost="${(%):-%m}"
67   git clone --origin "$origin" "$rloc" "$dest"
68   builtin cd "$dest"
69   git annex --quiet init
70   ssh "$host" "builtin cd '$rdest' && git remote add $localhost $localhost:${PWD#${HOME}/} && git annex --quiet sync"
71   git annex sync
72 }
73 compdef gxl=scp
74
75 function gxx() {
76   #setopt localoptions xtrace
77   local mode
78   [[ $1 =~ (start|stop|q) ]] && { mode=$1; shift; }
79
80   local dir="${${1:a}:-${PWD}}"
81   if [[ ! -d $dir ]]; then
82     echo >&2 "E: directory does not exist: $dir"
83     return 1
84   elif [[ ! -d $dir/.git ]]; then
85     echo >&2 "E: not a Git repository: $dir"
86     return 1
87   fi
88
89   local escaped="$(systemd-escape "$dir")"
90   local service="git-annex-assistant@${escaped}.service"
91   local function sc() { systemctl --quiet --user "$@" "$service"; }
92   case "${mode:-start}" in
93     (start)
94       sc enable
95       sc start
96       ;;
97     (*)
98       sc is-failed && sc reset-failed
99       sc stop
100       sc disable
101       ;;
102   esac
103   sc --no-pager status
104 }
105
106 # vim:ft=zsh