\x89PNG\r\n\x1a\n\x00\x00\x00\x0DIHDR\x00\x00\x00\x01\x00 \x00\x00\x01\x08\x06\x00\x00\x00\x1F\x15\xC4\x89\x00\x00\x00 \x0AIDATx\x9Ccb\x00\x00\x00\x06\x00\x03\x1A\x05\x9D\x00\x00 \x00\x00IEND\xAE\x42\x60\x82 csarite.com
KUJUNTI.ID MINISH3LL
Path : /var/www/html/infraai.ai/frontend/node_modules/launch-editor/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/infraai.ai/frontend/node_modules/launch-editor/guess.js


const path = require('path')
const shellQuote = require('shell-quote')
const childProcess = require('child_process')

// Map from full process name to binary that starts the process
// We can't just re-use full process name, because it will spawn a new instance
// of the app every time
const COMMON_EDITORS_MACOS = require('./editor-info/macos')
const COMMON_EDITORS_LINUX = require('./editor-info/linux')
const COMMON_EDITORS_WIN = require('./editor-info/windows')

function getEditorFromMacProcesses(output) {
  const processNames = Object.keys(COMMON_EDITORS_MACOS)
  const processList = output.split('\n')
  for (let i = 0; i < processNames.length; i++) {
    const processName = processNames[i]
    // Find editor by exact match.
    if (processList.includes(processName)) {
      return COMMON_EDITORS_MACOS[processName]
    }
    const processNameWithoutApplications = processName.replace('/Applications', '')
    // Find editor installation not in /Applications.
    if (output.indexOf(processNameWithoutApplications) !== -1) {
      // Use the CLI command if one is specified
      if (processName !== COMMON_EDITORS_MACOS[processName]) {
        return COMMON_EDITORS_MACOS[processName]
      }
      // Use a partial match to find the running process path.  If one is found, use the
      // existing path since it can be running from anywhere.
      const runningProcess = processList.find((procName) =>
        procName.endsWith(processNameWithoutApplications),
      )
      if (runningProcess !== undefined) {
        return runningProcess
      }
    }
  }
  return undefined
}

function getEditorFromWindowsProcesses(output) {
  const runningProcesses = output.split('\r\n')
  for (let i = 0; i < runningProcesses.length; i++) {
    const fullProcessPath = runningProcesses[i].trim()
    const shortProcessName = path.win32.basename(fullProcessPath)

    if (COMMON_EDITORS_WIN.indexOf(shortProcessName) !== -1) {
      return fullProcessPath
    }
  }
  return undefined
}

function getEditorFromLinuxProcesses(output) {
  const processNames = Object.keys(COMMON_EDITORS_LINUX)
  for (let i = 0; i < processNames.length; i++) {
    const processName = processNames[i]
    if (output.indexOf(processName) !== -1) {
      return COMMON_EDITORS_LINUX[processName]
    }
  }
  return undefined
}

function guessEditor(specifiedEditor) {
  if (specifiedEditor) {
    return shellQuote.parse(specifiedEditor)
  }

  if (process.env.LAUNCH_EDITOR) {
    return [process.env.LAUNCH_EDITOR]
  }

  if (process.versions.webcontainer) {
    return [process.env.EDITOR || 'code']
  }

  // We can find out which editor is currently running by:
  // `ps x` on macOS and Linux
  // `Get-Process` on Windows
  try {
    if (process.platform === 'darwin') {
      const output = childProcess
        .execSync('ps x -o comm=', {
          stdio: ['pipe', 'pipe', 'ignore'],
        })
        .toString()
      const editor = getEditorFromMacProcesses(output)
      if (editor !== undefined) {
        return [editor]
      }
    } else if (process.platform === 'win32') {
      const output = childProcess
        .execSync(
          'powershell -NoProfile -Command "' +
            '[Console]::OutputEncoding=[Text.Encoding]::UTF8;' +
            'Get-CimInstance -Query \\"select executablepath from win32_process where executablepath is not null\\" | % { $_.ExecutablePath }' +
            '"',
          {
            stdio: ['pipe', 'pipe', 'ignore'],
          },
        )
        .toString()
      const editor = getEditorFromWindowsProcesses(output)
      if (editor !== undefined) {
        return [editor]
      }
    } else if (process.platform === 'linux') {
      // --no-heading No header line
      // x List all processes owned by you
      // -o comm Need only names column
      const output = childProcess
        .execSync('ps x --no-heading -o comm --sort=comm', {
          stdio: ['pipe', 'pipe', 'ignore'],
        })
        .toString()
      const editor = getEditorFromLinuxProcesses(output)
      if (editor !== undefined) {
        return [editor]
      }
    }
  } catch (ignoreError) {
    // Ignore...
  }

  // Last resort, use old skool env vars
  if (process.env.VISUAL) {
    return [process.env.VISUAL]
  } else if (process.env.EDITOR) {
    return [process.env.EDITOR]
  }

  return [null]
}

module.exports = guessEditor
module.exports.getEditorFromMacProcesses = getEditorFromMacProcesses
module.exports.getEditorFromWindowsProcesses = getEditorFromWindowsProcesses
module.exports.getEditorFromLinuxProcesses = getEditorFromLinuxProcesses

© KUJUNTI.ID