版本
版本 | 最新变动 | |
---|---|---|
Windows | 2018.03.09 | 首发版。 |
macOS | 2022.03.03 | 修复框架命令不支持空格路径的问题。 |
用法
将代码复制并保存为 Do 文件,放置在 Stata 根目录。在 profile.do 文件中(推荐在最后)加入如下命令;若 profile.do 文件不存在,则新建。
// Load Boss Ox's framework for Windows
noisily run bossox_framework_win.do
// Load Boss Ox's framework for macOS
noisily run bossox_framework_mac.do
若不再使用,从 profile.do 中删除上述命令,删除框架 Do 文件,删除 Stata 根目录下 Framework 文件夹即可。
Windows
/*******************************************************************************
Boss Ox's Framework
Boss Ox / 2018.03.09 / Beijing @RUC
Optimized for Windows 10, with StataMP 14.0.
--------------------------------------------------------------------------------
Instruction:
1. Copy BOSSOX_Framework_Windows.do to where Stata.exe locates.
2. Create profile.do at the same place, if not existed.
3. Add script line [noisily run BOSSOX_Framework_Windows.do] anywhere in profile.do.
Notes:
Because the PWD(present working directory) will be changed to QuickStart
folder, if any further directory-related operation is to be performed in
profile.do, it's most convenient putting the scirpt line at the bottom.
If not, where it lies doesn't matter.
Introduction:
Creates folders and files like this on startup:
[Name] [Type] [Description] [Content]
|-BOSSOX_Framework_OS.do Both
|-Framework [Directory]: Framework folder. Auto
|-AutoLog_Log [Directory]: Autolog, logs. Auto
|-AutoLog_CmdLog [Directory]: Autolog, command logs. Auto
|-QuickStart [Directory]: Shortcut-like dofiles. Manual
|-Notes.txt [File] : Notes. Manual
Any operations will be saved into logs and command logs automatically using
unique filenames indicated by launching time. Even sometimes the UI may not
be showing you that any log is active, the record is on from startup.
QuickStart is where you can put shortcut-like dofiles when dealing with
multiple projects. Wwitching folders, initializing macros and any other
preparations you like. Thus simplize the way of multitasking. Typically,
I have several projects exists in different folders, it's hard navigating
to each one of them. So I wright a simple line of dofile, e.g.,
[cd D:\Researches\Project1\] and save it into QuickStart folder. Everything
related of the project, dofiles, datafiles, and others are placed there.
Next time launching Stata, run this shortcut dofile, and it will take you
directly to the right location.
Notes.txt is created automatically. It's just a note, whose content can be
displayed in Stata, and edited with NotePad.exe. I usually use it as TODO
and Memo.
There are several global macros, prefixed with "fw_", make life esaier
even. They are displayed everytime the Framework loads, on startup I mean,
in case you forget. Enter macro name prefixed with "$" to use them.
*******************************************************************************/
// Set Ado folders to relative location.
cd ado
cap cd Plus
if _rc {
mkdir Plus
cd plus
}
cd ..
cap cd Personal
if _rc {
mkdir Personal
cd personal
}
cd ..
cd ..
sysdir set PLUS "`c(sysdir_stata)'\ado\Plus"
sysdir set PERSONAL "`c(sysdir_stata)'\ado\Personal"
// Set Framework folders.
cap cd Framework
if _rc {
mkdir Framework
cd Framework
}
cap cd AutoLog_Log
if _rc {
mkdir AutoLog_Log
cd AutoLog_Log
}
cd ..
cap cd AutoLog_CmdLog
if _rc {
mkdir AutoLog_CmdLog
cd AutoLog_CmdLog
}
cd ..
cap cd QuickStart
if _rc {
mkdir QuickStart
cd QuickStart
}
cd ..
// Set Notes.txt
cap type Notes.txt
if _rc {
// Create Notes.txt by logging.
cmdlog using Notes.txt
cmdlog close
}
else {
// Notes.txt exists, do nothing.
}
// Return to startup location.
cd ..
// Start auto logging.
local time = subinstr("`c(current_time)'", ":", "-", 2)
local date = "`c(current_date)'"
local filename_log = "AutoLog_Log @`date' `time'.Log"
local filename_cmdlog = "AutoLog_CmdLog @`date' `time'.Log"
log using "Framework\AutoLog_Log\\`filename_log'", text replace
cmdlog using "Framework\AutoLog_CmdLog\\`filename_cmdlog'", replace
// Set working environment.
set more off, permanently
// Just for fun.
window manage maintitle "Stata/MP 14.0 @Boss Ox's Framework"
// Define global framework environment variables.
global fw_ev_startup = "`c(sysdir_stata)'"
global fw_ev_version = "2018.03.09"
// Define global framework commands, except fw_help.
global fw_profile = "doe $fw_ev_startup\profile.do"
global fw_config = "doe $fw_ev_startup\BOSSOX_Framework_Windows.do"
global fw_home = "cd $fw_ev_startup\Framework\QuickStart"
global fw_autolog = "dir $fw_ev_startup\Framework\AutoLog_Log\*.Log"
global fw_autocmdlog = "dir $fw_ev_startup\Framework\AutoLog_CmdLog\*.Log"
global fw_clearlog = "shell erase /q $fw_ev_startup\Framework\AutoLog_Log\*.Log"
global fw_clearcmdlog = "shell erase /q $fw_ev_startup\Framework\AutoLog_CmdLog\*.Log"
global fw_note = "type $fw_ev_startup\Framework\Notes.txt"
global fw_editnote = "winexec notepad $fw_ev_startup\Framework\Notes.txt"
global fw_about = `"dis as text _dup(61) "-""' + ///
`" _n(1) as result " Boss Ox"' + "'s Framework" + `"""' + ///
`" _n(1) as text " An auxiliary working environment solution.""' + ///
`" _n(1) as text " Optimized for Windows 10.""' + ///
`" _n(1) " Boss Ox / $fw_ev_version / Beijing @RUC""' + ///
`" _n(1) _dup(61) "-""'
// Define global framework command fw_help.
global fw_help_profile = `"as result " $" "' + `""fw_profile" as text _col(20) ": Edit profile.do.""'
global fw_help_config = `"as result " $" "' + `""fw_config" as text _col(20) ": Edit BOSSOX_Framework_Windows.do.""'
global fw_help_home = `"as result " $" "' + `""fw_home" as text _col(20) ": Return to QuickStart folder.""'
global fw_help_autolog = `"as result " $" "' + `""fw_autolog" as text _col(20) ": List AutoLog_Log in history.""'
global fw_help_autocmdlog = `"as result " $" "' + `""fw_autocmdlog" as text _col(20) ": List AutoLog_CmdLog in history.""'
global fw_help_clearlog = `"as result " $" "' + `""fw_clearlog" as text _col(20) ": Clear AutoLog_Log but current one.""'
global fw_help_clearcmdlog = `"as result " $" "' + `""fw_clearcmdlog" as text _col(20) ": Clear AutoLog_CmdLog but current one.""'
global fw_help_note = `"as result " $" "' + `""fw_note" as text _col(20) ": Show notes.""'
global fw_help_editnote = `"as result " $" "' + `""fw_editnote" as text _col(20) ": Edit notes.""'
global fw_help_help = `"as result " $" "' + `""fw_help" as text _col(20) ": Show global framework commands.""'
global fw_help_about = `"as result " $" "' + `""fw_about" as text _col(20) ": Information about the framework.""'
global fw_help = `"dis _dup(61) as text "-""' + ///
`" _n(1) " Global Framework Commands:""' + ///
`" _n(1) $fw_help_profile"' + ///
`" _n(1) $fw_help_config"' + ///
`" _n(1) $fw_help_home"' + ///
`" _n(1) $fw_help_autolog"' + ///
`" _n(1) $fw_help_autocmdlog"' + ///
`" _n(1) $fw_help_clearlog"' + ///
`" _n(1) $fw_help_clearcmdlog"' + ///
`" _n(1) $fw_help_note"' + ///
`" _n(1) $fw_help_editnote"' + ///
`" _n(1) $fw_help_help"' + ///
`" _n(1) $fw_help_about"' + ///
`" _n(1) _dup(61) "-""'
// Show framework information.
n dis _n(1)
n dis as text _dup(61) "="
n dis as text _dup(19) "/" " Framework designed by " _dup(19) "/"
n dis as text _dup(61) "-"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis _n(0) as text _dup(61) "-"
n dis as text _dup(19) "/" " $fw_ev_version / Beijing " _dup(20) "/"
// Show global framework commands.
n $fw_help
// Show QuickStart dofiles.
n dis as text " Available QuickStarts:"
cd "$fw_ev_startup\Framework\QuickStart"
n dir *.do
// Show notes.
local fw_notes = "$fw_ev_startup\Framework\Notes.txt"
cap type "`fw_notes'"
if _rc {
// Impossible. Do nothing.
}
else {
clear
cap unicode encoding set gb18030
cap unicode erasebackups, badidea
cap unicode translate Notes.txt, transutf8
n dis _n(0) as text _dup(61) "-"
n dis as text " Notes:"
n type "`fw_notes'"
}
n dis _n(0) as text _dup(61) "="
macOS
/*******************************************************************************
Boss Ox's Framework
Boss Ox / 2022.03.03 / Beijing
Optimized for macOS Monterey, with StataMP 15.1.
--------------------------------------------------------------------------------
Setup
1. Copy [BOSSOX_Framework_macOS.do] to where Stata.app locates.
2. Create [profile.do] at the same place, if not existed.
3. Add the script [noisily run BOSSOX_Framework_macOS.do] anywhere in
profile.do, though at the end is where I recommend.
4. Relaunch Stata, and manually disable conflicting modules.
5. Done.
Note:
Initiation process of this framework will set the PWD (aka, Present Working
Directory) to Framework/QuickStart folder. Bear that in mind if any other
directory-related operation is to be performed in [profile.do].
Introduction:
Creates folders and files like this on startup:
[Name] [Type] [Description] [Content]
|-BOSSOX_Framework_OS.do Both
|-Framework [Directory]: Framework folder. Auto
|-AutoLog_Log [Directory]: Autolog, logs. Auto
|-AutoLog_CmdLog [Directory]: Autolog, command logs. Auto
|-QuickStart [Directory]: Shortcut-like dofiles. Manual
|-Notes.txt [File] : Notes. Manual
Any operations will be saved into logs and command logs automatically using
unique filenames indicated by launching time. Even sometimes the UI may not
be showing you that any log is active, the record is on from startup.
QuickStart is where you can put shortcut-like dofiles when dealing with
multiple projects. Wwitching folders, initializing macros and any other
preparations you like. Thus simplize the way of multitasking. Typically,
I have several projects exists in different folders, it's hard navigating
to each one of them. So I wright a simple line of dofile, e.g.,
[cd D:/Researches/Project1/] and save it into QuickStart folder. Everything
related of the project, dofiles, datafiles, and others are placed there.
Next time launching Stata, run this shortcut dofile, and it will take you
directly to the right location.
Notes.txt is created automatically. It's just a note, whose content can be
displayed in Stata, and edited with NotePad.exe. I usually use it as TODO
and Memo.
There are several global macros, prefixed with "fw_", make life esaier
even. They are displayed everytime the Framework loads, on startup I mean,
in case you forget. Enter macro name prefixed with "$" to use them.
*******************************************************************************/
// Notice (sth strange in macOS):
// - Case sensitive in paths, sometimes.
// - Backslash (/) at the end of c(pwd), sometimes.
// - Changing program caption doesn't work here, definitely.
// - Do not use slash (/), use backslash (/) instead, when typing a path.
// - Global macro, when referred in a string, is often parsed into noting.
* MODULE: FRAMEWORK INITIATION
// Environment variable config.
global fw_ev_version = "2022.03.03"
global fw_ev_startup = "`c(sysdir_stata)'"
// Set framework folders.
cap cd Framework
if _rc {
mkdir Framework
cd framework
}
cap cd AutoLog_Log
if _rc {
mkdir AutoLog_Log
cd AutoLog_Log
}
cd ..
cap cd AutoLog_CmdLog
if _rc {
mkdir AutoLog_CmdLog
cd AutoLog_CmdLog
}
cd ..
cap cd QuickStart
if _rc {
mkdir QuickStart
cd QuickStart
}
cd ..
// Set Notes.txt
cap type Notes.txt
if _rc {
// Trick: Use log command to create a text file.
cmdlog using Notes.txt
cmdlog close
}
else {
// Notes.txt exists, do nothing by default.
}
* MODULE: ADO
// Set Ado folder to relative location.
cd "$fw_ev_startup"
cap cd ado
if _rc {
mkdir ado
cd ado
}
cap cd Plus
if _rc {
mkdir Plus
cd Plus
}
cd ..
cap cd Personal
if _rc {
mkdir Personal
cd Personal
}
cd ..
sysdir set PLUS "$fw_ev_startupado/Plus"
sysdir set PERSONAL "$fw_ev_startupado/Personal"
* MODULE: AUTO LOGGING
cd "$fw_ev_startup"
// Start auto logging.
local time = subinstr("`c(current_time)'", ":", "-", 2)
local date = "`c(current_date)'"
local filename_log = "AutoLog_Log @`date' `time'.Log"
local filename_cmdlog = "AutoLog_CmdLog @`date' `time'.Log"
log using "Framework/AutoLog_Log/`filename_log'", text replace
cmdlog using "Framework/AutoLog_CmdLog/`filename_cmdlog'", replace
* MODULE: WORKING PREFERENCE
// Set working environment.
set more off, permanently
* MODULE: JUST FOR FUN
// Doesn't work on macOS.
window manage maintitle "Stata (with Boss Ox's Framework)"
* MODULE: FRAMEWORK FINISHING
// Define global framework commands, except fw_help.
global fw_profile = "doe " + `""$fw_ev_startup"' + `"profile.do""'
global fw_config = "doe " + `""$fw_ev_startup"' + `"BOSSOX_Framework_macOS.do""'
global fw_home = `"cd "$fw_ev_startup"' + `"Framework/QuickStart""'
global fw_autolog = "dir " + `""$fw_ev_startup"' + ///
`"Framework/AutoLog_Log/*.Log""'
global fw_autocmdlog = "dir " + `""$fw_ev_startup"' + ///
`"Framework/AutoLog_CmdLog/*.Log""'
global fw_clearlog = "shell rm " + `""$fw_ev_startup"' + ///
`"Framework/AutoLog_Log/*.Log""'
global fw_clearcmdlog = "shell rm " + `""$fw_ev_startup"' + ///
`"Framework/AutoLog_CmdLog/*.Log""'
global fw_note = "type " + `""$fw_ev_startup"' + `"Framework/Notes.txt""'
global fw_editnote = "shell open " + `""$fw_ev_startup"' + ///
`"Framework/Notes.txt""'
global fw_about = `"dis as text _dup(61) "-""' + ///
`" _n(1) as result " Boss Ox"' + "'s Framework" + `"""' + ///
`" _n(1) as text " An auxiliary working environment solution.""' + ///
`" _n(1) as text " Optimized for macOS Monterey.""' + ///
`" _n(1) " Boss Ox / $fw_ev_version / Beijing""' + ///
`" _n(1) _dup(61) "-""'
// Define global framework command fw_help.
global fw_help_profile = `"as result " $" "' + ///
`""fw_profile" as text _col(20) ": Edit profile.do.""'
global fw_help_config = `"as result " $" "' + ///
`""fw_config" as text _col(20) ": Edit BOSSOX_Framework_macOS.do.""'
global fw_help_home = `"as result " $" "' + ///
`""fw_home" as text _col(20) ": Return to QuickStart folder.""'
global fw_help_autolog = `"as result " $" "' + ///
`""fw_autolog" as text _col(20) ": List AutoLog_Log in history.""'
global fw_help_autocmdlog = `"as result " $" "' + ///
`""fw_autocmdlog" as text _col(20) ": List AutoLog_CmdLog in history.""'
global fw_help_clearlog = `"as result " $" "' + ///
`""fw_clearlog" as text _col(20) ": Clear AutoLog_Log but current one.""'
global fw_help_clearcmdlog = `"as result " $" "' + ///
`""fw_clearcmdlog" as text _col(20) ": "' + ///
`"Clear AutoLog_CmdLog but current one.""'
global fw_help_note = `"as result " $" "' + ///
`""fw_note" as text _col(20) ": Show notes.""'
global fw_help_editnote = `"as result " $" "' + ///
`""fw_editnote" as text _col(20) ": Edit notes.""'
global fw_help_help = `"as result " $" "' + ///
`""fw_help" as text _col(20) ": Show global framework commands.""'
global fw_help_about = `"as result " $" "' + ///
`""fw_about" as text _col(20) ": Information about the framework.""'
global fw_help = `"dis _dup(61) as text "-""' + ///
`" _n(1) " Global Framework Commands:""' + ///
`" _n(1) $fw_help_profile"' + ///
`" _n(1) $fw_help_config"' + ///
`" _n(1) $fw_help_home"' + ///
`" _n(1) $fw_help_autolog"' + ///
`" _n(1) $fw_help_autocmdlog"' + ///
`" _n(1) $fw_help_clearlog"' + ///
`" _n(1) $fw_help_clearcmdlog"' + ///
`" _n(1) $fw_help_note"' + ///
`" _n(1) $fw_help_editnote"' + ///
`" _n(1) $fw_help_help"' + ///
`" _n(1) $fw_help_about"' + ///
`" _n(1) _dup(61) "-""'
// Display welcome information.
n dis _n(1)
n dis as text _dup(61) "="
n dis as text _dup(19) "/" " Framework designed by " _dup(19) "/"
n dis as text _dup(61) "-"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis as result " ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"
n dis _n(0) as text _dup(61) "-"
n dis as text _dup(19) "/" " $fw_ev_version / Beijing " _dup(20) "/"
// Show global framework commands.
n $fw_help
// Show QuickStart dofiles.
n dis as text " Available QuickStarts:"
cd "$fw_ev_startup/Framework/QuickStart"
n dir *.do
// Show notes.
local fw_notes = "$fw_ev_startup" + "Framework/Notes.txt"
cap type "`fw_notes'"
if _rc {
// Impossible. Do nothing.
}
else {
clear
cap unicode encoding set gb18030
cap unicode erasebackups, badidea
cap unicode translate Notes.txt, transutf8
n dis _n(0) as text _dup(61) "-"
n dis as text " Notes:"
n type "`fw_notes'"
}
n dis _n(0) as text _dup(61) "="
变更记录
2022.03.03
- [mac] 修复框架命令不支持空格路径的问题。
- [mac] 窗口标题改得稍微正经了那么一点点(虽然 macOS 上无效)。
- [mac] 重写了一部分指引说明,将代码宽度控制在竖线以左。