• Stars
    star
    220
  • Rank 179,364 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 10 years ago
  • Updated 3 months ago

Reviews

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

Repository Details

Plot your .zsh_history.

Zsh History Analysis

zsh logs commands and timestamps to ~/.zsh_history for shell features such as reverse history search. This repository is a fun project that provides shell, Python, and R scripts to parse, analyze, visualize .zsh_history files. These scripts can be extended to support Bash's .bash_history.

Getting Started

You can run this on your .zsh_history files by cloning this repository with git clone https://github.com/bamos/zsh-history-analysis.git and installing the following prerequisites. Ensure you have increased the history file size so commands aren't removed. Then, follow the steps in Control Flow to generate the plots.

Prerequisites

  • PATH contains python3 and Rscript, which can be installed from your package manager. In Arch Linux, the required packages are python and r.
  • R: ggplot2 and reshape are installed from an R shell with install.packages("ggplot2") and install.packages("reshape").

Increasing the History File Size

Unfortunately, zsh's default history file size is limited to 10000 lines by default and will truncate the history to this length by deduplicating entries and removing old data.

Adding the following lines to .zshrc will remove the limits and deduplication of the history file.

export HISTSIZE=1000000000
export SAVEHIST=$HISTSIZE
setopt EXTENDED_HISTORY

Control Flow

The following is the control flow for generating plots.

  1. Archive all .zsh_history files in data/<server>.zsh_history. ./pull-history-data.sh is a script to partially help archiving the data that will pull files from a list of servers separated by newlines in a file named servers.
  2. Run ./analyze.py to analyze the raw data files. ./analyze.py --help will provide a help menu with the supported options.
  3. Run ./plot.r to generate plots from the analyzed data.

Sample Results

Command Frequencies

At a given hour or weekday, how frequently do I run commands? The following shows the average number of commands executed for each hour and weekday. I average 10 commands per hour overnight and a little more during the day, and Wednesdays seem to be my least productive days.

Many hours have 0 commands executed since I'm not typing commands every hour of every day, so these points have a high standard deviation. Empirical Cumulative Distribution Functions (ECDF's) provide a deeper visualization of the distributions.

Average command length

What command was over 100 characters!? analyze.py will output the top five commands, and these long commands are from using the full path to an executable, such as the Android ARM cross compiler, as shown in the following output.

$ ./analyze.py commandLengths
  105: /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc

Scoping into the majority of the data shows that almost 50% of my commands are one or two characters.

Top Commands

Since almost 50% of my commands are one or two characters, what are the top commands? The following plot shows the top commands are Linux utilities and oh-my-zsh aliases.

My Undergrad vs Grad Student Frequencies

More Repositories

1

dcgan-completion.tensorflow

Image Completion with Deep Learning in TensorFlow
Python
1,308
star
2

densenet.pytorch

A PyTorch implementation of DenseNet.
Python
817
star
3

cv

TeX
397
star
4

latex-templates

Website for personal collection and previewing of LaTeX templates. Presented with Python/Jinja2.
TeX
364
star
5

thesis

Differentiable Optimization-Based Modeling for Machine Learning
TeX
311
star
6

block

An intelligent block matrix library for numpy, PyTorch, and beyond.
Python
294
star
7

dotfiles

♥ Linux, xmonad, emacs, vim, zsh, tmux
Shell
237
star
8

python-scripts

Short and fun Python scripts.
Python
197
star
9

reading-list

My reading list.
CSS
188
star
10

presentations

TeX
124
star
11

beamer-snippets

Website for personal collection and previewing of Beamer and TikZ snippets. Presented with Python/Jinja2.
TeX
109
star
12

setGPU

Small Python library to automatically set CUDA_VISIBLE_DEVICES to the least loaded device on multi-GPU systems.
Python
106
star
13

parsec-benchmark

An unofficial mirror of the core PARSEC 3.0 benchmark suite with patches to run on x86_64 Arch Linux and generalize builds.
C
93
star
14

conference-tracker

Minimal-maintenance conference tracker.
Python
71
star
15

girl

Check your GitHub READMEs for broken links.
Scala
70
star
16

bamos.github.io

JavaScript
34
star
17

snowglobe

Haskell-driven, small-scale web analytics with minimal configuration.
Haskell
27
star
18

ecos.torch

Unofficial Torch ECOS bindings to solve linear programs (LPs) and second-order cone programs (SOCPs).
C
16
star
19

gurobi.torch

Unofficial Gurobi Torch bindings.
Lua
9
star
20

shell-scripts

Miscellaneous short shell scripts.
Shell
9
star
21

github-wiki-link-validator

Ensure all links in a Github Wiki point to valid locations within the Wiki.
Python
5
star
22

docker-llvm-polly-pocl

Build LLVM, Polly, and PoCL in an Ubuntu 12.04 Docker container.
Shell
4
star