diff --git a/docs/source/user/files.rst b/docs/source/user/files.rst index 1eeff41421b5..dfbf6b02e5d2 100644 --- a/docs/source/user/files.rst +++ b/docs/source/user/files.rst @@ -88,6 +88,12 @@ directory open. :align: center :class: jp-screenshot +.. _file-copy-path: + +Right-click on a file or directory and select "Copy Path" to copy the +filesystem relative path. This can be used for passing arguments to open +files in functions called in various kernels. + Creating Files and Activities ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index 9e0ca999266e..7b60a212d14a 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -93,6 +93,10 @@ namespace CommandIDs { export const share = 'filebrowser:share-main'; + // For main browser only. + export + const copyPath = 'filebrowser:copy-path'; + // For main browser only. export const showBrowser = 'filebrowser:activate-main'; @@ -405,6 +409,20 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker, bro label: 'Copy Shareable Link' }); + commands.addCommand(CommandIDs.copyPath, { + execute: () => { + const item = browser.selectedItems().next(); + if (!item) { + return; + } + + Clipboard.copyToSystem(item.path); + }, + isVisible: () => toArray(browser.selectedItems()).length === 1, + iconClass: 'jp-MaterialIcon jp-FileIcon', + label: 'Copy Path' + }); + commands.addCommand(CommandIDs.showBrowser, { execute: () => { app.shell.activateById(browser.id); } }); @@ -490,6 +508,7 @@ function createContextMenu(model: Contents.IModel | undefined, commands: Command } menu.addItem({ command: CommandIDs.share }); + menu.addItem({ command: CommandIDs.copyPath }); return menu; }