@@ -182,13 +182,21 @@ githook_download_file() {
182182
183183githook_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
440453case " ${0##*/ } " in
441- githook.sh|githook) githook_main " $@ " ;;
454+ githook.sh|githook|sh|bash|dash|ash|zsh|ksh ) githook_main " $@ " ;;
442455esac
0 commit comments