Last active
September 3, 2019 23:33
-
-
Save TiE23/f9dd60f53a5c448455ece1b98b94e38a to your computer and use it in GitHub Desktop.
Atom File Name Tab Disambiguator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This makes file names in the tabs a little bit easier to read, especially | |
// when you have TONS of identically prefixed and very long named files. | |
// It'll convert a row of tabs that looks like this (USELESS): | |
// [NewsFeedConfigurati…][NewsFeedConfigurati…][NewsFeedConfigurati…] | |
// And make it look a little more like this (BETTER): | |
// [NewsFee…ManagerSpec.js][NewsFee…eView.react.js][NewsFee…ainer.react.js] | |
// And optionally, if TRIM_EXTENSION is set to true, like this (BEST): | |
// [NewsFee…inManagerSpec‗][NewsFee…etailPageView‗][NewsFee…ViewContainer‗] | |
// Just create 'init.js' in your ~/.atom directory. | |
// You'll need to restart Atom to load it, sorry. | |
const TRIM_MAX_LEN = 22; | |
const TRIM_TRAILING = 14; | |
const TRIM_ELLIPSES = "…"; | |
const TRIM_EXTENSION = true; // Trims the extension first if too long. | |
const TRIM_EXTENSION_CHAR = "‗"; // Make a blank string to leave out. | |
atom.workspace.observeTextEditors(editor => { | |
const currentTitle = editor.getTitle(); | |
if (currentTitle !== "untitled" && currentTitle.length > TRIM_MAX_LEN) { | |
const dotIndex = currentTitle.indexOf("."); | |
const workTitle = (TRIM_EXTENSION && dotIndex !== -1) ? | |
currentTitle.slice(0, dotIndex) + TRIM_EXTENSION_CHAR : currentTitle; | |
const trimmedTitle = (workTitle.length > TRIM_MAX_LEN) ? | |
( | |
workTitle.slice(0, TRIM_MAX_LEN - TRIM_TRAILING - TRIM_ELLIPSES.length) + | |
TRIM_ELLIPSES + | |
workTitle.slice(TRIM_TRAILING * -1) | |
) : workTitle; | |
editor.getTitle = () => trimmedTitle; | |
editor.emitter.emit("did-change-title", editor.getTitle()); | |
} | |
}); | |
atom.workspace.onDidOpen(event => { | |
for (item of event.pane.items) { | |
if (item.emitter) { | |
item.emitter.emit("did-change-title", item.getTitle()); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired initially by https://gist.github.com/tribou/53b508b65b390183e4b23678e5b0816f