Skip to content

Commit 7ad59f6

Browse files
Create tabs cli command
1 parent cb4a2cd commit 7ad59f6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const meow = require('meow')
22

33
const slack = require('./slack')
4+
const tabs = require('./tabs')
45
const { start, succeed, fail } = require('./helpers')
56

67
const at = (input, flags) => slack.status(input[1] || '')
@@ -23,6 +24,13 @@ switch (cli.input[0]) {
2324
.then(status => succeed(`New status: ${status.status_text}`))
2425
.catch(err => fail(err))
2526
break
27+
case 'tabs':
28+
tabs(cli)
29+
.then(({ safari, chrome, total }) => {
30+
succeed(`\n Safari: ${safari.tabs}/${safari.windows}\n Chrome: ${chrome.tabs}/${chrome.windows}\n Total: ${total.tabs}/${total.windows}`)
31+
})
32+
.catch(err => fail(err))
33+
break
2634
default:
2735
cli.showHelp()
2836
break

lib/tabs/index.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const {promisify} = require('util')
2+
const exec = promisify(require('child_process').exec)
3+
4+
module.exports = (cli) => new Promise(async (resolve, reject) => {
5+
const results = {
6+
safari: {
7+
windows: 0,
8+
tabs: 0,
9+
},
10+
chrome: {
11+
windows: 0,
12+
tabs: 0,
13+
},
14+
total: {
15+
windows: 0,
16+
tabs: 0,
17+
},
18+
}
19+
results.safari.windows = parseInt((await exec('osascript -e \'tell application "Safari" to get count of windows\'')).stdout, 10)
20+
results.safari.tabs = parseInt((await exec('osascript -e \'tell application "Safari" to get count of tabs of windows\'')).stdout, 10)
21+
22+
results.chrome.windows = parseInt((await exec('osascript -e \'tell application "Google Chrome" to get count of windows\'')).stdout, 10)
23+
results.chrome.tabs = parseInt((await exec('osascript -e \'tell application "Google Chrome" to get count of tabs of windows\'')).stdout, 10)
24+
25+
results.total.windows = results.safari.windows + results.chrome.windows
26+
results.total.tabs = results.safari.tabs + results.chrome.tabs
27+
28+
resolve(results)
29+
})

0 commit comments

Comments
 (0)