Skip to content

Commit 1434cbe

Browse files
committed
noot
1 parent 1f8d430 commit 1434cbe

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

githook.sh

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,21 @@ githook_download_file() {
182182

183183
githook_cmd_setup() {
184184
_git_root="$(githook_check_git_repository)"
185-
_script_path="$(githook_get_script_path)"
186185
_target_path="$_git_root/githook.sh"
187186

188-
if [ "$_script_path" = "$_target_path" ]; then
189-
githook_info "already in repo root: $_target_path"
190-
chmod +x "$_target_path"
191-
return
187+
# check if running from file or piped
188+
case "${0##*/}" in
189+
sh|bash|dash|ash|zsh|ksh) _piped=1 ;;
190+
*) _piped=0 ;;
191+
esac
192+
193+
if [ "$_piped" -eq 0 ]; then
194+
_script_path="$(githook_get_script_path)"
195+
if [ "$_script_path" = "$_target_path" ]; then
196+
githook_info "already in repo root: $_target_path"
197+
chmod +x "$_target_path"
198+
return
199+
fi
192200
fi
193201

194202
if [ -f "$_target_path" ]; then
@@ -201,10 +209,15 @@ githook_cmd_setup() {
201209
esac
202210
fi
203211

204-
cp "$_script_path" "$_target_path"
212+
if [ "$_piped" -eq 1 ]; then
213+
githook_info "downloading githook.sh..."
214+
githook_download_file "$GITHOOK_API_URL" "$_target_path"
215+
else
216+
cp "$_script_path" "$_target_path"
217+
fi
205218
chmod +x "$_target_path"
206219

207-
githook_info "copied to $_target_path"
220+
githook_info "installed to $_target_path"
208221
echo ""
209222
githook_info "next:"
210223
githook_info " ./githook.sh install"
@@ -436,7 +449,7 @@ githook_main() {
436449
esac
437450
}
438451

439-
# only run if executed directly (not sourced)
452+
# run if executed directly or piped
440453
case "${0##*/}" in
441-
githook.sh|githook) githook_main "$@" ;;
454+
githook.sh|githook|sh|bash|dash|ash|zsh|ksh) githook_main "$@" ;;
442455
esac

src/commands.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
githook_cmd_setup() {
44
_git_root="$(githook_check_git_repository)"
5-
_script_path="$(githook_get_script_path)"
65
_target_path="$_git_root/githook.sh"
76

8-
if [ "$_script_path" = "$_target_path" ]; then
9-
githook_info "already in repo root: $_target_path"
10-
chmod +x "$_target_path"
11-
return
7+
# check if running from file or piped
8+
case "${0##*/}" in
9+
sh|bash|dash|ash|zsh|ksh) _piped=1 ;;
10+
*) _piped=0 ;;
11+
esac
12+
13+
if [ "$_piped" -eq 0 ]; then
14+
_script_path="$(githook_get_script_path)"
15+
if [ "$_script_path" = "$_target_path" ]; then
16+
githook_info "already in repo root: $_target_path"
17+
chmod +x "$_target_path"
18+
return
19+
fi
1220
fi
1321

1422
if [ -f "$_target_path" ]; then
@@ -21,10 +29,15 @@ githook_cmd_setup() {
2129
esac
2230
fi
2331

24-
cp "$_script_path" "$_target_path"
32+
if [ "$_piped" -eq 1 ]; then
33+
githook_info "downloading githook.sh..."
34+
githook_download_file "$GITHOOK_API_URL" "$_target_path"
35+
else
36+
cp "$_script_path" "$_target_path"
37+
fi
2538
chmod +x "$_target_path"
2639

27-
githook_info "copied to $_target_path"
40+
githook_info "installed to $_target_path"
2841
echo ""
2942
githook_info "next:"
3043
githook_info " ./githook.sh install"

src/main.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ githook_main() {
2626
esac
2727
}
2828

29-
# only run if executed directly (not sourced)
29+
# run if executed directly or piped
3030
case "${0##*/}" in
31-
githook.sh|githook) githook_main "$@" ;;
31+
githook.sh|githook|sh|bash|dash|ash|zsh|ksh) githook_main "$@" ;;
3232
esac

0 commit comments

Comments
 (0)