-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup_labkit.m
More file actions
62 lines (52 loc) · 1.6 KB
/
Copy pathstartup_labkit.m
File metadata and controls
62 lines (52 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function startup_labkit(printBanner)
%STARTUP_LABKIT Configure MATLAB path for LabKit workbench apps.
if nargin < 1 || isempty(printBanner)
printBanner = true;
end
printBanner = logical(printBanner);
root = fileparts(mfilename('fullpath'));
addPathIfMissing(root);
addPathIfMissing(fullfile(root, 'apps'), '-end');
appDirs = appPathDirs(fullfile(root, 'apps'));
for k = 1:numel(appDirs)
addPathIfMissing(appDirs{k}, '-end');
end
if printBanner
fprintf('LabKit workbench loaded from:\n %s\n', root);
end
end
function dirs = appPathDirs(appRoot)
dirs = {};
if exist(appRoot, 'dir') ~= 7
return;
end
entries = dir(appRoot);
dirsByEntry = cell(numel(entries), 1);
for k = 1:numel(entries)
entry = entries(k);
if ~entry.isdir || ismember(entry.name, {'.', '..'})
continue;
end
if shouldSkipAppDir(entry.name)
continue;
end
fullpath = fullfile(appRoot, entry.name);
childDirs = appPathDirs(fullpath);
dirsByEntry{k} = [{fullpath}, childDirs];
end
dirs = [dirsByEntry{:}];
end
function tf = shouldSkipAppDir(name)
tf = startsWith(name, '.') || startsWith(name, '+') ...
|| startsWith(name, '@') || any(strcmp(name, {'private', 'scaffold'}));
end
function addPathIfMissing(folder, varargin)
if exist(folder, 'dir') ~= 7 || pathContains(folder)
return;
end
addpath(folder, varargin{:});
end
function tf = pathContains(folder)
paths = strsplit(path, pathsep);
tf = any(strcmp(paths, folder));
end