{"action":"created","comment":{"url":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/comments/41479077","id":41479077,"diff_hunk":"@@ -83,83 +87,65 @@ function setAvailableApps(cb) {\n \t// `which` all commands and expect stdout to return a positive\n \tconst whichCmd = `which -a ${names.join('; which -a ')}`;\n \n-\tchildProcess.exec(whichCmd, (err, stdout) => {\n-\t\tif (!stdout) {\n-\t\t\tthrow new Error('None of the apps were found');\n-\t\t}\n+\treturn exec(whichCmd)\n+\t\t.then(function (stdout) {\n+\t\t\tif (!stdout) {\n+\t\t\t\tthrow new Error('None of the apps were found');\n+\t\t\t}\n \n-\t\t// it may return aliases so we only want the real path\n-\t\t// and only the executable name. i.e. 'foo' from /bin/foo\n-\t\tstdout = stdout.trim().split('\\n');\n+\t\t\t// it may return aliases so we only want the real path\n+\t\t\t// and only the executable name. i.e. 'foo' from /bin/foo\n+\t\t\tstdout = stdout.trim().split('\\n');\n \n-\t\tstdout.forEach(el => {\n-\t\t\t// it's an alias\n-\t\t\tif (el[0] !== path.sep) {\n-\t\t\t\treturn;\n-\t\t\t}\n+\t\t\tstdout.forEach(el => {\n+\t\t\t\t// it's an alias\n+\t\t\t\tif (el[0] !== path.sep) {\n+\t\t\t\t\treturn;\n+\t\t\t\t}\n \n-\t\t\tel = el.split(path.sep).pop();\n+\t\t\t\tel = el.split(path.sep).pop();\n \n-\t\t\tavailableApps.push(availableAppsDict[el]);\n+\t\t\t\tavailableApps.push(availableAppsDict[el]);\n+\t\t\t});\n \t\t});\n-\n-\t\tcb(availableApps);\n-\t});\n }\n \n-exports.get = function get(cb) {\n+exports.get = function get() {\n \tif (!availableApps) {\n-\t\treturn setAvailableApps(() => {\n-\t\t\tget(cb);\n-\t\t});\n+\t\treturn setAvailableApps().then(get);\n \t}\n \n-\tcb = cb || function () {};\n-\n-\tlet found = false;\n-\n-\tavailableApps.forEach(app => {\n-\t\tif (!app.get || found) {\n-\t\t\treturn;\n-\t\t}\n-\n-\t\tchildProcess.execFile(app.cmd, app.get, (err, stdout) => {\n-\t\t\tif (err || !stdout || found) {\n-\t\t\t\treturn;\n-\t\t\t}\n-\n-\t\t\tfound = true;\n+\tconst app = availableApps.find(app => {\n+\t\treturn app.get !== undefined;\n+\t});\n \n+\treturn execFile(app.cmd, app.get)\n+\t\t.then(stdout => {\n \t\t\tif (typeof app.transform === 'function') {\n-\t\t\t\tstdout = app.transform(stdout);\n+\t\t\t\treturn app.transform(stdout);\n \t\t\t}\n \n-\t\t\tcb(null, stdout);\n+\t\t\treturn stdout;\n \t\t});\n-\t});\n };\n \n-exports.set = function set(imagePath, cb) {\n+exports.set = function set(imagePath) {\n \tif (typeof imagePath !== 'string') {\n-\t\tthrow new TypeError('Expected a string');\n+\t\treturn Promise.reject(new TypeError('Expected a string'));\n \t}\n \n \tif (!availableApps) {\n-\t\treturn setAvailableApps(() => set(imagePath, cb));\n+\t\treturn setAvailableApps().then(() => set(imagePath));\n \t}\n \n-\tcb = cb || function () {};\n-\n \timagePath = path.resolve(imagePath);\n \n-\tavailableApps.forEach(app => {\n-\t\tif (!app.set) {\n-\t\t\treturn;\n-\t\t}\n+\tconst app = availableApps.find(app => {\n+\t\treturn app.set !== undefined;\n+\t});\n \n-\t\tconst params = JSON.parse(JSON.stringify(app.set));\n-\t\tparams[params.length - 1] = params[params.length - 1].replace('%s', imagePath);\n+\tconst params = JSON.parse(JSON.stringify(app.set));\n+\tparams[params.length - 1] = params[params.length - 1].replace('%s', imagePath);","path":"lib/linux.js","position":133,"original_position":133,"commit_id":"529683b1b0a9c3f3ec41a61218fa2f2131cc2a17","original_commit_id":"529683b1b0a9c3f3ec41a61218fa2f2131cc2a17","user":{"login":"SamVerschueren","id":1913805,"avatar_url":"https://avatars.githubusercontent.com/u/1913805?v=3","gravatar_id":"","url":"https://api.github.com/users/SamVerschueren","html_url":"https://github.com/SamVerschueren","followers_url":"https://api.github.com/users/SamVerschueren/followers","following_url":"https://api.github.com/users/SamVerschueren/following{/other_user}","gists_url":"https://api.github.com/users/SamVerschueren/gists{/gist_id}","starred_url":"https://api.github.com/users/SamVerschueren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamVerschueren/subscriptions","organizations_url":"https://api.github.com/users/SamVerschueren/orgs","repos_url":"https://api.github.com/users/SamVerschueren/repos","events_url":"https://api.github.com/users/SamVerschueren/events{/privacy}","received_events_url":"https://api.github.com/users/SamVerschueren/received_events","type":"User","site_admin":false},"body":"This can be implemented like this as well\r\n\r\n```js\r\nparams.push(params.pop().replace('%s', imagePath));\r\n```","created_at":"2015-10-08T06:15:11Z","updated_at":"2015-10-08T06:15:11Z","html_url":"https://github.com/sindresorhus/wallpaper/pull/9#discussion_r41479077","pull_request_url":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/comments/41479077"},"html":{"href":"https://github.com/sindresorhus/wallpaper/pull/9#discussion_r41479077"},"pull_request":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9","id":47079781,"html_url":"https://github.com/sindresorhus/wallpaper/pull/9","diff_url":"https://github.com/sindresorhus/wallpaper/pull/9.diff","patch_url":"https://github.com/sindresorhus/wallpaper/pull/9.patch","issue_url":"https://api.github.com/repos/sindresorhus/wallpaper/issues/9","number":9,"state":"open","locked":false,"title":"Promisify linux","user":{"login":"SamVerschueren","id":1913805,"avatar_url":"https://avatars.githubusercontent.com/u/1913805?v=3","gravatar_id":"","url":"https://api.github.com/users/SamVerschueren","html_url":"https://github.com/SamVerschueren","followers_url":"https://api.github.com/users/SamVerschueren/followers","following_url":"https://api.github.com/users/SamVerschueren/following{/other_user}","gists_url":"https://api.github.com/users/SamVerschueren/gists{/gist_id}","starred_url":"https://api.github.com/users/SamVerschueren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamVerschueren/subscriptions","organizations_url":"https://api.github.com/users/SamVerschueren/orgs","repos_url":"https://api.github.com/users/SamVerschueren/repos","events_url":"https://api.github.com/users/SamVerschueren/events{/privacy}","received_events_url":"https://api.github.com/users/SamVerschueren/received_events","type":"User","site_admin":false},"body":"I promisified `linux.js`. Did some major refactoring work and wasn't able to test so there might be some flaws in it. It's also getting late here so an upfront sorry for some things I overlooked :).","created_at":"2015-10-07T20:46:47Z","updated_at":"2015-10-08T06:15:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"18a39b21ba48e788bda18da671f46bb258db5b29","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9/commits","review_comments_url":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9/comments","review_comment_url":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sindresorhus/wallpaper/issues/9/comments","statuses_url":"https://api.github.com/repos/sindresorhus/wallpaper/statuses/529683b1b0a9c3f3ec41a61218fa2f2131cc2a17","head":{"label":"SamVerschueren:pify","ref":"pify","sha":"529683b1b0a9c3f3ec41a61218fa2f2131cc2a17","user":{"login":"SamVerschueren","id":1913805,"avatar_url":"https://avatars.githubusercontent.com/u/1913805?v=3","gravatar_id":"","url":"https://api.github.com/users/SamVerschueren","html_url":"https://github.com/SamVerschueren","followers_url":"https://api.github.com/users/SamVerschueren/followers","following_url":"https://api.github.com/users/SamVerschueren/following{/other_user}","gists_url":"https://api.github.com/users/SamVerschueren/gists{/gist_id}","starred_url":"https://api.github.com/users/SamVerschueren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamVerschueren/subscriptions","organizations_url":"https://api.github.com/users/SamVerschueren/orgs","repos_url":"https://api.github.com/users/SamVerschueren/repos","events_url":"https://api.github.com/users/SamVerschueren/events{/privacy}","received_events_url":"https://api.github.com/users/SamVerschueren/received_events","type":"User","site_admin":false},"repo":{"id":43841605,"name":"wallpaper","full_name":"SamVerschueren/wallpaper","owner":{"login":"SamVerschueren","id":1913805,"avatar_url":"https://avatars.githubusercontent.com/u/1913805?v=3","gravatar_id":"","url":"https://api.github.com/users/SamVerschueren","html_url":"https://github.com/SamVerschueren","followers_url":"https://api.github.com/users/SamVerschueren/followers","following_url":"https://api.github.com/users/SamVerschueren/following{/other_user}","gists_url":"https://api.github.com/users/SamVerschueren/gists{/gist_id}","starred_url":"https://api.github.com/users/SamVerschueren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamVerschueren/subscriptions","organizations_url":"https://api.github.com/users/SamVerschueren/orgs","repos_url":"https://api.github.com/users/SamVerschueren/repos","events_url":"https://api.github.com/users/SamVerschueren/events{/privacy}","received_events_url":"https://api.github.com/users/SamVerschueren/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SamVerschueren/wallpaper","description":"Get or set the desktop wallpaper","fork":true,"url":"https://api.github.com/repos/SamVerschueren/wallpaper","forks_url":"https://api.github.com/repos/SamVerschueren/wallpaper/forks","keys_url":"https://api.github.com/repos/SamVerschueren/wallpaper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SamVerschueren/wallpaper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SamVerschueren/wallpaper/teams","hooks_url":"https://api.github.com/repos/SamVerschueren/wallpaper/hooks","issue_events_url":"https://api.github.com/repos/SamVerschueren/wallpaper/issues/events{/number}","events_url":"https://api.github.com/repos/SamVerschueren/wallpaper/events","assignees_url":"https://api.github.com/repos/SamVerschueren/wallpaper/assignees{/user}","branches_url":"https://api.github.com/repos/SamVerschueren/wallpaper/branches{/branch}","tags_url":"https://api.github.com/repos/SamVerschueren/wallpaper/tags","blobs_url":"https://api.github.com/repos/SamVerschueren/wallpaper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SamVerschueren/wallpaper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SamVerschueren/wallpaper/git/refs{/sha}","trees_url":"https://api.github.com/repos/SamVerschueren/wallpaper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SamVerschueren/wallpaper/statuses/{sha}","languages_url":"https://api.github.com/repos/SamVerschueren/wallpaper/languages","stargazers_url":"https://api.github.com/repos/SamVerschueren/wallpaper/stargazers","contributors_url":"https://api.github.com/repos/SamVerschueren/wallpaper/contributors","subscribers_url":"https://api.github.com/repos/SamVerschueren/wallpaper/subscribers","subscription_url":"https://api.github.com/repos/SamVerschueren/wallpaper/subscription","commits_url":"https://api.github.com/repos/SamVerschueren/wallpaper/commits{/sha}","git_commits_url":"https://api.github.com/repos/SamVerschueren/wallpaper/git/commits{/sha}","comments_url":"https://api.github.com/repos/SamVerschueren/wallpaper/comments{/number}","issue_comment_url":"https://api.github.com/repos/SamVerschueren/wallpaper/issues/comments{/number}","contents_url":"https://api.github.com/repos/SamVerschueren/wallpaper/contents/{+path}","compare_url":"https://api.github.com/repos/SamVerschueren/wallpaper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SamVerschueren/wallpaper/merges","archive_url":"https://api.github.com/repos/SamVerschueren/wallpaper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SamVerschueren/wallpaper/downloads","issues_url":"https://api.github.com/repos/SamVerschueren/wallpaper/issues{/number}","pulls_url":"https://api.github.com/repos/SamVerschueren/wallpaper/pulls{/number}","milestones_url":"https://api.github.com/repos/SamVerschueren/wallpaper/milestones{/number}","notifications_url":"https://api.github.com/repos/SamVerschueren/wallpaper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SamVerschueren/wallpaper/labels{/name}","releases_url":"https://api.github.com/repos/SamVerschueren/wallpaper/releases{/id}","created_at":"2015-10-07T20:01:22Z","updated_at":"2015-10-07T20:01:23Z","pushed_at":"2015-10-08T06:14:05Z","git_url":"git://github.com/SamVerschueren/wallpaper.git","ssh_url":"git@github.com:SamVerschueren/wallpaper.git","clone_url":"https://github.com/SamVerschueren/wallpaper.git","svn_url":"https://github.com/SamVerschueren/wallpaper","homepage":null,"size":187,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sindresorhus:master","ref":"master","sha":"a1d20f1703135a1a8f3e302eae234ce4dc6bb002","user":{"login":"sindresorhus","id":170270,"avatar_url":"https://avatars.githubusercontent.com/u/170270?v=3","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"repo":{"id":33351424,"name":"wallpaper","full_name":"sindresorhus/wallpaper","owner":{"login":"sindresorhus","id":170270,"avatar_url":"https://avatars.githubusercontent.com/u/170270?v=3","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sindresorhus/wallpaper","description":"Get or set the desktop wallpaper","fork":false,"url":"https://api.github.com/repos/sindresorhus/wallpaper","forks_url":"https://api.github.com/repos/sindresorhus/wallpaper/forks","keys_url":"https://api.github.com/repos/sindresorhus/wallpaper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sindresorhus/wallpaper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sindresorhus/wallpaper/teams","hooks_url":"https://api.github.com/repos/sindresorhus/wallpaper/hooks","issue_events_url":"https://api.github.com/repos/sindresorhus/wallpaper/issues/events{/number}","events_url":"https://api.github.com/repos/sindresorhus/wallpaper/events","assignees_url":"https://api.github.com/repos/sindresorhus/wallpaper/assignees{/user}","branches_url":"https://api.github.com/repos/sindresorhus/wallpaper/branches{/branch}","tags_url":"https://api.github.com/repos/sindresorhus/wallpaper/tags","blobs_url":"https://api.github.com/repos/sindresorhus/wallpaper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sindresorhus/wallpaper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sindresorhus/wallpaper/git/refs{/sha}","trees_url":"https://api.github.com/repos/sindresorhus/wallpaper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sindresorhus/wallpaper/statuses/{sha}","languages_url":"https://api.github.com/repos/sindresorhus/wallpaper/languages","stargazers_url":"https://api.github.com/repos/sindresorhus/wallpaper/stargazers","contributors_url":"https://api.github.com/repos/sindresorhus/wallpaper/contributors","subscribers_url":"https://api.github.com/repos/sindresorhus/wallpaper/subscribers","subscription_url":"https://api.github.com/repos/sindresorhus/wallpaper/subscription","commits_url":"https://api.github.com/repos/sindresorhus/wallpaper/commits{/sha}","git_commits_url":"https://api.github.com/repos/sindresorhus/wallpaper/git/commits{/sha}","comments_url":"https://api.github.com/repos/sindresorhus/wallpaper/comments{/number}","issue_comment_url":"https://api.github.com/repos/sindresorhus/wallpaper/issues/comments{/number}","contents_url":"https://api.github.com/repos/sindresorhus/wallpaper/contents/{+path}","compare_url":"https://api.github.com/repos/sindresorhus/wallpaper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sindresorhus/wallpaper/merges","archive_url":"https://api.github.com/repos/sindresorhus/wallpaper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sindresorhus/wallpaper/downloads","issues_url":"https://api.github.com/repos/sindresorhus/wallpaper/issues{/number}","pulls_url":"https://api.github.com/repos/sindresorhus/wallpaper/pulls{/number}","milestones_url":"https://api.github.com/repos/sindresorhus/wallpaper/milestones{/number}","notifications_url":"https://api.github.com/repos/sindresorhus/wallpaper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sindresorhus/wallpaper/labels{/name}","releases_url":"https://api.github.com/repos/sindresorhus/wallpaper/releases{/id}","created_at":"2015-04-03T07:04:15Z","updated_at":"2015-10-08T03:31:16Z","pushed_at":"2015-10-08T06:14:06Z","git_url":"git://github.com/sindresorhus/wallpaper.git","ssh_url":"git@github.com:sindresorhus/wallpaper.git","clone_url":"https://github.com/sindresorhus/wallpaper.git","svn_url":"https://github.com/sindresorhus/wallpaper","homepage":null,"size":187,"stargazers_count":252,"watchers_count":252,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":8,"forks":13,"open_issues":8,"watchers":252,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9"},"html":{"href":"https://github.com/sindresorhus/wallpaper/pull/9"},"issue":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/issues/9"},"comments":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/sindresorhus/wallpaper/statuses/529683b1b0a9c3f3ec41a61218fa2f2131cc2a17"}}}}