• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
    Shell
  • Created over 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Show execution time for long commands in zsh

zsh-command-time

Plugin that output time: xx after long commands and export ZSH_COMMAND_TIME variable for usage in your scripts.

It similar builin feature REPORTTIME, but it outputs only if user + system time >= REPORTTIME in config. For example:

$ time sleep 3
sleep 3  0,00s user 0,00s system 0% cpu 3,008 total

Sleep don't consume any cpu time and REPORTTIME "don't see" such idle commands.

If you need to monitor only cpu-angry commands, use REPORTTIME instead this plugin.

Install with antigen

antigen bundle popstas/zsh-command-time

Install with zplug

zplug "popstas/zsh-command-time"

Install for oh-my-zsh

Download:

git clone https://github.com/popstas/zsh-command-time.git ~/.oh-my-zsh/custom/plugins/command-time

And add command-time to plugins in .zshrc.

Configuration

You can override defaults in .zshrc:

# If command execution time above min. time, plugins will not output time.
ZSH_COMMAND_TIME_MIN_SECONDS=3

# Message to display (set to "" for disable).
ZSH_COMMAND_TIME_MSG="Execution time: %s sec"

# Message color.
ZSH_COMMAND_TIME_COLOR="cyan"

# Exclude some commands
ZSH_COMMAND_TIME_EXCLUDE=(vim mcedit)

Customization

You can customize view of the plugin by redefinition of function zsh_command_time. There is an example of custom definition zsh_command_time:

zsh_command_time() {
    if [ -n "$ZSH_COMMAND_TIME" ]; then
        hours=$(($ZSH_COMMAND_TIME/3600))
        min=$(($ZSH_COMMAND_TIME/60))
        sec=$(($ZSH_COMMAND_TIME%60))
        if [ "$ZSH_COMMAND_TIME" -le 60 ]; then
            timer_show="$fg[green]$ZSH_COMMAND_TIME s."
        elif [ "$ZSH_COMMAND_TIME" -gt 60 ] && [ "$ZSH_COMMAND_TIME" -le 180 ]; then
            timer_show="$fg[yellow]$min min. $sec s."
        else
            if [ "$hours" -gt 0 ]; then
                min=$(($min%60))
                timer_show="$fg[red]$hours h. $min min. $sec s."
            else
                timer_show="$fg[red]$min min. $sec s."
            fi
        fi
        printf "${ZSH_COMMAND_TIME_MSG}\n" "$timer_show"
    fi
}

You can see result of this function on the following screenshot:

screenshot

Variable $ZSH_COMMAND_TIME contains execution time in seconds. We calculate how many minutes and hours it was and print this information to terminal.

  • Commands that were executed less than one minutes highlights by green color.
  • Commands that were executed less than three minutes highlights by yellow color.
  • Commands that were executed more than three minutes highlights by red color.

Usage with powerlevel9k theme

You should not want to use this plugin with powerlevel9k. Sinse powerlevel9k v0.6.0 theme have native segment command_execution_time (see PR), so you can just add it to your prompt:

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs vcs command_execution_time time)

If you still want to use it with powerlevel9k, add custom element in .zshrc:

POWERLEVEL9K_CUSTOM_COMMAND_TIME="zsh_command_time"
POWERLEVEL9K_CUSTOM_COMMAND_TIME_BACKGROUND="253" # white
POWERLEVEL9K_CUSTOM_COMMAND_TIME_FOREGROUND="000" # black

And add element custom_command_time to your prompt:

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs vcs custom_command_time time)

Provision with ansible

Plugin command-time included in ansible role viasite-ansible/ansible-role-zsh with other useful plugins. Plugin excluded from viasite-ansible.zsh, but you can still check role.

More Repositories

1

yandex-dialogs-client

Тестирование навыков Яндекс.Диалогов Алисы с автотестами
Vue
39
star
2

yandex-dialogs-whatis

Навык "Вторая память" для Алисы (Яндекс.Диалоги), подскажет, что где находится, если вы перед этим расскажете ему об этом
JavaScript
21
star
3

transmission-cli

Transmission PHP client for detect profit torrents and automate weburg.net downloads
PHP
19
star
4

yandex-dialogs-products-shop-list

Навык "Список покупок" для Алисы (Яндекс.Диалоги)
JavaScript
9
star
5

nodemcu-co2-temp-hum-grafana

Temperature, humidity and CO2 in Grafana (NodeMCU, MH-Z19, DHT11) with MQTT and OTA updates
Lua
8
star
6

json-viewer

Web viewer for viasite/site-audit-seo
Vue
6
star
7

yandex-dialogs-tester

Автоматические тесты для Яндекс.Диалогов
JavaScript
6
star
8

ansible-server

Ansible playbook for setup shared hosting
Shell
4
star
9

scad-models

3D Customizable Models - STL, SCAD generator: 1.Select model, 2. Customize, 3. Download STL or SCAD, 4. Print
JavaScript
4
star
10

yandex-speechkit-talk-recognition

Распознавание больших файлов разговоров через Yandex SpeechKit
JavaScript
4
star
11

windows11-manager

JavaScript
3
star
12

windows-mqtt

Windows service for control PC with MQTT, modular
JavaScript
3
star
13

zsh-browser-history

History explore of Firefox, Chrome, Yandex from terminal
Shell
2
star
14

pixel-server

Kapacitor alerting with RGB led and display controlled arduino or AnyBar
Go
2
star
15

yandex-dialogs-sdk-chatbase

Отправка данных диалога в Google Chatbase
JavaScript
2
star
16

planfix-go

Клиент API для Планфикса на Go
Go
2
star
17

site-audit-seo-readability

JavaScript
2
star
18

yandex-speechkit-talk-viewer

Vue
1
star
19

mqtt2tts

Receive text from MQTT and TTS via Google TTS
JavaScript
1
star
20

arduino-pixel-meter

RGB led and 16x2 display
Arduino
1
star
21

site-audit-seo-yake

JavaScript
1
star
22

ansible-ubuntu-desktop

Setup Ubuntu desktop (Unity).
Shell
1
star
23

strava-mqtt

Send last activities from Strava to MQTT
JavaScript
1
star
24

chrome-tabs-exporter

JavaScript
1
star
25

terraform-selectel

Demo project for provision servers with terraform on Selectel
HCL
1
star
26

nodemcu-ws2812-strip

NodeMcu and WS2812 LED Strip "hello world" project
Lua
1
star
27

mongoose-redmond-rcm-1512-mqtt

JavaScript
1
star
28

chords-data

Repository with data generated with chords-parser
1
star
29

chords-viewer

View chords.json generated with popstas/chords-parser
SCSS
1
star