From 0ad0ccb0c8fefe3e39e8e9320dd5c34927089812 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sun, 28 Aug 2022 16:07:22 +0200 Subject: [PATCH] git: Make `commit-last-msg` available as alias Move `git-commit-last-msg` into an autoloadable function. This way it can also be executed as external script and thus in a git alias. This makes it additionally possible to call it in vim over fugitive's `:Git`. --- .config/git/config | 1 + .config/zsh/autoload/git/git-commit-last-msg | 12 ++++++++++++ .config/zsh/zshrc.d/40-functions.zsh | 12 ------------ 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100755 .config/zsh/autoload/git/git-commit-last-msg diff --git a/.config/git/config b/.config/git/config index 85cfffc..0d60b44 100644 --- a/.config/git/config +++ b/.config/git/config @@ -15,6 +15,7 @@ # Implemented as zsh functions or external programs checkout-worktree = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-checkout-worktree\"" + commit-last-msg = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-commit-last-msg\"" filter-repo = !git-filter-repo flog = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/glog\"" ssync = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-ssync\"" diff --git a/.config/zsh/autoload/git/git-commit-last-msg b/.config/zsh/autoload/git/git-commit-last-msg new file mode 100755 index 0000000..392fa65 --- /dev/null +++ b/.config/zsh/autoload/git/git-commit-last-msg @@ -0,0 +1,12 @@ +#!/usr/bin/env zsh + +# Commit, but put the last written commit message into the editor buffer. +# For this it uses .git/COMMIT_EDITMSG but deletes all lines after and including +# the first comment of the file. +# Useful for example when the commit-msg hook fails but only slight +# modifications are needed. +# Additional arguments (for example `-n` to bypass the hooks) can be passed. + +local gitdir +gitdir="$(git rev-parse --git-dir)" || return +git commit -eF <(sed -n '/^#/q;p' "$gitdir/COMMIT_EDITMSG") "$@" diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index 8d39d1d..04fee06 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -393,18 +393,6 @@ cd() { fi } -# Commit, but put the last written commit message into the editor buffer. -# For this it uses .git/COMMIT_EDITMSG but deletes all lines after and including -# the first comment of the file. -# Useful for example when the commit-msg hook fails but only slight -# modifications are needed. -# Additional arguments (for example `-n` to bypass the hooks) can be passed. -git-commit-last-msg() { - local gitdir - gitdir="$(git rev-parse --git-dir)" || return - git commit -eF <(sed -n '/^#/q;p' "$gitdir/COMMIT_EDITMSG") "$@" -} - nvim-man() { # Use nvim only if it exists, there was just one argument passed, that # argument is not an option (e.g. `--version`) and stdout is a terminal.