@@ -10,29 +10,36 @@ trap _term SIGTERM
1010
1111# if there is a binder/ sub-directory it takes precedence
1212# files outside it are ignored
13- if [ -e ./binder ]; then
14- nixpath=" ./binder/default.nix" ;
15- if [ -f ./binder/start ]; then
16- chmod u+x ./binder/start
17- # Using `$@`` here which is what the internet recommends leads to
18- # errors when the command is something like `jupyter --ip=0.0.0.0 ...`
19- # as nix-shell picks that up as an argument to it instead of the command.
20- # There are several issues on the nix repos discussing this and adding support
21- # for -- to indicate "all arguments after this are for the command, not nix-shell"
22- # but it seems they have stalled/not yet produced an implementation.
23- # So let's use `$*` for now.
24- nix-shell $nixpath --command " ./binder/start $* " &
25- else
26- nix-shell $nixpath --command " $* " &
13+ # find binder sub-directory (if present)
14+ binder_dir=" ./"
15+ for dir in " ./binder" " ./.binder" ; do
16+ if [ -e $dir ]; then
17+ binder_dir=$dir
18+ break
2719 fi
20+ done
21+
22+ # raise error if both binder and .binder are found
23+ if [[ -d " ./binder" && -d " ./.binder" ]]; then
24+ echo " Error: Found both binder and .binder directories."
25+ exit 1
26+ fi
27+
28+ echo " binder_dir is: $binder_dir "
29+
30+ nixpath=" $binder_dir /default.nix" ;
31+ if [ -f $binder_dir /start ]; then
32+ chmod u+x $binder_dir /start
33+ # Using `$@`` here which is what the internet recommends leads to
34+ # errors when the command is something like `jupyter --ip=0.0.0.0 ...`
35+ # as nix-shell picks that up as an argument to it instead of the command.
36+ # There are several issues on the nix repos discussing this and adding support
37+ # for -- to indicate "all arguments after this are for the command, not nix-shell"
38+ # but it seems they have stalled/not yet produced an implementation.
39+ # So let's use `$*` for now.
40+ nix-shell $nixpath --command " $binder_dir /start $* " &
2841else
29- nixpath=" ./default.nix" ;
30- if [ -f ./start ]; then
31- chmod u+x ./start
32- nix-shell $nixpath --command " ./start $* " &
33- else
34- nix-shell $nixpath --command " $* " &
35- fi
42+ nix-shell $nixpath --command " $* " &
3643fi
3744
3845PID=$!
0 commit comments