-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsl
executable file
·34 lines (29 loc) · 847 Bytes
/
gsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# fzf search on the files in `git status` output.
# Uses fzf: https://github.com/junegunn/fzf
#
# Usage, e.g.:
# gsl diff
# gsl add
# gsl checkout - check out files
# gsl -b checkout - check out branches
#
# Use TAB to multiselect in `fzf`.
set -e
if [ "$#" -le 0 ]; then
blog error "Missing git subcommand. Do you want 'gsl add'?";
bashdoc "$BASH_SOURCE";
exit 1;
fi
gitcommand=(git status --porcelain);
formatter=(sed 's/^...//'); # Trim leading chars.
# If `-b` flag is the first argument, operate on branches.
if [ "$1" = "-b" ]; then
# Might want --sort=committerdate to sort by freshness.
gitcommand=(git branch --format='%(refname:short)');
formatter=(tee) # Noop.
shift 1;
fi
ARGS=$(${gitcommand[@]} | ${formatter[@]} | fzf -m --preview 'git -c color.diff=always diff {}' )
set -x
git "${@:1}" $ARGS