tools.which: cleanup code a little.
parent
00584264d5
commit
233e84bdf4
|
@ -9,19 +9,6 @@ IN: tools.which
|
||||||
|
|
||||||
<PRIVATE
|
<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 -- ? )
|
: executable? ( path -- ? )
|
||||||
{
|
{
|
||||||
[ exists? ]
|
[ exists? ]
|
||||||
|
@ -29,6 +16,9 @@ IN: tools.which
|
||||||
[ file-info directory? not ]
|
[ file-info directory? not ]
|
||||||
} 1&& ;
|
} 1&& ;
|
||||||
|
|
||||||
|
: split-path ( paths -- seq )
|
||||||
|
os windows? ";" ":" ? split harvest ;
|
||||||
|
|
||||||
: path-extensions ( command -- commands )
|
: path-extensions ( command -- commands )
|
||||||
"PATHEXT" os-env [
|
"PATHEXT" os-env [
|
||||||
split-path 2dup [ [ >lower ] bi@ tail? ] with any?
|
split-path 2dup [ [ >lower ] bi@ tail? ] with any?
|
||||||
|
@ -41,7 +31,7 @@ IN: tools.which
|
||||||
[ prepend-path ] { } assoc>map
|
[ prepend-path ] { } assoc>map
|
||||||
[ executable? ] find nip ;
|
[ executable? ] find nip ;
|
||||||
|
|
||||||
: (which) ( command paths -- file/f )
|
: (which) ( command path -- file/f )
|
||||||
split-path os windows? [
|
split-path os windows? [
|
||||||
[ path-extensions ] [ "." prefix ] bi*
|
[ path-extensions ] [ "." prefix ] bi*
|
||||||
] [ [ 1array ] dip ] if ((which)) ;
|
] [ [ 1array ] dip ] if ((which)) ;
|
||||||
|
@ -49,4 +39,4 @@ IN: tools.which
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: which ( command -- file/f )
|
: which ( command -- file/f )
|
||||||
current-path (which) ;
|
"PATH" os-env (which) ;
|
||||||
|
|
Loading…
Reference in New Issue