#!/bin/sh
|
|
|
|
# Help messages:
|
|
export LONG_USAGE="Select changed files using fzf and print to standard output.
|
|
|
|
Optionally, give a tree-ish to list files changed between that and the working
|
|
tree.
|
|
|
|
For example, to select from files in the last 3 commits:
|
|
|
|
git sel-changed HEAD@{3}
|
|
"
|
|
|
|
# Tell git-sh-setup we're ok with being in a subdir:
|
|
export SUBDIRECTORY_OK=1
|
|
|
|
. "$(git --exec-path)/git-sh-setup"
|
|
|
|
# Make sure we're in a working tree
|
|
require_work_tree_exists
|
|
|
|
# Jump to top level so we can use $PWD below to print absolute paths
|
|
# (this seems easier than trying to figure out relative paths from
|
|
# porcelained git-status output):
|
|
cd_to_toplevel
|
|
|
|
# For files in the working tree which are currently changed:
|
|
_list_from_status () {
|
|
# -z does NUL-terminated outputs, puts new filenames first for renamed files,
|
|
# etc. -u includes untracked files.
|
|
git status -u -z --porcelain | \
|
|
|
|
# Take from the 4th character up to end-of-line (first 3 are status chars):
|
|
cut -z -c4-
|
|
}
|
|
|
|
# For files changed since a particular tree-ish:
|
|
_list_from_treeish () {
|
|
git diff-index -z --name-only "$1"
|
|
}
|
|
|
|
run_git="_list_from_status"
|
|
if [ -n "$1" ]; then
|
|
run_git="_list_from_treeish $1"
|
|
fi
|
|
|
|
$run_git | \
|
|
|
|
# IFF we're inside a tmux, fzf-tmux will pop up in a separate pane:
|
|
fzf-tmux --multi --read0 --print0 | \
|
|
|
|
# This is ridiculous, but I never know how to combine stdin and args:
|
|
xargs -0 -I{} -n1 echo "$PWD/{}"
|