forked from johannesjo/linux-window-session-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.js
executable file
·116 lines (100 loc) · 3.18 KB
/
cmd.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
'use strict';
const base = require('./dist/index');
const omelette = require('omelette');
const createWhatTodoTxt = (win) => ``;
// There should be no output to stdin until completion.init()
const sessionList = Object.keys(base.getSessions());
let completion = omelette('lwsm');
completion.tree({
save: sessionList,
restore: sessionList
});
completion.init();
if (~process.argv.indexOf('--setupCompletion')) {
completion.setupShellInitFile()
}
function catchInputHandlerErr(err) {
console.error('Input Handler Error: ', err, err.stack);
}
const savePrompts = {
desktopFilePath: (error, win, stdout) => {
return new Promise((fulfill, reject) => {
function askForVal(displayEntries) {
// autosave first entry for now
if (displayEntries && displayEntries[0]) {
// take appimagekit links into account
if (displayEntries[0].match(/appimagekit/) && displayEntries[1]) {
fulfill(displayEntries[1]);
} else {
fulfill(displayEntries[0]);
}
} else {
reject('No input for desktop file path for window "' + win.wmClassName + '". Please fix this manually in config file for this session in ~/.lwsm/{currentSessionName}.json\n' + createWhatTodoTxt(win));
}
}
if (error) {
if (stdout && stdout.split) {
askForVal(stdout.split('\n'));
} else {
askForVal();
}
} else if (stdout && stdout.split) {
const displayEntries = stdout.split('\n');
let displayStr = '';
for (let i = 0; i < displayEntries.length; i++) {
if (displayEntries[i] !== '') {
displayStr += `${i + 1}. ${displayEntries[i]} \n`;
}
}
askForVal(displayEntries);
} else {
askForVal();
}
}).catch(catchInputHandlerErr);
}
};
const isCloseAllWinBefore = process.argv.indexOf('--closeAllOpenWindows') > -1;
const isAllowInputArgs = process.argv.indexOf('--allowInputArgs') > -1;
const action = process.argv[2];
let sessionName;
if (process.argv[3] && !process.argv[3].match(/^--/)) {
sessionName = process.argv[3];
}
function killX11() {
const x = base.getX();
if (x) {
x.terminate();
}
}
if (action === 'save') {
base.saveSession(sessionName, savePrompts).then(killX11);
} else if (action === 'restore') {
base.restoreSession(sessionName, isCloseAllWinBefore, isAllowInputArgs).then(killX11);
} else if (action === 'remove') {
base.removeSession(sessionName).then(killX11);
} else if (action === 'resetCfg') {
base.resetCfg();
} else if (action === 'list') {
base.listSessions();
} else if (action === 'rename' && sessionName && (process.argv[4] && !process.argv[4].match(/^--/))) {
base.renameSession(sessionName, process.argv[4]);
} else {
let version = '';
try {
const p = require('./package.json');
version = p.version;
} catch (e) {
}
console.log(`
Linux Window Session Manager ${version}
Saving your current windows:
lwsm save [OPTIONAL_SESSION_ID]
Restoring a session:
lwsm restore [OPTIONAL_SESSION_ID] [--closeAllOpenWindows]
List all saved sessions:
lwsm list
Renaming a session:
lwsm save [OLD_NAME] [NEW_NAME]
`);
}