From: martin f. krafft Date: Mon, 8 Apr 2019 13:28:22 +0000 (+0200) Subject: add git & systemd X-Git-Url: https://git.madduck.net/etc/zsh.git/commitdiff_plain/5dc4d9aa8c7835d46aeb8afc2123c5e344a58df4?ds=sidebyside add git & systemd --- diff --git a/.gitignore.d/zsh b/.gitignore.d/zsh index 54fe9b9..17dd223 100644 --- a/.gitignore.d/zsh +++ b/.gitignore.d/zsh @@ -99,7 +99,10 @@ !/.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 index 0000000..d60ce99 --- /dev/null +++ b/.zsh/zshrc/85-git @@ -0,0 +1,30 @@ +# +# set up git aliases and functions +# +# Copyright © 2018 martin f. krafft +# 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 index 0000000..8cdb15b --- /dev/null +++ b/.zsh/zshrc/85-git-annex @@ -0,0 +1,106 @@ +# +# set up git-annex aliases and functions +# +# Copyright © 2018 martin f. krafft +# 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 index 0000000..34be874 --- /dev/null +++ b/.zsh/zshrc/85-systemd @@ -0,0 +1,13 @@ +# +# set up git aliases and functions +# +# Copyright © 2018 martin f. krafft +# 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