Skip to content

Instantly share code, notes, and snippets.

@amirhp-com
Forked from piascikj/atom-copy-filename.md
Last active August 15, 2022 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirhp-com/6a6c821397a2f5e4a162553799e0572d to your computer and use it in GitHub Desktop.
Save amirhp-com/6a6c821397a2f5e4a162553799e0572d to your computer and use it in GitHub Desktop.
Atom copy filename

Use CTRL-SHIFT-A to Copy current filename to clipboard or CTRL-SHFIT-X to insert file name at current position.

Add following code on ~/.atom/keymap.cson
'atom-text-editor':
  'ctrl-shift-a': 'amirhp-com:copy-file-name'
  'ctrl-shift-x': 'amirhp-com:insert-file-name'
Add following code on ~/.atom/init.coffee
path = require 'path'
atom.commands.add 'atom-text-editor', 'amirhp-com:copy-file-name', ->
  return unless editor = atom.workspace.getActiveTextEditor()
  selection = editor.getLastSelection()
  filename = atom.workspace.getActivePaneItem().getPath().split(path.sep).pop()
  atom.clipboard.write(filename)
  atom.notifications.addSuccess('Copied "'+filename+'" to Clipboard!', {detail: false, dismissable: false, icon: "check"})

atom.commands.add 'atom-text-editor', 'amirhp-com:insert-file-name', ->
  return unless editor = atom.workspace.getActiveTextEditor()
  selection = editor.getLastSelection()
  filename = atom.workspace.getActivePaneItem().getPath().split(path.sep).pop()
  editor.insertText(filename)
  atom.notifications.addSuccess('Filename "'+filename+'" inserted!', {detail: false, dismissable: false, icon: "check"})

Finnaly, press CTRL-SHIFT-F5 to reload and activate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment