Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

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