https://github.com/rongronggg9/powerline-exectime
A Powerline segment to show the execution (wall, user, sys) time of the last command, as well as the startup time of the shell.
https://github.com/rongronggg9/powerline-exectime
bash powerline prompt python statusline timer
Last synced: 12 days ago
JSON representation
A Powerline segment to show the execution (wall, user, sys) time of the last command, as well as the startup time of the shell.
- Host: GitHub
- URL: https://github.com/rongronggg9/powerline-exectime
- Owner: Rongronggg9
- License: mit
- Created: 2023-10-24T15:43:35.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-20T16:41:16.000Z (11 months ago)
- Last Synced: 2025-10-04T00:39:04.304Z (12 days ago)
- Topics: bash, powerline, prompt, python, statusline, timer
- Language: Python
- Homepage:
- Size: 521 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Powerline Exectime
A Powerline segment to show the execution time of the last command.
If configured properly, the startup time (consumed by `.bashrc`, etc.) of the shell can be measured as well.
By default, only wall time is measured. Setting `enable_user_sys_time` to true enables user and system time measurement.

## Installation
You don't need to install this package system-wide as it is enough to install it as a user package.
Thus, do not use `sudo` in the following commands unless you are aware of what you are doing.```sh
pip install .
```If `pip` complains that "This environment is externally managed," you may use virtual-env or try this
(again, do not use `sudo` unless you are aware of what you are doing):```sh
pip install --user --break-system-packages .
```After installation, restart the Powerline daemon (I assume that your init system is systemd):
```sh
systemctl --user restart powerline-daemon.service
```## Configuration
### Shell
#### Bash
In `~/.bashrc`, add the following line RIGHT AFTER the line that sources `powerline.sh`:
```bash
source /path/to/powerline_exectime/bindings/bash/powerline-exectime.sh
```To measure the startup time of Bash, add the following line at the beginning of `~/.bashrc`:
```bash
_POWERLINE_EXECTIME_TIMER_START="${EPOCHREALTIME/[^0-9]/}"
# _POWERLINE_EXECTIME_TIMER_START="$(date +%s%N)" # for Bash 4 or older
```If `~/.bashrc` starts with the following lines, the above line should be placed RIGHT AFTER them:
```bash
case $- in
*i*) ;;
*) return;;
esac
# ==== INSERT HERE ====
```If you do all these things correctly, `~/.bashrc` should look like this:
```bash
# something or nothing
case $- in
*i*) ;;
*) return;;
esac
_POWERLINE_EXECTIME_TIMER_START="${EPOCHREALTIME/[^0-9]/}"
# _POWERLINE_EXECTIME_TIMER_START="$(date +%s%N)" # for Bash 4 or older
# do something...
source /usr/share/powerline/bindings/bash/powerline.sh
source /path/to/powerline-exectime/bindings/bash/powerline-exectime.sh
# do something...
```#### Other Shells
In theory, `powerline-exectime` should work with other shells as well. However, appropriate bindings
are not provided yet. See [TODO](#todo) for more information.### Segment
In `~/.config/powerline/themes/shell/default.json`, add the `powerline_exectime.exectime` segment.
If the former file does not exist, copy `/usr/share/powerline/config_files/themes/shell/default.json`
before adding the segment.```json
{
"function": "powerline_exectime.exectime",
"priority": 30
}
```Or passing arguments for further customization:
> Refer to [powerline_exectime/segments.py](powerline_exectime/segments.py) for pydoc and default value.
```json
{
"function": "powerline_exectime.exectime",
"args": {
"threshold": 0.0,
"significant_figures": 3,
"max_parts": 2,
"gradient_range_low": 0.5,
"gradient_range_high": 30.0,
"highlight_groups": [
"exectime_gradient_bg"
],
"wall_time_prefix": "",
"user_time_prefix": "u:",
"sys_time_prefix": "s:",
"enable_user_sys_time": true
},
"priority": 30
}
```### Colorschemes
In `~/.config/powerline/colorschemes/default.json`, add `powerline-exectime`-specific colorschemes
(refer to [colorschemes/default.json](colorschemes/default.json)). If the former file does not exist,
just copy the latter one.## TODO
> Feel free to open an issue or a pull request if you have any idea.
- [ ] Publish to PyPI
- [ ] Add bindings for other shells
- [ ] Make the segment more configurable
- [ ] Make the segment a part of upstream (Powerline)