├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── lib └── custom-title.coffee └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.7.0 4 | - Added `devMode` and `safeMode` booleans. 5 | 6 | ## 0.6.3 7 | - Fixed an error when renaming files. 8 | 9 | ## 0.5.0 10 | 11 | - Added `relativeFilePath` 12 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Dominic Adelaar 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # custom-title package 2 | 3 | Set your own template for Atom's title bar. Uses [underscore.js templates](http://underscorejs.org/#template). 4 | 5 | The following variables are available: 6 | 7 | - `projectPath` 8 | - `projectName` 9 | - `filePath` 10 | - `fileInProject` 11 | - `relativeFilePath` 12 | - `fileName` 13 | - `gitHead` 14 | - `gitAdded` 15 | - `gitDeleted` 16 | - `devMode` 17 | - `safeMode` (always false, since the package will not be loaded in safe mode!) 18 | 19 | Plus the `atom` global, as usual. 20 | 21 | Project and git variables always refer to the first path in your project. 22 | 23 | ## Examples 24 | 25 | ### Default 26 | 27 | The default template matches the regular Atom titlebar: 28 | 29 | ``` 30 | <%= fileName %><% if (projectPath) { %> - <%= projectPath %><% } %> 31 | ``` 32 | 33 | ### With Atom version 34 | 35 | ``` 36 | <%= fileName %><% if (projectPath) { %> - <%= projectPath %><% } %> - Atom <%= atom.getVersion() %> 37 | ``` 38 | 39 | ### With the current git branch 40 | 41 | ``` 42 | <%= fileName %><% if (projectPath) { %> - <%= projectPath %><% if (gitHead) { %> [<%= gitHead %>]<% } %><% } %> 43 | ``` 44 | -------------------------------------------------------------------------------- /lib/custom-title.coffee: -------------------------------------------------------------------------------- 1 | _updateWindowTitle = null 2 | 3 | module.exports = 4 | configDefaults: 5 | template: '<%= fileName %><% if (projectPath) { %> - <%= projectPath %><% } %>' 6 | 7 | config: 8 | template: 9 | type: 'string' 10 | default: '<%= fileName %><% if (projectPath) { %> - <%= projectPath %><% } %>' 11 | 12 | subscriptions: null 13 | configSub: null 14 | 15 | activate: (state) -> 16 | _ = require 'underscore' 17 | { allowUnsafeNewFunction } = require 'loophole' 18 | path = require 'path' 19 | {CompositeDisposable} = require 'event-kit' 20 | 21 | @subscriptions = new CompositeDisposable 22 | 23 | template = null 24 | 25 | @configSub = atom.config.observe 'custom-title.template', -> 26 | templateString = atom.config.get('custom-title.template') 27 | 28 | if templateString 29 | try 30 | template = allowUnsafeNewFunction -> _.template templateString 31 | catch e 32 | template = null 33 | else 34 | template = null 35 | 36 | atom.workspace.updateWindowTitle() 37 | 38 | _updateWindowTitle = atom.workspace.updateWindowTitle 39 | 40 | atom.workspace.updateWindowTitle = -> 41 | if template 42 | projectPath = atom.project.getPaths()[0] 43 | projectName = if projectPath then path.basename(projectPath) else null 44 | 45 | item = atom.workspace.getActivePaneItem() 46 | 47 | fileName = item?.getTitle?() ? 'untitled' 48 | filePath = item?.getPath?() 49 | fileInProject = false 50 | 51 | repo = atom.project.getRepositories()[0] 52 | gitHead = repo?.getShortHead() 53 | 54 | gitAdded = null 55 | gitDeleted = null 56 | relativeFilePath = null 57 | 58 | devMode = atom.inDevMode() 59 | safeMode = atom.inSafeMode?() 60 | 61 | if filePath and repo 62 | status = repo.getCachedPathStatus(filePath) 63 | if repo.isStatusModified(status) 64 | stats = repo.getDiffStats(filePath) 65 | gitAdded = stats.added 66 | gitDeleted = stats.deleted 67 | else if repo.isStatusNew(status) 68 | gitAdded = item.getBuffer?().getLineCount() 69 | gitDeleted = 0 70 | else 71 | gitAdded = gitDeleted = 0 72 | 73 | if filePath and projectPath 74 | relativeFilePath = path.relative(projectPath, filePath) 75 | if filePath.startsWith(projectPath) 76 | fileInProject = true 77 | 78 | try 79 | 80 | title = template { 81 | projectPath, projectName, fileInProject, 82 | filePath, relativeFilePath, fileName, 83 | gitHead, gitAdded, gitDeleted 84 | devMode, safeMode 85 | } 86 | 87 | if filePath or projectPath 88 | atom.setRepresentedFilename(filePath ? projectPath) 89 | document.title = title 90 | catch e 91 | _updateWindowTitle.call(this) 92 | else 93 | _updateWindowTitle.call(this) 94 | 95 | atom.workspace.updateWindowTitle() 96 | 97 | @subscriptions.add atom.workspace.observeTextEditors (editor) => 98 | editorSubscriptions = new CompositeDisposable 99 | editorSubscriptions.add editor.onDidSave -> atom.workspace.updateWindowTitle() 100 | editorSubscriptions.add editor.onDidDestroy -> editorSubscriptions.dispose() 101 | 102 | @subscriptions.add editorSubscriptions 103 | 104 | 105 | deactivate: -> 106 | @subscriptions?.dispose() 107 | @configSub?.dispose() 108 | atom.workspace.updateWindowTitle = _updateWindowTitle 109 | 110 | serialize: -> 111 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-title", 3 | "main": "./lib/custom-title", 4 | "version": "1.0.1", 5 | "description": "Set your own template for Atom's title bar.", 6 | "repository": "https://github.com/postcasio/custom-title", 7 | "license": "MIT", 8 | "engines": { 9 | "atom": ">0.136.0" 10 | }, 11 | "dependencies": { 12 | "event-kit": "^0.7.2", 13 | "loophole": "^1.0.0", 14 | "underscore": "^1.6.0" 15 | } 16 | } 17 | --------------------------------------------------------------------------------