-
Notifications
You must be signed in to change notification settings - Fork 2
/
path_management.m
66 lines (56 loc) · 1.95 KB
/
path_management.m
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
63
64
65
66
%% Copyright 2014 MERCIER David
function path_management(varargin)
%% Set Matlab search path
%
%TODO: checkout addpath_recurse which mtex uses
% http://www.mathworks.com/matlabcentral/fileexchange/21086-recursive-addpath/content/addpath_recurse.m
%
% http://www.mathworks.de/de/help/matlab/ref/addpath.html
commandwindow;
% http://stackoverflow.com/questions/2720140/find-location-of-current-m-file-in-matlab
S = dbstack('-completenames');
[folder, name, ext] = fileparts(S(1).file);
path_to_add = genpath(folder);
% Add path for 'util' folder to use 'cells_filter', 'cell2path' and
% 'path2cell' functions
util_path = fullfile(folder, 'Matlab_Code/util');
addpath(util_path);
path_cell = path2cell(path_to_add);
% Do not put version control metadata on the search path
if ispc
psep = '\';
else
psep = '/';
end
path_cell_filtered = cellstr_filter(path_cell, {[psep, '.git']});
%path_cell_filtered = cellstr_filter(path_cell, {[psep, '.']}); % all dot dirs?
%path_cell_filtered = path_cell; % no filter
n_dirs = numel(path_cell_filtered);
%n_filtered_entries = numel(path_cell) - n_dirs;
path_to_add = cell2path(path_cell_filtered);
fprintf('%s\n', folder)
if nargin > 0 && ischar(varargin{1})
answer = varargin{1};
else
display(['Add the above folder with subfolders ' ...
'to the Matlab search path?'])
fprintf('(%i items)\n', n_dirs)
answer = input('([y](default)/n/rm(remove))','s');
end
root_var = 'POPIN_TBX_ROOT';
if strcmpi(answer, 'y') || isempty(answer)
fprintf('Adding %i entries to the Matlab search path\n', n_dirs);
addpath(path_to_add);
%savepath;
setenv(root_var, folder)
elseif strcmpi(answer, 'rm')
fprintf('Removing %i entries from Matlab search path\n', n_dirs);
rmpath(path_to_add);
% delete environment variable, TODO: works on Linux?
setenv(root_var, '')
else
display('doing nothing');
end
%% Optionally display the matlab search path after modifications with the 'path' command
%path
end