mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-24 17:16:03 +00:00
added a 'copy current path' hotkey and context menu item - fixes #2586
This commit is contained in:
@@ -363,6 +363,10 @@ export class SSHSession extends BaseSession {
|
|||||||
this.kill('TERM')
|
this.kill('TERM')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
supportsWorkingDirectory (): boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
async getWorkingDirectory (): Promise<string|null> {
|
async getWorkingDirectory (): Promise<string|null> {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ import { TerminalDecorator } from './decorator'
|
|||||||
/** @hidden */
|
/** @hidden */
|
||||||
export interface ToastrServiceProxy {
|
export interface ToastrServiceProxy {
|
||||||
info: (_: string) => void
|
info: (_: string) => void
|
||||||
|
error: (_: string) => void
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* A class to base your custom terminal tabs on
|
* A class to base your custom terminal tabs on
|
||||||
@@ -140,7 +141,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
|
|||||||
this.logger = this.log.create('baseTerminalTab')
|
this.logger = this.log.create('baseTerminalTab')
|
||||||
this.setTitle('Terminal')
|
this.setTitle('Terminal')
|
||||||
|
|
||||||
this.hotkeysSubscription = this.hotkeys.matchedHotkey.subscribe(hotkey => {
|
this.hotkeysSubscription = this.hotkeys.matchedHotkey.subscribe(async hotkey => {
|
||||||
if (!this.hasFocus) {
|
if (!this.hasFocus) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -207,6 +208,9 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
|
|||||||
case 'pane-focus-all':
|
case 'pane-focus-all':
|
||||||
this.focusAllPanes()
|
this.focusAllPanes()
|
||||||
break
|
break
|
||||||
|
case 'copy-current-path':
|
||||||
|
this.copyCurrentPath()
|
||||||
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.bellPlayer = document.createElement('audio')
|
this.bellPlayer = document.createElement('audio')
|
||||||
@@ -438,6 +442,19 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async copyCurrentPath (): Promise<void> {
|
||||||
|
let cwd: string|null = null
|
||||||
|
if (this.session?.supportsWorkingDirectory()) {
|
||||||
|
cwd = await this.session.getWorkingDirectory()
|
||||||
|
}
|
||||||
|
if (cwd) {
|
||||||
|
this.electron.clipboard.writeText(cwd)
|
||||||
|
this.toastr.info('Copied')
|
||||||
|
} else {
|
||||||
|
this.toastr.error('Shell does not support current path detection')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @hidden */
|
/** @hidden */
|
||||||
ngOnDestroy (): void {
|
ngOnDestroy (): void {
|
||||||
this.frontend?.detach(this.content.nativeElement)
|
this.frontend?.detach(this.content.nativeElement)
|
||||||
|
@@ -4,6 +4,7 @@ import { ConfigProvider, Platform } from 'terminus-core'
|
|||||||
export class TerminalConfigProvider extends ConfigProvider {
|
export class TerminalConfigProvider extends ConfigProvider {
|
||||||
defaults = {
|
defaults = {
|
||||||
hotkeys: {
|
hotkeys: {
|
||||||
|
'copy-current-path': [],
|
||||||
shell: {
|
shell: {
|
||||||
__nonStructural: true,
|
__nonStructural: true,
|
||||||
},
|
},
|
||||||
|
@@ -62,6 +62,10 @@ export class TerminalHotkeyProvider extends HotkeyProvider {
|
|||||||
id: 'ctrl-c',
|
id: 'ctrl-c',
|
||||||
name: 'Intelligent Ctrl-C (copy/abort)',
|
name: 'Intelligent Ctrl-C (copy/abort)',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'copy-current-path',
|
||||||
|
name: 'Copy current path',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'search',
|
id: 'search',
|
||||||
name: 'Search',
|
name: 'Search',
|
||||||
|
@@ -87,6 +87,7 @@ export abstract class BaseSession {
|
|||||||
abstract kill (signal?: string): void
|
abstract kill (signal?: string): void
|
||||||
abstract async getChildProcesses (): Promise<ChildProcess[]>
|
abstract async getChildProcesses (): Promise<ChildProcess[]>
|
||||||
abstract async gracefullyKillProcess (): Promise<void>
|
abstract async gracefullyKillProcess (): Promise<void>
|
||||||
|
abstract supportsWorkingDirectory (): boolean
|
||||||
abstract async getWorkingDirectory (): Promise<string|null>
|
abstract async getWorkingDirectory (): Promise<string|null>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,6 +260,16 @@ export class Session extends BaseSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
supportsWorkingDirectory (): boolean {
|
||||||
|
if (this.reportedCWD || this.guessedCWD) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (!this.truePID) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return process.platform !== 'win32'
|
||||||
|
}
|
||||||
|
|
||||||
async getWorkingDirectory (): Promise<string|null> {
|
async getWorkingDirectory (): Promise<string|null> {
|
||||||
if (this.reportedCWD) {
|
if (this.reportedCWD) {
|
||||||
return this.reportedCWD
|
return this.reportedCWD
|
||||||
|
@@ -123,6 +123,13 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tab instanceof TerminalTabComponent && tab.session?.supportsWorkingDirectory()) {
|
||||||
|
items.push({
|
||||||
|
label: 'Copy current path',
|
||||||
|
click: () => this.zone.run(() => tab.copyCurrentPath()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user