Skip to content

Instantly share code, notes, and snippets.

@TiE23
Last active September 3, 2019 23:33
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 TiE23/f9dd60f53a5c448455ece1b98b94e38a to your computer and use it in GitHub Desktop.
Save TiE23/f9dd60f53a5c448455ece1b98b94e38a to your computer and use it in GitHub Desktop.
Atom File Name Tab Disambiguator
// 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());
}
}
});
@TiE23
Copy link
Author

TiE23 commented Sep 3, 2019

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