Skip to content

Commit a122fd3

Browse files
committed
get_shell: current running shell rather than default shell
1 parent d93b5f8 commit a122fd3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

+stdlib/get_shell.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
%% GET_SHELL shell of the current user
2-
% return value of environment variable SHELL
3-
% this is mostly relevant on unix-like systems
1+
%% GET_SHELL full path to currently running shell
42

53
function s = get_shell()
64

7-
s = getenv("SHELL");
5+
if ispc()
6+
% https://stackoverflow.com/a/61469226
7+
cmd = "(dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition";
8+
else
9+
% https://askubuntu.com/a/1349538
10+
cmd = strcat("lsof -p ", '"$$"', " | grep -m 1 txt | xargs -n 1 | tail -n +9 | tr -d [:space:]");
11+
end
12+
13+
[r, msg] = system(cmd);
14+
15+
if r == 0
16+
s = msg;
17+
else
18+
s = getenv("SHELL");
19+
end
820

921
end
1022

0 commit comments

Comments
 (0)