Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ffaf18c

Browse files
committed
add git pick command
1 parent edc6a5a commit ffaf18c

File tree

3 files changed

+91
-9
lines changed

3 files changed

+91
-9
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
git-ptt
22
git-mark
33
git-set-message
4+
git-pick

‎Makefile‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@ LN = ln
66

77
BINS = \
88
git-dot \
9-
git-mark \
9+
git-mark \
1010
git-ptt \
11-
git-set-message \
12-
git-synth
11+
git-set-message \
12+
git-synth \
13+
git-pick
1314

1415
GENERATED = \
1516
git-mark \
1617
git-ptt \
17-
git-set-message
18+
git-set-message \
19+
git-pick
1820

1921
all: $(BINS)
2022

23+
git-pick: common.sh git-pick.in.sh
24+
cat $^ > $@
25+
chmod 755 $@
26+
2127
git-mark: common.sh git-mark.in.sh
2228
cat $^ > $@
2329
chmod 755 $@
@@ -31,11 +37,7 @@ git-set-message: common.sh git-set-message.in.sh
3137
chmod 755 $@
3238

3339
install: all
34-
$(INSTALL) -m 755 git-dot $(bindir)/
35-
$(INSTALL) -m 755 git-synth $(bindir)/
36-
$(INSTALL) -m 755 git-ptt $(bindir)/
37-
$(INSTALL) -m 755 git-set-message $(bindir)/
38-
$(INSTALL) -m 755 git-mark $(bindir)/
40+
$(INSTALL) -m 755 $(BINS) $(bindir)/
3941
$(LN) -sf git-mark $(bindir)/unmark
4042

4143
clean:

‎git-pick.in.sh‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
OPTS_SPEC="\
2+
${0##*/} [<options>] [<pattern>]
3+
4+
Select references using fzf.
5+
--
6+
h,help Show the help
7+
8+
t,tags Pick tags
9+
b,branches Pick local branches (this is the default)
10+
r,remote-branches Pick remote branches
11+
a,all Pick all references
12+
m,multi Allow multiple selections
13+
c,checkout Pass selection to 'git checkout'
14+
"
15+
16+
checkout=0
17+
select_branches=0
18+
select_tags=0
19+
select_remotes=0
20+
fzf_opts=()
21+
22+
eval "$(git rev-parse --parseopt -- "$@" <<<$OPTS_SPEC || echo exit $?)"
23+
24+
while (( $# > 0 )); do
25+
case 1ドル in
26+
(-t) select_tags=1
27+
shift
28+
;;
29+
30+
(-b) select_branches=1
31+
shift
32+
;;
33+
34+
(-r) select_remotes=1
35+
shift
36+
;;
37+
38+
(-a) select_tags=1
39+
select_branches=1
40+
select_remotes=1
41+
shift
42+
;;
43+
44+
(-m) fzf_opts+=(-m)
45+
shift
46+
;;
47+
48+
(-c) checkout=1
49+
shift
50+
;;
51+
52+
(--) shift
53+
break
54+
;;
55+
56+
(-*) DIE "unknown option: 1ドル"
57+
;;
58+
esac
59+
done
60+
shift $(( OPTIND - 1 ))
61+
62+
patterns=()
63+
64+
(( $select_tags + $select_branches + $select_remotes == 0 )) && select_branches=1
65+
[[ $select_tags == 1 ]] && patterns+=(refs/tags/)
66+
[[ $select_branches == 1 ]] && patterns+=(refs/heads/)
67+
[[ $select_remotes == 1 ]] && patterns+=(refs/remotes/)
68+
69+
selected=($(
70+
git for-each-ref --format='%(refname)' "${patterns[@]}" |
71+
cut -f3- -d/ |
72+
fzf "${fzf_opts[@]}"
73+
))
74+
75+
if [[ $checkout = 1 ]]; then
76+
git checkout $selected
77+
else
78+
echo "${selected[@]}"
79+
fi

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /