npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zsh-history

v1.0.1

Published

Read and parse your complete zsh history.

Downloads

16

Readme

zsh history

Build Status

Read and parse your complete zsh history.

require('zsh-history')().then(console.log);

[
  {
    time: Date('2016-08-20T20:09:24.000Z'),
    executionTime: 2,
    command: 'sleep',
    arguments: [ '2' ]
  },

  // many more commands
]

API

#history([histFile])

Parse a zsh history file, defaulting to ~/.zsh_history. Pass a path to a different history file if that's not where your history lives.

Returns a Promise resolving to an array of commands, or throwing an error if there was an issue parsing the file.

Input-Output Correspondence

zsh History Format

: 1471766804:3;git push origin master
  • 1471766804: The time the command was executed in seconds from the Unix Epoch.
  • 3: The execution time of the command in seconds.
  • git push origin master: The full command executed and its arguments.

JavaScript Parsed Command

Each command (in the array of commands promised) has four parts:

{
  time: Date('2016-08-20T20:09:24.000Z'),
  executionTime: 2,
  command: 'sleep',
  arguments: [ '2' ]
}
  • time: An instance of Date. The date and time the command was executed with second resolution.
  • executionTime: The execution time of the command in seconds.
  • command: The command executed. Just the first space-separated word from the full command.
  • arguments: An array of arguments passed to the command, split with argv-split.

Example

Read the default zsh-history and log the result.

require('zsh-history')().then(console.log);

[
  {
    time: Date('2016-08-20T20:09:24.000Z'),
    executionTime: 2,
    command: 'sleep',
    arguments: [ '2' ]
  },

  // many more commands
]

Notes on Execution Time

You might see all 0s for execution time, even when commands (like sleep 1) don't execute instantaneously.

This likely means you are using the INC_APPEND_HISTORY and SHARE_HISTORY options, both of which are oh-my-zsh defaults.

These options write history to ~/.zsh_history before the command finishes executing so it can be immediately shared with other shell instances. A side effect is all zero execution times, since zsh has written down the command before it finishes.

Confusingly, history will report non-zero times for commands that took greater than zero seconds in your current shell. zsh maintains an internal history for the current shell, which history (aliased to fc -l 1) merges with ~/.zsh_history. The internal history contains accurate execution times regardless of settings.

To write execution time to history, the following zsh options must be set:

unsetopt SHARE_HISTORY
unsetopt APPEND_HISTORY
unsetopt INC_APPEND_HISTORY

setopt EXTENDED_HISTORY
setopt INC_APPEND_HISTORY_TIME

zsh has much more documentation on its history options.

Share History Without SHARE_HISTORY

To share history between shells with SHARE_HISTORY off, you may can to alias history="fc -R && fc -l 1", which will reload the history file when you run history.

Retrieving a session's own history (ex. up arrow) will always work as expected.