Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 0.3.0

* Automatically hide files/directories that are named with relative paths in .hideInTxtEd


## 0.2.0

* fixed files/directories not rehiding after their parent directory is closed and expended
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,17 @@ Easily focus on the task at hand by hiding irrelevantly files and directories.
* Unhide children of a directory
* unhide by right clicking a directory and selecting "Unhide Children"

## Todos
* add ability to save state of hidden files/folders and rehide files/folders when the project is reopened.
* Hide files specified in .hideInTxtEd
```
#this is an example .hideInTxtEd file
#empty lines are ignored

#any matching file/dir path (relative to the current dir) will be hidden:
somedir
foo.txt
bar.txt
otherdir/baz.txt
otherdir/yetanotherdir
#hide this file also
.hideInTxtEd
```
1 change: 1 addition & 0 deletions index.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
HideItems = require "./lib/hide_items.coffee"
require "./lib/hideFilesNamedInTxtFiles.js"

module.exports =
activate: (state) ->
Expand Down
68 changes: 68 additions & 0 deletions lib/hideFilesNamedInTxtFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const hidingFileName = '.hideInTxtEd';

const fs = require('fs');
const path = require('path')
const getDirectories = rootDir => fs.readdirSync(rootDir).map(file => path.join(rootDir,file)).filter(filePath => fs.lstatSync(filePath).isDirectory());
const fileExists = path => fs.existsSync(path) && fs.lstatSync(path).isFile();
const dirExists = path => fs.existsSync(path) && fs.lstatSync(path).isDirectory();

let pathsToHide=[], addedListenerOnPath=[], allProjPaths=[];

function lookForStuffToHide(curPath) {
getDirectories(curPath).forEach(lookForStuffToHide);
const hideListFilePath = path.join(curPath, hidingFileName);
if (fileExists(hideListFilePath)) {
const subFilesToHide = fs.readFileSync(hideListFilePath).toString().split('\n').filter(s => s.length && s[0]!=='#');
subFilesToHide.forEach(file => {
const fullPath = path.join(curPath, file);
pathsToHide.push(fullPath);
});
}
}

function addClasses(treeView) {
const spanA = treeView.element.querySelectorAll('span.icon-file-directory, span.icon-file-text');
for (let i=0;i<spanA.length;++i) {
let span=spanA[i], li=span.parentElement;
while (li.tagName!=='LI') li = li.parentElement;
li.classList.toggle('hide-files-hide', pathsToHide.indexOf(span.getAttribute('data-path'))>-1);
}
}

function addListenerToDirEntry(treeView, entryDir) {
if (entryDir.entries!==undefined) Object.keys(entryDir.entries).forEach(subEntry => {
addListenerToDirEntry(treeView, entryDir.entries[subEntry])
});
if (addedListenerOnPath.indexOf(entryDir.path)===-1 && entryDir.onDidExpand!==undefined) {
addedListenerOnPath.push(entryDir.path);
entryDir.onDidExpand(()=>{
addClasses(treeView);
addListenerToDirEntry(treeView, entryDir);
});
}
}

function scanPaths(paths) {
pathsToHide=[];
addedListenerOnPath=[];
paths.forEach(lookForStuffToHide);
pathsToHide = pathsToHide.filter(itemPath => fs.existsSync(itemPath));
let expandableDirs = pathsToHide.map(curPath => fs.lstatSync(curPath).isFile() ? path.dirname(curPath) : curPath);
expandableDirs = expandableDirs.filter((dir,pos) => expandableDirs.indexOf(dir)===pos);
atom.packages.activatePackage('tree-view').then(result => {
treeView = result.mainModule.treeView
expandableDirs.forEach(dir => addListenerToDirEntry(treeView, treeView.entryForPath(dir).directory));
addClasses(treeView);
});
}

atom.project.onDidChangePaths(newPaths => {
allProjPaths = newPaths;
scanPaths(allProjPaths);
});

atom.project.onDidAddBuffer(buf => {
if (typeof buf.file==='object' && buf.file!==null && typeof buf.file.path==='string' && path.basename(buf.file.path)===hidingFileName && typeof buf.onDidSave==='function') {
buf.onDidSave(() => treeView!==null && scanPaths(allProjPaths));
}
});
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "hide-files",
"main": "index.coffee",
"version": "0.2.0",
"version": "0.3.0",
"description": "Hide files and folders in the file tree",
"repository": "https://github.com/imamathwiz/atom-hide-files",
"license": "MIT",
"author": {
"name": "Brian Weiser",
"url": "https://github.com/imamathwiz"
},
"contributors": {
"name": "ESC",
"url": "https://github.com/softwarecreations"
},
"bugs": {
"url": "https://github.com/imamathwiz/atom-hide-files/issues"
}
Expand Down