├── .gitignore ├── system ├── mygif.gif ├── src ├── eject.png ├── pendrive.png └── index.js ├── .babelrc ├── .npmignore ├── scripts └── debug ├── webpack.config.js ├── Readme.md ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /system: -------------------------------------------------------------------------------- 1 | /media/adrian/Datos/DESARROLLO/Cerebro/system -------------------------------------------------------------------------------- /mygif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdrianArencibia/cerebro-linux-system/HEAD/mygif.gif -------------------------------------------------------------------------------- /src/eject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdrianArencibia/cerebro-linux-system/HEAD/src/eject.png -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "transform-react-jsx", 4 | "syntax-jsx" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | .babelrc 3 | node_modules 4 | scripts 5 | screenshot.png 6 | webpack.config.js 7 | -------------------------------------------------------------------------------- /src/pendrive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdrianArencibia/cerebro-linux-system/HEAD/src/pendrive.png -------------------------------------------------------------------------------- /scripts/debug: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | symlink="${HOME}/.config/Cerebro/plugins/node_modules/${PWD##*/}" 3 | ln -s "${PWD}" "$symlink" 4 | trap "rm \"$symlink\"" SIGHUP SIGINT SIGTERM 5 | ./node_modules/.bin/webpack --watch 6 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const path = require('path'); 3 | 4 | module.exports = { 5 | entry: { 6 | index: './src/index' 7 | }, 8 | output: { 9 | path: './dist', 10 | libraryTarget: 'commonjs2', 11 | filename: 'index.js' 12 | }, 13 | resolve: { 14 | extensions: ['.js'], 15 | modules: [ 16 | path.resolve('./src'), 17 | path.resolve('./node_modules'), 18 | ] 19 | }, 20 | target: 'electron-renderer', 21 | module: { 22 | rules: [{ 23 | test: /\.jsx?$/, 24 | use: { 25 | loader: 'babel-loader' 26 | }, 27 | exclude: /node_modules/, 28 | 29 | }, { 30 | test: /\.css$/, 31 | use: [{ 32 | loader: 'style-loader' 33 | }, { 34 | loader: 'css-loader', 35 | query: { 36 | modules: true 37 | } 38 | }] 39 | }, { 40 | test: /\.png$/, 41 | loader: 'url-loader' 42 | },] 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # cerebro-linux-system 2 | 3 | > [Cerebro](https://cerebroapp.com) plugin to automate some Linux system features 4 | 5 | ![cerebro-linux-system](mygif.gif) 6 | 7 | ## Usage 8 | 9 | In Cerebro, type command that you need and `enter` to execute it. 10 | 11 | ### List of available system commands: 12 | #### Power control 13 | * `Restart` 14 | * `Sleep` 15 | * `Shut Down` 16 | 17 | #### Volume control 18 | * `! mute` Turn off the volume 19 | * `! unmute` Turn on the volume 20 | * `! 100%` Set the volume to 100% 21 | * `! (+|++|+++)` Increase volume by (10|30|50)% 22 | * `! (-|--|---)` Decrease volume by (10|30|50)% 23 | 24 | 25 | #### Wifi control 26 | * `wifi on` Turn on the wifi 27 | * `wifi off` Turn off the wifi 28 | 29 | #### Pendrive control 30 | * `eject (name)` Unmount and eject pendrive 31 | 32 | 33 | #### Brightness control 34 | * `* (10|20|30|40|50|60|70|80|90|100)%` Set the Brightness to seleced % 35 | 36 | ## Related 37 | 38 | - [Cerebro](http://github.com/KELiON/cerebro) – main repo for Cerebro app; 39 | 40 | 41 | ## License 42 | 43 | MIT © Adrian Arencibia Herrera 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cerebro-linux-system", 3 | "version": "0.2.8", 4 | "description": "Cerebro plugin to automate some Linux system features", 5 | "license": "MIT", 6 | "repository": "adrian011494/cerebro-linux-system", 7 | "author": { 8 | "name": "Adrian Arencibia Herrera", 9 | "email": "adrian011494@gmail.com", 10 | "url": "https://humanos.uci.cu" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "build": "webpack && babili dist -d dist --compact --no-comments", 17 | "debug": "./scripts/debug", 18 | "prepublish": "rm -rf ./dist && npm run build" 19 | }, 20 | "main": "dist/index.js", 21 | "keywords": [ 22 | "cerebro-plugin", 23 | "cerebro" 24 | ], 25 | "devDependencies": { 26 | "babel-cli": "^6.18.0", 27 | "babel-loader": "^6.2.8", 28 | "babel-plugin-syntax-jsx": "^6.18.0", 29 | "babel-plugin-transform-react-jsx": "^6.8.0", 30 | "babili": "0.0.9", 31 | "cerebro-tools": "^0.1.0", 32 | "css-loader": "^0.26.0", 33 | "react": "^15.4.1", 34 | "style-loader": "^0.13.1", 35 | "webpack": "2.1.0-beta.27", 36 | "file-loader":"0.10.0", 37 | "url-loader":"0.5.7" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var stringSearcher = require('string-search'); 3 | var path="/usr/share/applications"; 4 | 5 | var apps = new Array(); 6 | 7 | //fs.readdir(path, (err, files) => { 8 | //files.forEach(file => { 9 | //console.log("\n\n"+file+"\n\n"); 10 | //if(fs.lstatSync(path+"/"+file).isFile()) 11 | fs.readFile("/usr/share/applications/cinnamon-control-center.desktop",{encoding: "utf8"}, function read(err, data) { 12 | if (err) { 13 | console.log(err) 14 | } 15 | 16 | content = data; 17 | var nameapp=""; 18 | stringSearcher.find(content, '^Name').then(function(resultArr) { 19 | //resultArr => [ {line: 1, text: 'This is the string to search text in'} ] 20 | nameapp=resultArr[0].text.replace("Name=",""); 21 | console.log(nameapp); 22 | if(!apps[nameapp]) 23 | apps[nameapp]=""; 24 | 25 | }); 26 | stringSearcher.find(content, '^Exec') 27 | .then(function(resultArr) { 28 | //resultArr => [ {line: 1, text: 'This is the string to search text in'} ] 29 | if(resultArr[0].text){ 30 | var s=resultArr[0].text.replace("Exec=",""); 31 | if(s.indexOf('%')>0) 32 | s=s.substring(0, s.indexOf('%')); 33 | apps[nameapp]=s; 34 | } 35 | console.log(apps); 36 | 37 | 38 | //console.log(apps); 39 | }); 40 | 41 | 42 | // Invoke the next step here however you like 43 | //console.log(content); // Put all of the code here (not the best solution) 44 | // Or put the next step in a function and invoke it 45 | }); 46 | // console.log(file); 47 | // }); 48 | console.log(apps); 49 | //}) 50 | 51 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /* eslint max-len: [0] */ 2 | const ejectIcon = require('./eject.png'); 3 | const pendriveIcon = require('./pendrive.png'); 4 | 5 | var usb = []; 6 | 7 | const { search, shellCommand } = require('cerebro-tools') 8 | 9 | const COMMANDS = { 10 | Restart: { 11 | command: "systemctl reboot", 12 | }, 13 | Sleep: { 14 | command: 'systemctl suspend', 15 | }, 16 | 'Shut Down': { 17 | command: "systemctl poweroff", 18 | }, 19 | 'Empty Trash': { 20 | command: "rm -rf ~/.local/share/Trash/*" 21 | }, 22 | '! mute': { 23 | command: "amixer -D pulse set Master mute", 24 | subtitle: "Volume off" 25 | }, 26 | '! unmute': { 27 | command: "amixer -D pulse set Master unmute", 28 | subtitle: "Volume on" 29 | } 30 | , 31 | '! +': { 32 | command: "amixer -D pulse set Master unmute;amixer set Master 10+", 33 | subtitle: "Volume +10%" 34 | }, 35 | '! ++': { 36 | command: "amixer -D pulse set Master unmute;amixer set Master 30+", 37 | subtitle: "Volume +30%" 38 | } 39 | , 40 | '! +++': { 41 | command: "amixer -D pulse set Master unmute;amixer set Master 50+", 42 | subtitle: "Volume +50%" 43 | }, 44 | '! 100%': { 45 | command: "amixer -D pulse set Master unmute;amixer set Master 100+", 46 | subtitle: "Volume 100%" 47 | }, 48 | '! -': { 49 | command: "amixer -D pulse set Master unmute;amixer set Master 10-", 50 | subtitle: "Volume -10%" 51 | }, 52 | '! --': { 53 | command: "amixer -D pulse set Master unmute;amixer set Master 30-", 54 | subtitle: "Volume -30%" 55 | } 56 | , 57 | '! ---': { 58 | command: "amixer -D pulse set Master unmute;amixer set Master 50-", 59 | subtitle: "Volume -50%" 60 | } 61 | , 62 | 'wifi on': { 63 | command: "nmcli radio wifi on", 64 | subtitle: "Enable wifi" 65 | }, 66 | 'wifi off': { 67 | command: "nmcli radio wifi off", 68 | subtitle: "Disable wifi" 69 | } 70 | , 71 | '* 10%': { 72 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.1", 73 | subtitle: "Brightness 10%" 74 | } 75 | , 76 | '* 20%': { 77 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.2", 78 | subtitle: "Brightness 20%" 79 | } 80 | , 81 | '* 30%': { 82 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.3", 83 | subtitle: "Brightness 30%" 84 | } 85 | , 86 | '* 40%': { 87 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.4", 88 | subtitle: "Brightness 40%" 89 | }, 90 | '* 50%': { 91 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.5", 92 | subtitle: "Brightness 50%" 93 | }, 94 | '* 60%': { 95 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.6", 96 | subtitle: "Brightness 60%" 97 | }, 98 | '* 70%': { 99 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.7", 100 | subtitle: "Brightness 70%" 101 | }, 102 | '* 80%': { 103 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.8", 104 | subtitle: "Brightness 80%" 105 | }, 106 | '* 90%': { 107 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 0.9", 108 | subtitle: "Brightness 90%" 109 | }, 110 | '* 100%': { 111 | command: "xrandr --output $(xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1) --brightness 1", 112 | subtitle: "Brightness 100%" 113 | } 114 | } 115 | 116 | 117 | 118 | 119 | 120 | /** 121 | * Plugin for Linux system commands 122 | * 123 | * @param {String} options.term 124 | * @param {Function} options.display 125 | */ 126 | const fn = ({ term, display }) => { 127 | const commands = search(Object.keys(COMMANDS), term) 128 | if (commands.length > 0) { 129 | const result = commands.map((cmd) => ({ 130 | title: cmd, 131 | subtitle: COMMANDS[cmd].subtitle, 132 | term: cmd, 133 | icon: COMMANDS[cmd].icon, 134 | onSelect: () => shellCommand(COMMANDS[cmd].command) 135 | })) 136 | display(result) 137 | } 138 | 139 | const match = /eject\s(.*)/.exec(term); 140 | if (term =="eject"||match) { 141 | usb = []; 142 | 143 | shellCommand('lsblk -J -p -o name,label,size,type,state,rm,hotplug,mountpoint') 144 | .then((output) => { 145 | var partitios = JSON.parse(output); 146 | for (var attributename in partitios.blockdevices) { 147 | //console.log(partitios.blockdevices[attributename]); 148 | for (var c in partitios.blockdevices[attributename].children) { 149 | //console.log(partitios.blockdevices[attributename].children[c]); 150 | 151 | if (partitios.blockdevices[attributename].children[c].mountpoint != null && 152 | partitios.blockdevices[attributename].children[c].hotplug == "1") { 153 | // console.log(partitios.blockdevices[attributename].children[c]); 154 | usb.push(partitios.blockdevices[attributename].children[c]); 155 | showMy(display); 156 | } 157 | } 158 | 159 | } 160 | 161 | //console.log(output); 162 | }); 163 | 164 | 165 | } 166 | 167 | } 168 | 169 | 170 | function showMy(display) { 171 | if (usb.length) { 172 | display([{ 173 | icon: ejectIcon, 174 | 175 | title: 'Eject All', 176 | subtitle: 'Unmount and eject all external disks and partitions', 177 | onSelect: () => usb.forEach(ejectDrive) 178 | }].concat(usb.map(({ label, mountpoint, size }) => ({ 179 | icon: pendriveIcon, 180 | 181 | title: (label==null?"":label) + " " + size, 182 | subtitle: `Unmount and eject ${mountpoint} `, 183 | onSelect: () => ejectDrive({ mountpoint, label }) 184 | })))); 185 | 186 | } 187 | } 188 | 189 | function ejectDrive({ mountpoint, label }) { 190 | 191 | shellCommand('umount "' + mountpoint + '"').then(() => { 192 | new Notification('Drive Ejected', { 193 | body: `${label==null?"Drive":label} has been ejected.` 194 | }); 195 | }); 196 | } 197 | 198 | 199 | 200 | module.exports = { fn } 201 | --------------------------------------------------------------------------------