tools.which: cleanup code a little.

db4
John Benediktsson 2013-01-11 11:37:59 -08:00
parent 00584264d5
commit 233e84bdf4
1 changed files with 5 additions and 15 deletions

View File

@ -9,19 +9,6 @@ IN: tools.which
<PRIVATE
: default-path ( -- path )
os {
{ windows [ ".;C:\\bin" ] }
{ macosx [ ":" ] }
{ linux [ ":/bin:/usr/bin" ] }
} case ;
: current-path ( -- path )
"PATH" os-env [ default-path ] unless* ;
: split-path ( path -- seq )
os windows? ";" ":" ? split harvest ;
: executable? ( path -- ? )
{
[ exists? ]
@ -29,6 +16,9 @@ IN: tools.which
[ file-info directory? not ]
} 1&& ;
: split-path ( paths -- seq )
os windows? ";" ":" ? split harvest ;
: path-extensions ( command -- commands )
"PATHEXT" os-env [
split-path 2dup [ [ >lower ] bi@ tail? ] with any?
@ -41,7 +31,7 @@ IN: tools.which
[ prepend-path ] { } assoc>map
[ executable? ] find nip ;
: (which) ( command paths -- file/f )
: (which) ( command path -- file/f )
split-path os windows? [
[ path-extensions ] [ "." prefix ] bi*
] [ [ 1array ] dip ] if ((which)) ;
@ -49,4 +39,4 @@ IN: tools.which
PRIVATE>
: which ( command -- file/f )
current-path (which) ;
"PATH" os-env (which) ;