From d38ee159edf319c7fae9392c5258fb0a7d9b1340 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Tue, 18 Jul 2023 14:30:09 +0200 Subject: [PATCH] git: Add perm-stash to save a stash to a file --- .config/git/config | 1 + .config/zsh/autoload/git/git-perm-stash | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100755 .config/zsh/autoload/git/git-perm-stash diff --git a/.config/git/config b/.config/git/config index 02e7abb..706ac25 100644 --- a/.config/git/config +++ b/.config/git/config @@ -32,6 +32,7 @@ ssync = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-ssync\"" submodule-rm = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-submodule-rm\"" track = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-track\"" + perm-stash = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-perm-stash\"" [blame] date = short [branch] diff --git a/.config/zsh/autoload/git/git-perm-stash b/.config/zsh/autoload/git/git-perm-stash new file mode 100755 index 0000000..b90c093 --- /dev/null +++ b/.config/zsh/autoload/git/git-perm-stash @@ -0,0 +1,17 @@ +#!/usr/bin/env zsh + +emulate -L zsh -eu + +local REF_LEN DIR idx stash_ref commit_ref + +REF_LEN=8 +DIR="$HOME/gitstashes" + +git rev-parse + +idx="${1:-0}" +stash_ref="$(git rev-parse stash@{$idx} | cut -c-$REF_LEN)" +commit_ref="$(git rev-parse HEAD | cut -c-$REF_LEN)" + +git stash show -up "$idx" > \ + "${2:-$DIR}/${PWD//\//__}__${commit_ref}__$stash_ref.diff"