mirror of
https://github.com/purocean/yn.git
synced 2026-10-12 23:31:39 +08:00
修复切换路径问题
This commit is contained in:
@@ -109,9 +109,9 @@ export default {
|
||||
File.openInOS(this.item)
|
||||
},
|
||||
revealInXterminal () {
|
||||
const path = this.currentRepo ? this.currentRepo.path + this.item.path : '~'
|
||||
const path = this.currentRepo ? this.currentRepo.path + this.item.path : ''
|
||||
|
||||
this.$bus.emit('xterm-run', `cd '${path.replace('\'', '\\\'')}'`)
|
||||
this.$bus.emit('xterm-run', `--yank-note-run-command-cd-- ${path}`)
|
||||
},
|
||||
async createFile () {
|
||||
let filename = await this.$modal.input({
|
||||
|
||||
+8
-1
@@ -6,6 +6,7 @@ import * as xStatic from 'koa-static'
|
||||
import * as mime from 'mime'
|
||||
import * as request from 'request'
|
||||
import * as pty from 'node-pty'
|
||||
import * as os from 'os'
|
||||
import { STATIC_DIR, HOME_DIR, HELP_DIR } from './constant'
|
||||
import init from './init'
|
||||
import file from './file'
|
||||
@@ -218,7 +219,13 @@ const server = (port = 3000) => {
|
||||
})
|
||||
ptyProcess.on('data', (data: any) => socket.emit('output', data))
|
||||
ptyProcess.on('exit', () => socket.disconnect())
|
||||
socket.on('input', (data: any) => ptyProcess.write(data))
|
||||
socket.on('input', (data: any) => {
|
||||
if (data.startsWith(shell.CD_COMMAND_PREFIX)) {
|
||||
ptyProcess.write(shell.transformCdCommand(data.toString()))
|
||||
} else {
|
||||
ptyProcess.write(data)
|
||||
}
|
||||
})
|
||||
socket.on('resize', (size: any) => ptyProcess.resize(size[0], size[1]))
|
||||
socket.on('disconnect', () => ptyProcess.kill())
|
||||
})
|
||||
|
||||
+23
-3
@@ -1,14 +1,34 @@
|
||||
import config from './config'
|
||||
import * as os from 'os'
|
||||
import config from './config'
|
||||
import { toWslPath } from './wsl'
|
||||
|
||||
const configKey = 'shell'
|
||||
|
||||
const defaultVal = os.platform() === 'win32' ? 'cmd.exe' : 'bash'
|
||||
const CD_COMMAND_PREFIX = '--yank-note-run-command-cd--'
|
||||
const defaultShell = os.platform() === 'win32' ? 'cmd.exe' : 'bash'
|
||||
|
||||
const getShell = () => {
|
||||
return config.get(configKey, defaultVal)
|
||||
return config.get(configKey, defaultShell).toLowerCase()
|
||||
}
|
||||
|
||||
const transformCdCommand = (command: string) => {
|
||||
const path = command.replace(CD_COMMAND_PREFIX, '').trim()
|
||||
|
||||
if (os.platform() !== 'win32') {
|
||||
return `cd '${path.replace(/\'/g, '\\\'')}'`
|
||||
}
|
||||
|
||||
// 使用 wsl 做 shell,需要先转换路径
|
||||
if (getShell().indexOf('wsl.exe') > -1) {
|
||||
return `cd '${toWslPath(path).replace(/\'/g, '\\\'')}'`
|
||||
}
|
||||
|
||||
// windows 下的切换目录
|
||||
return `cd /d "${path}"`
|
||||
}
|
||||
|
||||
export default {
|
||||
CD_COMMAND_PREFIX,
|
||||
getShell,
|
||||
transformCdCommand,
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,11 +23,11 @@ export const getIsWsl = () => {
|
||||
export const isWsl = getIsWsl()
|
||||
|
||||
export const toWslPath = (path: string) => {
|
||||
return execFileSync('wslpath', ['-u', `${path.replace(/\\/g, '/')}`]).toString().trim()
|
||||
return execFileSync('wsl.exe', ['--', 'wslpath', '-u', `${path.replace(/\\/g, '/')}`]).toString().trim()
|
||||
}
|
||||
|
||||
export const toWinPath = (path: string) => {
|
||||
return execFileSync('wslpath', ['-w', path]).toString().trim()
|
||||
return execFileSync('wsl.exe', ['--', 'wslpath', '-w', path]).toString().trim()
|
||||
}
|
||||
|
||||
export const getWinTempPath = () => {
|
||||
|
||||
Reference in New Issue
Block a user