https://blog.sebastian-daschner.com/entries/custom-git-subco...
Many "built-in" Git commands are themselves separate executables. My Linux machine has them in `/usr/lib/git-core/`, and my macOS machine has them in `/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/`.
!/bin/zsh
alias git_my_branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
local selected_branch=$(git_my_branches --color | fzf --ansi --tac | awk '{print $1}')
if [ "$selected_branch" != '*' ]; then
git checkout $selected_branch
fi [user@user ~]# cat > ~/bin/git-test-me <<'EOF'
#!/bin/bash
echo hi
EOF
[user@user ~]# chmod +x ~/bin/git-test-me
[user@user ~]# git test-me
hiMany Linux tools do this. Rust's cargo is another.
In fact, `man` itself can take multiple positional arguments and will concatenate them with a hyphen to perform the lookup.
You configure a ~/.git-authors file with people with whom you regularly pair, and use `git duet [author-1] [author-2]` to set primary and secondary commit authors. Env variables set whether you want `Signed-off-by` or `Co-authored-by` trailers.
There seems to be at least these three advantages over my approach:
- `git duet` has neat syntax for attributing more than two people.
- `git duet` lets me enter a mode where it keeps attributing my co-authors.
- `git duet` keeps the authors in a separata data file, not in the script.
I might consider switching for the next small project. :-) zstyle ':completion:*:*:git:*' user-commands ${${(M)${(k)commands}:#git-*}/git-/}
Or specify just the ones you want to be completed: zstyle ':completion:*:*:git:*' user-commands foo:'description for foo'
(from /usr/share/zsh/functions/Completion/Unix/_git)My .gitconfig has:
[pretty]
co-authored-by = Co-authored-by: %an <%ae>
[alias]
co-authored-by = log -1 --pretty=co-authored-by --regexp-ignore-case --author
Now `git co-authored-by Tom` generates a Co-authored-by: trailer for the last person named Tom who committed to the repo. Typically I'd just do `:r !git co-authored-by Name` in vim (mapped to \gc to save typing).To the OP: You might be able to simplify the script by using `git commit --trailer …`. Or maybe you tried that and it didn't display the message in the editor window satisfactorily?
For some reason `--trailer` is not available on my system, so I'd need to upgrade git, it seems.
I eventually got tired of writing that manually, so I wrote a small
that works just like 'git commit', except it adds another line to the commit message template.Placing it in e.g. ~/bin/git-co-commit and having ~/bin in your $PATH will enable it as a git sub-command.
I've never had a use for this before, and I don't think I'll need it much beyond this team, but this was my first git sub-command that wasn't trivially solvable by existing command parameters (that I know of).
https://gist.github.com/sshine/d5a2986a6fc377b440bc8aa096037...