Created
March 13, 2018 15:44
-
-
Save lepinekong/5c7e1473d18d382f9c1f87a1100e6dff to your computer and use it in GitHub Desktop.
.system.override.red
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Title: ".system.override.red" | |
] | |
if not value? 'syscd [ | |
syscd: :cd | |
cd: func [ | |
"Change directory (shell shortcut function)." | |
[catch] | |
'path [file! word! path! unset! string! paren! url!] "Accepts %file, :variables and just words (as dirs)" | |
][ | |
dir-not-found: function [path searchString][ | |
print rejoin ["Path" { "} searchString {" } "not found, searching partial name..."] | |
files: read path | |
dirs-found: copy [] | |
all-dirs: copy [] | |
foreach file files [ | |
if dir? file [ | |
if find (to-string file) searchString [ | |
print rejoin [searchString " found in " file] | |
append dirs-found file | |
] | |
append all-dirs file | |
] | |
] | |
either (length? dirs-found) > 0 [ | |
probe dirs-found | |
n: to-integer ask "Which one do you choose? 0 for none, else to exit: " | |
either (n > 0) [ | |
chosen-dir: dirs-found/:n | |
cd (chosen-dir) | |
][ | |
either (n = 0) [ | |
foreach file all-dirs [ | |
dir-not-found file searchString | |
] | |
][ | |
exit | |
] | |
] | |
][ | |
] | |
] | |
if paren? get/any 'path [set/any 'path do path] | |
switch/default type?/word get/any 'path [ | |
unset! [print what-dir] | |
string! file! url! [ | |
;path: to-string path | |
searchString: (to-string path) | |
path: to-file searchString | |
if error? try [ change-dir to-file path][ | |
dir-not-found %. searchString | |
] | |
] | |
word! path! [ | |
change-dir path | |
if exists? %autoload.red [ | |
do %autoload.red | |
;print "autoload.red executed" | |
] | |
if exists? %.red [ | |
do %.red | |
;print ".red executed" | |
] | |
] | |
] [ | |
throw-error 'script 'expect-arg reduce ['cd 'path type? get/any 'path] | |
] | |
what-dir | |
] | |
] | |
if not value? 'sysprint [ | |
sysprint: :print | |
print: function[arg1 /sentence /mute][ | |
either sentence [ | |
either block? arg1 [ | |
cum: [] | |
foreach element arg1 [ | |
append cum element | |
append cum " " | |
] | |
the-sentence: rejoin cum | |
][ | |
the-sentence: arg1 | |
] | |
][ | |
the-sentence: arg1 | |
] | |
either not (value? in system/words '__MUTE__) [ | |
__MUTE__: false | |
][ | |
__MUTE__: system/words/__MUTE__ | |
] | |
either not (mute OR __MUTE__) [ | |
sysprint the-sentence | |
][] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment