├── .npmignore ├── LICENSE ├── README.md ├── index.js └── package.json /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | tmp 4 | *.swp 5 | .npmignore 6 | .ftppass 7 | tests 8 | *.sublime-project 9 | *.sublime-workspace -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 John Xiao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # set iterm2 badge 2 | 3 | Thanks to [@sel-fish](http://stackoverflow.com/questions/36613285/how-to-exec-script-to-set-iterm2-badge-from-nodejs) 4 | 5 | ## Usage 6 | 7 | Use it in your Webpack config, Gulpfile.js, Express app or other Node project to set a distinct infomation on the right up corner of Iterm2. 8 | 9 | ### pure nodejs integration 10 | 11 | ```js 12 | var setIterm2Badge = require('set-iterm2-badge'); 13 | var port = '8088'; 14 | setIterm2Badge(port); 15 | ``` 16 | 17 | ### browser-sync integration 18 | 19 | ```js 20 | var setIterm2Badge = require('set-iterm2-badge'); 21 | var bs = require('browser-sync').create(); 22 | bs.init({ 23 | port: "8080" 24 | }, function(err, bs) { 25 | // The actual port may not be the passed in "8080" 26 | // as bs ensures listen a empty port inside 27 | setIterm2Badge(bs.options.getIn(['port'])); 28 | }) 29 | ``` 30 | 31 | ## Result Preview 32 | 33 | ![result](http://ww3.sinaimg.cn/large/6110a121gw1f2wbj234hoj20qq0g83yv.jpg) 34 | 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // Thanks to [@sel-fish](http://stackoverflow.com/questions/36613285/how-to-exec-script-to-set-iterm2-badge-from-nodejs) 2 | 3 | function setBadge(rawBadgeFormat) { 4 | var base64BadgeFormat = new Buffer(rawBadgeFormat.toString()).toString('base64') 5 | var setBadgeFormatCmd = 'printf "\\e]1337;SetBadgeFormat=' + base64BadgeFormat + '\\a"' 6 | require('child_process').exec(setBadgeFormatCmd, function(error, stdout, stderr) { 7 | if (error) console.log(error); 8 | process.stdout.write(stdout); // this line actually do the trick 9 | process.stderr.write(stderr); 10 | }); 11 | } 12 | 13 | module.exports = setBadge -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "set-iterm2-badge", 3 | "version": "0.0.4", 4 | "author": { 5 | "name": "Johnxiao" 6 | }, 7 | "description": "set-iterm2-badge", 8 | "repository": { 9 | "type": "git", 10 | "url": "git+ssh://git@github.com/bammoo/set-iterm2-badge.git" 11 | }, 12 | "licenses": [ 13 | { 14 | "type": "MIT", 15 | "url": "http://www.opensource.org/licenses/mit-license.php" 16 | } 17 | ], 18 | "bugs": { 19 | "url": "https://github.com/bammoo/set-iterm2-badge/issues" 20 | }, 21 | "homepage": "https://github.com/bammoo/set-iterm2-badge" 22 | } 23 | --------------------------------------------------------------------------------