Added
Link Here
|
1 |
--- src/Widgets/TerminalWidget.vala.orig 2021-12-13 18:31:36 UTC |
2 |
+++ src/Widgets/TerminalWidget.vala |
3 |
@@ -68,13 +68,6 @@ namespace Terminal { |
4 |
} |
5 |
|
6 |
public int default_size; |
7 |
- const string SEND_PROCESS_FINISHED_BASH = "dbus-send --type=method_call " + |
8 |
- "--session --dest=io.elementary.terminal " + |
9 |
- "/io/elementary/terminal " + |
10 |
- "io.elementary.terminal.ProcessFinished " + |
11 |
- "string:$PANTHEON_TERMINAL_ID " + |
12 |
- "string:\"$(history 1 | cut -c 8-)\" " + |
13 |
- "int32:\$__bp_last_ret_value >/dev/null 2>&1"; |
14 |
|
15 |
/* Following strings are used to build RegEx for matching URIs */ |
16 |
const string USERCHARS = "-[:alnum:]"; |
17 |
@@ -364,14 +357,7 @@ namespace Terminal { |
18 |
|
19 |
envv = { |
20 |
// Export ID so we can identify the terminal for which the process completion is reported |
21 |
- "PANTHEON_TERMINAL_ID=" + terminal_id, |
22 |
- |
23 |
- // Export callback command a BASH-specific variable, see "man bash" for details |
24 |
- "PROMPT_COMMAND=" + SEND_PROCESS_FINISHED_BASH + Environment.get_variable ("PROMPT_COMMAND"), |
25 |
- |
26 |
- // ZSH callback command will be read from ZSH config file supplied by us, see data/ |
27 |
- |
28 |
- // TODO: support FISH, see https://github.com/fish-shell/fish-shell/issues/1382 |
29 |
+ "PANTHEON_TERMINAL_ID=" + terminal_id |
30 |
}; |
31 |
|
32 |
/* We need opening uri to be available asap when constructing window with working directory |
33 |
@@ -454,12 +440,49 @@ namespace Terminal { |
34 |
return this.match_check_event (event, null); |
35 |
} |
36 |
|
37 |
+ private string? extract_cwd (string data) { |
38 |
+ string[] tokens; |
39 |
+ string result = null; |
40 |
+ |
41 |
+ tokens = data.split (" "); |
42 |
+ if (tokens.length > 0) { |
43 |
+ result = tokens[(tokens.length - 1)]; |
44 |
+ } |
45 |
+ return result; |
46 |
+ } |
47 |
+ |
48 |
public string get_shell_location () { |
49 |
+ string[] spawn_env = GLib.Environ.get (); |
50 |
+ string[] procstat_cmd = {"/usr/bin/pwdx", "--libxo:T",}; |
51 |
+ string standard_output = null; |
52 |
+ bool res; |
53 |
+ string cwd = null; |
54 |
+ |
55 |
int pid = (!) (this.child_pid); |
56 |
|
57 |
+ /* Update procstat(1) argument */ |
58 |
+ procstat_cmd += pid.to_string (); |
59 |
+ |
60 |
try { |
61 |
- return GLib.FileUtils.read_link ("/proc/%d/cwd".printf (pid)); |
62 |
- } catch (GLib.FileError error) { |
63 |
+ res = GLib.Process.spawn_sync (null, procstat_cmd, |
64 |
+ spawn_env, |
65 |
+ GLib.SpawnFlags.STDERR_TO_DEV_NULL, |
66 |
+ null, |
67 |
+ out standard_output, |
68 |
+ null, null); |
69 |
+ if (res) { |
70 |
+ cwd = extract_cwd (standard_output.strip ()); |
71 |
+ if (cwd != null) { |
72 |
+ return cwd; |
73 |
+ } |
74 |
+ else { |
75 |
+ return GLib.Environment.get_current_dir (); |
76 |
+ } |
77 |
+ } |
78 |
+ else { |
79 |
+ return GLib.Environment.get_current_dir (); |
80 |
+ } |
81 |
+ } catch (GLib.SpawnError error) { |
82 |
/* Tab name disambiguation may call this before shell location available. */ |
83 |
/* No terminal warning needed */ |
84 |
return ""; |