How to show full path in atom title


#15

It appears you don’t have git installed or not in your path. What happens if you type git on the command line?


#16

Oddly I noticed that the first time, but the second time I got the 1st set of errors. Not sure why it’s showing two sets of errors.

I’m using SourceTree for git with its embedded git, so it’s not in the path. I didn’t know that git was required for plugin packages to work?

(Also, thanks for all the quick responses. Y’all have been very helpful!)


#17

I’m not sure why it was required. I just saw it in the error message.

Try: http://git-scm.com/download/win


#18

Yes I noticed it as well, it’s perfect like this.


#19

Good stuff. Your custom-title package plus <%= filePath %><% if (projectPath) { %> - <%= projectPath %><% } %> worked like a charm @postcasio


#20

Google took me here when I was really looking to customize the tab titles rather than the entire project title. I ended up writing a snippet shows how to customize them.

# place this snippet into init.coffee in ~/.atom directory

atom.workspace.observeTextEditors (editor) ->
    if editor.getTitle() isnt "untitled"
        sp = editor.getPath().split('/')
        title = sp.slice(sp.length-2).join('/') # gives name of containing folder along with filename
        editor.getTitle = -> title
        editor.getLongTitle = -> title

for item in atom.workspace.getPaneItems()
    if item.emitter?
        item.emitter.emit "did-change-title", item.getTitle()

#21

Great solution - love it with ember development where in pods everything is named component.js or template.hbs, but there’s a tiny issue: item.emitted can sometimes be undefined (on settings pane for example).

Fix:

if item.emitter?
    item.emitted.emit "did-change-title", item.getTitle()

#22

Thanks for the catch. I’ll add it in.


#23

I have found this package does not work for me using Atom 1.4.3. The window title just says “untitled” for all windows. Any suggestions?


#24

I have since found that the package IS working (sort of) in Atom 1.4.3. It appears for me to be a title bar refresh issue. I can change tabs containing open files but the title does not update/refresh. If I click to another window I have open, then back to Atom, the refresh is forced and it does indeed show the right filename path. I’ve also seen issues with Atom title bar not refreshing the background navy-blue coloring sometimes. Maybe this is a package incompatibility or a bug in Atom. Any suggestions would be appreciated.


#25

Why are there two threads with almost identical content? Weird.


#26

Here is a clue to this being a refresh issue. Jackomat has a workaround in this thread…


#27

For those who came here from Google and wanted to tweak Atom title -
this is my ~/atom/init.coffee section for changing the title - Is a tweaked version from one of the later comments.

There are 3 variables set you can play with

  title = sp.slice(sp.length-2).join('/') # gives name of containing folder along with filename
  fileName = sp.slice(sp.length-1).join('/') # gives  filename
  titleLong = editor.getPath() # this is the full file pathname

You can use any of them to either the Pane title or the Window Title.

atom.workspace.observeTextEditors (editor) ->
    if editor.getTitle() isnt "untitled"
        sp = editor.getPath().split('/')
        title = sp.slice(sp.length-2).join('/') # gives name of containing folder along with filename
        fileName = sp.slice(sp.length-1).join('/') # gives  filename
        titleLong = editor.getPath() # this is the full file pathname
        editor.getTitle = -> file  # this is the Pane Title
        editor.getLongTitle = -> titleLong # This is Window Title

for item in atom.workspace.getPaneItems()
    if item.emitter?
        item.emitter.emit "did-change-title", item.getTitle()

tested on linux (ubuntu)


#28

Thanks to all who shared their init.coffee. After experimenting a bit I realized I only really needed a tiny token prefix and only on certain types of files. I do not generally need to know the folder context for a CSS file, for example. I’m working on a CakePHP project with lots of same named view files across different controller folders (ala Rails) so I limited the tab prefixing to those view files. All files get folder/file-name on the window though. Anyway, here’s mine in case it’s useful to anyone.

atom.workspace.observeTextEditors (editor) ->
    if editor.getTitle() isnt "untitled"
        splitPath = editor.getPath().split('/')
        splitPathLength = splitPath.length

        fileName = splitPath.slice(splitPathLength-1).join('/')
        containingFolder = splitPath.slice(splitPathLength-2)[0]

        # Shorten folders to keep the tabs from taking over
        # keep the first character in case it's a vowel; 
        # eg. "usrs" makes more sense than "srs"
        firstChar = containingFolder.substring(0,1)
        # no vowel version ("marketplace"->"mrktplc")
        fldrNm = containingFolder.substring(1).replace(/[aeiou]/ig,'')
        # 4 characters is plenty for context ("mrkt/view.ctp")
        fldr = firstChar + fldrNm.substring(0,3)
    
        # Set the window title
        editor.getLongTitle = -> containingFolder + '/' + fileName 

        # Set the pane/tab title
        # Only CTP files need the prefix, otherwise atom's default
        if fileName.indexOf('ctp') > 1
            editor.getTitle = -> fldr + '/' + fileName  

for item in atom.workspace.getPaneItems()
    if item.emitter?
        item.emitter.emit "did-change-title", item.getTitle()



Edited to keep the first character out of the vowel remover.


#29

Anyone got any further with this?
The ideal for me would be full path in window title, then simple filename in the actual tab.
I can’t achieve it:

atom.workspace.observeTextEditors (editor) ->
	if editor.getTitle() isnt "untitled"
		editor.getLongTitle = -> editor.getPath()
		editor.getTitle = -> 'not working?'

for item in atom.workspace.getPaneItems()
	if item.emitter?
		item.emitter.emit "did-change-title", item.getTitle()

Both the window and tab titles get set by getLongTitle and getTitle seemingly does nothing, except possibly for files that are opened after atom itself.

PS: I stripped out all the suggested split and slash replacing stuff, it’s overkill.

(Windows 7, Atom 1.10.0)


#30

You were there! Just comment the line editor.getTitle with a hash # in front :slight_smile:

The getLongTitle is for the main window and getTitle is to set it for the tab!

Enjoy


#31

Oh wow you’re right, thank you.
I had actually tried that but perhaps Atom was a little buggy. My current version 1.10.2 seems fine :slight_smile:


#32

thanks!!! Great package!!!


#33

Thank you for your solution with custom-title plugin.

FYI: I extended your solution. Now my Atom shows the relative path in case it is a project file, and full path if the file is outside the project.

<% if (fileInProject) { %><%= relativeFilePath %> | <%= projectName %><% } else { %><%= filePath %><% } %>

Cheers!


#34

awesome package, simple and does its job! I love it!