Skip to content

Commit 533bb3a

Browse files
committed
Upload the readme (and screenshots) and the setup.py .
1 parent 868a573 commit 533bb3a

File tree

7 files changed

+149
-5
lines changed

7 files changed

+149
-5
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# POWERLINE SWISSARMYKNIFE
2+
3+
A [Powerline](https://powerline.readthedocs.io/en/master/) segment. This segment shows the execution of complex command line defined by user.
4+
5+
By [Miguel de Dios Matias](https://github.com/mdtrooper).
6+
7+
## Installation
8+
9+
### Using pip
10+
11+
```
12+
pip install powerline-swissarmyknife
13+
```
14+
15+
## Configuration
16+
17+
You can activate the Powerline Slotmachine segment by adding it to your segment configuration,
18+
for example in `.config/powerline/themes/shell/default.json`:
19+
20+
```json
21+
{
22+
"function": "powerline_swissarmyknife.execute",
23+
"priority": 30,
24+
"args": {
25+
"commandLine": "ps aux --no-headers | wc -l",
26+
"postContent": "⚙️"
27+
}
28+
},
29+
```
30+
31+
Show the number of processes running in your system.
32+
33+
![screenshot number processes](https://raw.githubusercontent.com/mdtrooper/powerline_swissarmyknife/master/powerline_swissarmyknife_number_processes.jpg "screenshot number processes")
34+
35+
### Arguments
36+
* **commandLine (string)**: The command line to execute, it can be complex (with pipes) (remember python3 runs as /bin/sh, not bash).
37+
* **line (string)**: The string to format the content of segment.
38+
* Default: "{preContent}{output}{err}{postContent}"
39+
* **preContent (string)**: The string to show before the result.
40+
* Default: ""
41+
* **postContent (string)**: The string to show after the result.
42+
* Default: "🤖"
43+
* **successCodes (list(int) or None)**: The values are success code return (normally 0), the background change to critical success.
44+
* Default: None
45+
* **failureCodes (list(int) or None)**: The values are fail code return, the background change to critical failture.
46+
* Default: None
47+
48+
### Examples
49+
50+
Shows the upload and download rate and count of torrents download in Deluge.
51+
52+
```json
53+
{
54+
"function": "powerline_swissarmyknife.execute",
55+
"priority": 30,
56+
"args": {
57+
"commandLine": "deluge-console status | awk '/Total upload:/{print $3$4} /Total download:/{print $3$4} /Downloading:/{print $2\"D\"}' | tr '\n' ' '",
58+
"postContent": ""
59+
}
60+
},
61+
```
62+
63+
64+
![screenshot deluge](https://raw.githubusercontent.com/mdtrooper/powerline_dice/master/powerline_deluge.jpg "screenshot deluge")
65+
66+
Show a random pornstar from redtube api.
67+
68+
```json
69+
{
70+
"function": "powerline_swissarmyknife.execute",
71+
"priority": 30,
72+
"args": {
73+
"commandLine": "if [ -f /tmp/list.redtube.json ]; then list=$(cat /tmp/list.redtube.json); else list=$(curl 'https://api.redtube.com/?data=redtube.Stars.getStarList&output=json'); echo $list > /tmp/list.redtube.json; fi; list_length=$(echo $list | jq '.stars | length'); rand=$(echo 'ibase=16;' $(openssl rand -hex 4 | tr '[a-z]' '[A-Z]') | bc); echo $list | jq \".stars[$(echo \\\"$rand % $list_length\\\" | bc)].star.star_name\" -r",
74+
"postContent": " 🎥"
75+
}
76+
},
77+
```
78+
79+
![screenshot pornstar](https://raw.githubusercontent.com/mdtrooper/powerline_dice/master/powerline_pornstar.jpg "screenshot pornstar")
80+
81+
## License
82+
83+
Licensed under [the GPL3 License](https://github.com/mdtrooper/powerline_slotmachine/blob/master/LICENSE).

powerline_deluge.jpg

42.7 KB
Loading

powerline_pornstar.jpg

53 KB
Loading

powerline_swissarmyknife/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
#
3+
# slotmachine_oneline.py
4+
# Copyright (C) 2019 Miguel de Dios Matias
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from .execute import execute

powerline_swissarmyknife/execute.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,36 @@
1818

1919
import subprocess
2020

21-
def execute(pl, commandLine='', line='{preContent}{output}{err}{postContent}', successCodes=None, failureCode=None, preContent='', postContent='🧰', *args, **kwargs):
21+
def execute(pl, commandLine='', line='{preContent}{output}{err}{postContent}', preContent='', postContent='🤖', successCodes=None, failureCodes=None, *args, **kwargs):
22+
"""
23+
Return a segment with the info (as output and or error) from command line execution.
24+
Args:
25+
pl (object): The powerline logger.
26+
commandLine (string): The command line to execute, it can be complex (with pipes).
27+
line (string): The string to format the content of segment.
28+
Default value: {preContent}{output}{err}{postContent}
29+
preContent (string): The string to show before the result.
30+
postContent (string): The string to show after the result.
31+
Default value: 🤖
32+
successCodes list(int) or None: The values are success code return (normally 0), the background
33+
change to critical success.
34+
failureCodes list(int) or None: The values are fail code return, the background
35+
change to critical failture.
36+
Returns:
37+
segment (list(dict)): The formated line with output of execution command line as powerline segment.
38+
"""
2239
result = subprocess.run(commandLine, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2340

2441
returncode = result.returncode
25-
output = result.stdout.decode('utf8')
26-
err = result.stderr.decode('utf8')
42+
output = result.stdout.decode('utf8').strip()
43+
err = result.stderr.decode('utf8').strip()
2744

2845
color = ['information:regular']
2946
if isinstance(successCodes, list):
3047
if returncode in successCodes:
3148
color = ['critical:success']
32-
elif isinstance(failureCode, list):
33-
if returncode in failureCode:
49+
elif isinstance(failureCodes, list):
50+
if returncode in failureCodes:
3451
color = ['critical:failure']
3552

3653
return [{
46.6 KB
Loading

setup.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup(
7+
name="powerline_swissarmyknife",
8+
version="1.0.0",
9+
license="GPLv3+",
10+
author="Miguel de Dios Matias",
11+
author_email="tres.14159@gmail.com",
12+
description="A Powerline segment.This segment shows the execution of complex command line defined by user.",
13+
long_description=long_description,
14+
long_description_content_type="text/markdown",
15+
url="https://github.com/mdtrooper/powerline_swissarmyknife",
16+
packages=setuptools.find_packages(),
17+
classifiers=[
18+
"Programming Language :: Python :: 3",
19+
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
20+
"Operating System :: OS Independent",
21+
"Environment :: Console"
22+
],
23+
python_requires='>=3.7',
24+
platforms=['any']
25+
)

0 commit comments

Comments
 (0)