{"version":3,"sources":["../../src/shell.ts","../../src/normalize.ts"],"sourcesContent":["import type { DetectOptions, DetectionResult, ExecFileSync } from './types';\nimport { execFileSync as nodeExecFileSync } from 'node:child_process';\nimport { normalizeIdentifier } from './normalize';\n\nconst runShellTerm = (run: ExecFileSync): string => {\n  return run('sh', ['-c', 'printf %s \"$TERM\"'], {\n    encoding: 'utf8',\n    timeout: 1000,\n    stdio: ['ignore', 'pipe', 'ignore']\n  }) as string;\n};\n\nexport const detectFromShellResult = (\n  options: DetectOptions = {}\n): DetectionResult | null => {\n  const env = options.env ?? process.env;\n  const platform = options.platform ?? process.platform;\n\n  try {\n    if (platform === 'win32') {\n      if (env.WT_SESSION) {\n        return {\n          terminal: 'windows_terminal',\n          source: 'shell'\n        };\n      }\n\n      const shell = env.COMSPEC?.toLowerCase() || '';\n      if (/powershell/i.test(shell)) {\n        return {\n          terminal: 'powershell',\n          source: 'shell'\n        };\n      }\n\n      if (/pwsh/i.test(shell)) {\n        return {\n          terminal: 'powershell',\n          source: 'shell'\n        };\n      }\n\n      if (/cmd\\.exe/i.test(shell)) {\n        return {\n          terminal: 'cmd',\n          source: 'shell'\n        };\n      }\n\n      if (/wt\\.exe/i.test(shell)) {\n        return {\n          terminal: 'windows_terminal',\n          source: 'shell'\n        };\n      }\n\n      if (/conhost\\.exe/i.test(shell)) {\n        return {\n          terminal: 'conhost',\n          source: 'shell'\n        };\n      }\n\n      return {\n        terminal: 'windows_cmd',\n        source: 'shell'\n      };\n    }\n\n    const run = options.execFileSync ?? nodeExecFileSync;\n    const terminal = normalizeIdentifier(runShellTerm(run));\n\n    if (!terminal) {\n      return null;\n    }\n\n    if (!options.preferOuter) {\n      if (terminal.startsWith('tmux')) {\n        return {\n          terminal: 'tmux',\n          source: 'shell'\n        };\n      }\n\n      if (terminal.startsWith('screen')) {\n        return {\n          terminal: 'screen',\n          source: 'shell'\n        };\n      }\n    }\n\n    return {\n      terminal,\n      source: 'shell'\n    };\n  } catch {\n    return null;\n  }\n};\n\nexport const detectFromShell = (options: DetectOptions = {}): string | null => {\n  return detectFromShellResult(options)?.terminal ?? null;\n};\n","import type { DetectOptions } from './types';\nimport path from 'node:path';\n\nexport const AMBIGUOUS_ENV_TERMINALS = new Set([\n  'linux_console',\n  'truecolor_terminal',\n  'vt100',\n  'xterm',\n  'xterm_256color',\n  'xterm_truecolor'\n]);\n\nexport const SHELL_PROCESS_NAMES = new Set([\n  'bash',\n  'csh',\n  'dash',\n  'fish',\n  'ksh',\n  'login',\n  'node',\n  'nodejs',\n  'nu',\n  'sh',\n  'sudo',\n  'tcsh',\n  'zsh'\n]);\n\nexport const normalizeIdentifier = (value: string): string => {\n  return value\n    .trim()\n    .toLowerCase()\n    .replace(/[^a-z0-9]+/g, '_');\n};\n\nexport const normalizeAppName = (value: string, platform: NodeJS.Platform): string => {\n  const appName = platform === 'darwin' ? path.parse(value).name : value;\n  return normalizeIdentifier(appName);\n};\n\nexport const isAmbiguousEnvResult = (\n  terminal: string | null,\n  options: DetectOptions = {}\n): boolean => {\n  if (!terminal) {\n    return true;\n  }\n\n  if (options.preferOuter && (terminal === 'tmux' || terminal === 'screen')) {\n    return true;\n  }\n\n  return AMBIGUOUS_ENV_TERMINALS.has(terminal);\n};\n\nexport const hasKonsoleEnvironment = (env: NodeJS.ProcessEnv): boolean => {\n  return Object.keys(env).some(envVar => /konsole/i.test(envVar));\n};\n\nexport const normalizeParentProcessName = (processName: string): string | null => {\n  const normalized = normalizeIdentifier(path.parse(processName).name);\n\n  switch (normalized) {\n    case 'alacritty':\n    case 'aterm':\n    case 'atomic_terminal':\n    case 'eterm':\n    case 'foot':\n    case 'ghostty':\n    case 'hyper':\n    case 'kitty':\n    case 'konsole':\n    case 'kuake':\n    case 'mate_terminal':\n    case 'mrxvt':\n    case 'powershell':\n    case 'putty':\n    case 'qterminal':\n    case 'rio':\n    case 'rxvt':\n    case 'terminator':\n    case 'terminology':\n    case 'tilda':\n    case 'tmux':\n    case 'warp':\n    case 'wezterm':\n    case 'wterm':\n      return normalized;\n    case 'apple_terminal':\n    case 'terminal':\n      return 'terminal';\n    case 'cmd':\n      return 'cmd';\n    case 'code':\n    case 'code_insiders':\n      return 'vscode';\n    case 'conhost':\n      return 'conhost';\n    case 'gnome':\n    case 'gnome_terminal':\n    case 'gnome_terminal_server':\n    case 'guake':\n      return 'gnome_terminal';\n    case 'iterm':\n    case 'iterm2':\n      return 'iterm';\n    case 'login':\n    case 'linux':\n      return 'linux_console';\n    case 'pwsh':\n      return 'powershell';\n    case 'screen':\n      return 'screen';\n    case 'terminal_app':\n      return 'terminal_app';\n    case 'urxvt':\n    case 'urxvt256c':\n    case 'urxvt256c_ml':\n    case 'urxvt_ml':\n      return 'rxvt';\n    case 'wt':\n    case 'windows_terminal':\n      return 'windows_terminal';\n    case 'xfce':\n    case 'xfce_terminal':\n    case 'xfce4_terminal':\n      return 'xfce4_terminal';\n    default: {\n      if (normalized.startsWith('gnome_terminal')) {\n        return 'gnome_terminal';\n      }\n\n      if (normalized.startsWith('warp')) {\n        return 'warp';\n      }\n\n      return null;\n    }\n  }\n};\n"],"mappings":";;;;AACA,SAAS,gBAAgB,wBAAwB;;;ACAjD,OAAO,UAAU;AA2BV,IAAM,sBAAsB,wBAAC,UAA0B;AAC5D,SAAO,MACJ,KAAK,EACL,YAAY,EACZ,QAAQ,eAAe,GAAG;AAC/B,GALmC;;;ADxBnC,IAAM,eAAe,wBAAC,QAA8B;AAClD,SAAO,IAAI,MAAM,CAAC,MAAM,mBAAmB,GAAG;AAAA,IAC5C,UAAU;AAAA,IACV,SAAS;AAAA,IACT,OAAO,CAAC,UAAU,QAAQ,QAAQ;AAAA,EACpC,CAAC;AACH,GANqB;AAQd,IAAM,wBAAwB,wBACnC,UAAyB,CAAC,MACC;AAC3B,QAAM,MAAM,QAAQ,OAAO,QAAQ;AACnC,QAAM,WAAW,QAAQ,YAAY,QAAQ;AAE7C,MAAI;AACF,QAAI,aAAa,SAAS;AACxB,UAAI,IAAI,YAAY;AAClB,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