Skip to content

Instantly share code, notes, and snippets.

@mahmoudimus
Created January 19, 2023 03:10
Show Gist options
  • Select an option

  • Save mahmoudimus/010720c19a92b578c1b0d5ec1baedcd1 to your computer and use it in GitHub Desktop.

Select an option

Save mahmoudimus/010720c19a92b578c1b0d5ec1baedcd1 to your computer and use it in GitHub Desktop.
πŸ“ƒ (autohotkey) - create a list of .ahk files to be #included in your main script
/*
[search folders]
folder_1 =
folder_2 =
[ignore paths]
C:\Users\documents\scripts\example script name.ahk
C:\Users\documents\scripts\example folder name
[settings]
disable_warning = true
execute_names = \auto-executes\,\auto executes\
function_names = \functions\,\lib\
save_folder =
[stats]
script count =
list time =
*/
auto_include() {
start_time := a_tickCount
iniRead, disable_warning, % a_lineFile, settings, disable_warning
i := (disable_warning = "true") ? ("*i ") : ("")
iniRead, ignore_list, % a_lineFile, ignore paths
iniRead, execute_names, % a_lineFile, settings, execute_names
iniRead, function_names, % a_lineFile, settings, function_names
iniRead, save_folder, % a_lineFile, settings, save_folder
loop,
{
iniRead, search_folder, % a_lineFile, search folders, folder_%a_index%
if (search_folder = "")
continue
loop, files, % rTrim(search_folder, "\") . "\*.ahk", FR
{
if inStr(ignore_list . "`n", a_loopFileDir . "`n")
ignore_folder := a_loopFileDir
if a_loopFileDir contains %ignore_folder%
continue ; ignore certain folders
else if inStr(ignore_list, a_loopFileFullPath)
continue ; ignore certain files
script_count++
new_line := (a_loopFileDir = last_dir) ? "" : "`n"
last_dir := a_loopFileDir ; (add an extra line between folders)
if a_loopFileFullPath contains %execute_names%
executes .= new_line . "#include, " . i . a_loopFileFullPath . "`n"
else scripts .= new_line . "#include, " . i . a_loopFileFullPath . "`n"
if a_loopFileFullPath contains %function_names%
functions .= new_line . "#include, " . i . a_loopFileFullPath . "`n"
}
}
until (search_folder = "ERROR") ; loop end
if (save_folder = "")
save_folder := a_scriptDir "\include lists"
update_include_list(executes, save_folder "\~executes.ahk")
update_include_list(scripts, save_folder "\~scripts.ahk")
if (function_names)
update_include_list(functions, save_folder "\~functions.ahk")
; iniWrite, % " " script_count, % a_lineFile, stats, script count
; iniWrite, % " " (a_tickCount - start_time) " ms", % a_lineFile, stats, list time
}
update_include_list(new_text, list_file) {
file := fileOpen(list_file, "r `n")
current_text := file.read()
top_text := " `; ! auto-generated file. any changes made here will be overwritten`n"
new_text := strReplace(top_text . new_text, a_scriptDir, "%a_scriptDir%")
if (current_text != new_text)
{
if !fileExist(list_file)
{
splitPath, list_file, , file_dir
fileCreateDir, % file_dir
}
file := fileOpen(list_file, "w `n")
file.write(new_text)
}
file.close()
}
/*
[script info]
version = 1.10
description = create a list of .ahk files to be #included in your main script
author = davebrny
source = https://gist.github.com/davebrny/55de3ab40499e33e40324ac6a96b70c0
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment