by pluc · 4y ago · 0 comments
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.