Last active
September 24, 2017 01:12
-
-
Save btzr-io/9175cda2940bd6ee6e91555d0b8cea4b to your computer and use it in GitHub Desktop.
Electron -> shell -> showItemInFolder ( linux )
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
// 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