All Projects → popstas → zsh-command-time

popstas / zsh-command-time

Licence: other
Show execution time for long commands in zsh

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to zsh-command-time

Awesome Zsh Plugins
A collection of ZSH frameworks, plugins, themes and tutorials.
Stars: ✭ 10,129 (+5754.91%)
Mutual labels:  oh-my-zsh
Zsh Proxy
🔩 An oh-my-zsh plugin to configure proxy
Stars: ✭ 162 (-6.36%)
Mutual labels:  oh-my-zsh
Spaceship Prompt
🚀⭐ A Zsh prompt for Astronauts
Stars: ✭ 15,748 (+9002.89%)
Mutual labels:  oh-my-zsh
Dotfiles
Alacritty + Tmux + Oh My Zsh + Neovim = ❤️
Stars: ✭ 95 (-45.09%)
Mutual labels:  oh-my-zsh
Sheldon
A fast, configurable, shell plugin manager
Stars: ✭ 144 (-16.76%)
Mutual labels:  oh-my-zsh
Zsh In Docker
Install Zsh, Oh-My-Zsh and plugins inside a Docker container with one line!
Stars: ✭ 169 (-2.31%)
Mutual labels:  oh-my-zsh
Pi
A minimalist zsh theme with git status decorations
Stars: ✭ 76 (-56.07%)
Mutual labels:  oh-my-zsh
bliss-zsh
A delicate Zsh theme that injects color without overwhelming your workspace
Stars: ✭ 20 (-88.44%)
Mutual labels:  oh-my-zsh
Zsh Theme
Yet another zsh theme
Stars: ✭ 153 (-11.56%)
Mutual labels:  oh-my-zsh
Ansible Role Zsh
Setup antigen with oh-my-zsh, powerlevel10k theme, fzf, autosuggestions, syntax-highlighting
Stars: ✭ 210 (+21.39%)
Mutual labels:  oh-my-zsh
Zsh Nvm
Zsh plugin for installing, updating and loading nvm
Stars: ✭ 1,670 (+865.32%)
Mutual labels:  oh-my-zsh
Purify
🌈 Clean & vibrant color schemes for Vim, Terminals...
Stars: ✭ 142 (-17.92%)
Mutual labels:  oh-my-zsh
Zeta Zsh Theme
Another ⭐️ theme for oh-my-zsh
Stars: ✭ 184 (+6.36%)
Mutual labels:  oh-my-zsh
Zsh to fish
How to make zsh like fish?
Stars: ✭ 93 (-46.24%)
Mutual labels:  oh-my-zsh
Starship
☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell!
Stars: ✭ 20,504 (+11752.02%)
Mutual labels:  oh-my-zsh
Castle Winbuntu
Homesick Castle for use on WSL.
Stars: ✭ 87 (-49.71%)
Mutual labels:  oh-my-zsh
Dotfiles Win
🙈 oh-my-zsh on bash on windows configuration files
Stars: ✭ 167 (-3.47%)
Mutual labels:  oh-my-zsh
dotfiles
My amazing vim, zsh and tmux config files
Stars: ✭ 25 (-85.55%)
Mutual labels:  oh-my-zsh
dotfiles
My doots. Changes are frequent, stability not guaranteed. Supports Arch, CentOS and Darwin.
Stars: ✭ 27 (-84.39%)
Mutual labels:  oh-my-zsh
Zsh Vi Mode
💻 A better and friendly vi(vim) mode plugin for ZSH.
Stars: ✭ 181 (+4.62%)
Mutual labels:  oh-my-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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].