-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathffpl.mjs
executable file
·51 lines (41 loc) · 1.41 KB
/
ffpl.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
import inquirer from 'inquirer';
import fuzzy from 'fuzzy';
import autocompletePrompt from 'inquirer-autocomplete-prompt';
import os from 'os';
import { spawn } from 'child_process';
import getFirefoxProfiles from './modules/firefox-profiles.mjs';
import { getFirefoxCommand } from './modules/firefox-command.mjs';
inquirer.registerPrompt( 'autocomplete', autocompletePrompt );
const main = async () => {
// Detect the operating system
const platform = os.platform();
// Get the profiles based on the detected operating system
const profiles = getFirefoxProfiles(platform);
// Extract profile names
const profileNames = profiles.map((profile) => profile.Name).sort();
// Let the profiles be fuzzy searched
const searchProfiles = async (input, profileNames) => {
input = input || '';
return fuzzy.filter(input, profileNames).map(el => el.string);
};
// get the profile from user input
const { selectedProfile } = await inquirer.prompt([
{
type: 'autocomplete',
name: 'selectedProfile',
message: 'Select a Firefox Profile to Launch:',
source: async (answersSoFar, input) => searchProfiles(input, profileNames),
loop: false
},
]);
const command = getFirefoxCommand();
const args = ['-P', selectedProfile];
const options = {
detached: true,
stdio: 'ignore',
};
const child = spawn(command, args, options);
child.unref();
};
main();