Key combination to paste current working files absolute path


#1

I find that I spend a lot of time typing out file paths for documentation in the files themselves.
It would be convenient to have the working file’s path at my fingertips with a key command.

While searching around I found these two discussions about a similar problem, but they neither document a working solution, nor start me on a path to solve it myself.


How do I go about creating a package that does what I need?


#2

If you click on the file path in the status bar, it copies the absolute path to the clipboard.

If you still want a key combination to do the same thing, I’m sure either @olmokramer can help or you could take a look at the documentation on how to write a package here:

https://atom.io/docs/latest/hacking-atom-package-word-count


#3

Would something like autocomplete-paths help? Otherwise you can add to your init.coffee the following. It adds the custom:insert-working-file-path command that inserts the current file’s path at the current cursor position and for which you can set a keybinding. Replace the last uncommented line with the commented line to get the filepath relative to your project’s path (if the file is actually in your project).

atom.commands.add 'atom-text-editor', 'custom:insert-working-file-path', =>
  editor = atom.workspace.getActiveTextEditor()
  editor.insertText editor.getPath()
  # editor.insertText editor.getPath().replace(atom.project.getPaths()[0], '')

#4

@leedohm Thanks, that click-for-path looks useful, I never would have discovered that on my own!

@olmokramer That snippet worked like a charm! I dropped 'alt-v': 'custom:insert-working-file-path' in keymap.cson and now I have what I needed.