diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-10-30 20:02:05 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-10-30 20:04:33 +0100 |
commit | d8202d4a41313921764a2bc91ff25509e2b81a94 (patch) | |
tree | acf7d7fc1a78f947c3c8d943f78257d40de9104f | |
parent | 024eaa2e466356a28324e5bff3f6a4a74a203b22 (diff) |
zsh: support showing nth most recent snapshot in restic-review
-rw-r--r-- | zsh_aliases | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/zsh_aliases b/zsh_aliases index 5feeb2f..b30ae1b 100644 --- a/zsh_aliases +++ b/zsh_aliases @@ -31,7 +31,6 @@ cond-alias mg='mg -n' cond-alias ta='tmux new-session -AD -s $LOGNAME' cond-alias week='date +%V' cond-alias reload='exec zsh' -cond-alias restic-review='restic snapshots --group-by host --host $(hostname -s) | grep -Eo "^[a-f0-9]{8,}" | tail -n2 | xargs -r restic diff' if (( $+commands[apt-mark] )); then # This is the most precise method I've found for answering the question # "which packages did I install explicitly?" @@ -41,6 +40,21 @@ if (( $+commands[apt-mark] )); then alias apt-leaves='sudo grep -oP "Unpacking \K[^: ]+" /var/log/installer/syslog | sort -u | comm -13 /dev/stdin <(apt-mark showmanual | sort)' fi +# Show restic diff for the most recent snapshot. If offset is given, show the +# diff for the nth most recent snapshot instead +function restic-review { + local -r offset="${1:-0}" + if [[ $# -gt 1 || ! "$offset" =~ ^[0-9]+$ ]]; then + echo "usage: restic-review [COUNT]" 1>&2 + return 1 + fi + restic snapshots --group-by host --host $(hostname -s) | \ + grep -Eo "^[a-f0-9]{8,}" | \ + tail -$(( 2 + $offset )) | \ + head -2 | \ + xargs -r restic diff +} + # Fuzzy-finding wrapper for brew install, info and uninstall function brew-fzf { case "$1" in |