Skip to content

Instantly share code, notes, and snippets.

@btzr-io
Last active September 24, 2017 01:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save btzr-io/9175cda2940bd6ee6e91555d0b8cea4b to your computer and use it in GitHub Desktop.
Electron -> shell -> showItemInFolder ( linux )
// Linux patch for electron: shell.showItemInFolder
const { execFile } = require('child_process');
// Parse application name
//https://gist.github.com/btzr-io/abb2f2995a63c08bbdc655d9849c69ff
const parseName = (name) => name.replace(/\s+/g, '')
.split(".")
.filter( key => key !== "org" && key !== "desktop")
.join("-");
function run(command, args, callback, handleError) {
execFile(command, args, (error, stdout, stderr) => {
(error || stderr) ? handleError(error||stderr) : callback(stdout);
});
}
// Show the given file in a file manager. If possible, select the file.
export default function showItemInFolder(path) {
const args = ['query', 'default', 'inode/directory'];
run('xdg-mime', args, (name) => {
// Get default File-manager application
const fileManager = name ? parseName(name) : null;
// Open file-manager and select file
run(fileManager, [path], () => true, () => false)
// handle errors
}, (error) => console.log(error));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment