shellhist

package
v0.0.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package shellhist reads the commands a shell kept in its history file: bash's, zsh's, fish's, a plain sh's and PowerShell's (PSReadLine), with the time each ran where the file records it.

Index

Constants

View Source
const (
	Bash       = "bash"
	Zsh        = "zsh"
	Fish       = "fish"
	Sh         = "sh"
	PowerShell = "pwsh"
)

The shells whose history files are read.

View Source
const (
	TailBytes  = 512 << 10
	MaxEntries = 5000
)

TailBytes is how much of the end of a history file is read; MaxEntries how many different commands a history keeps at most, the newest.

Variables

This section is empty.

Functions

func LoginShell

func LoginShell(path string) string

LoginShell names the shell of a login shell's path, "" for none known.

Types

type Candidate

type Candidate struct {
	Shell string
	Path  string
}

Candidate is a history file a shell may keep, under the home folder.

func LocalCandidates

func LocalCandidates(goos, home string, getenv func(string) string) []Candidate

LocalCandidates are the history files of this computer's user: on goos with home, $ZDOTDIR, $XDG_DATA_HOME and %APPDATA% as getenv has them.

type Entry

type Entry struct {
	Cmd   string
	At    time.Time
	Shell string
	Count int
}

Entry is a command of the history: the newest time it ran (zero when its file keeps none), the shell of its file, and how many times the part read holds it.

func Parse

func Parse(shell string, data []byte, cut bool) []Entry

Parse is the commands of a history file of shell, in the file's order; cut drops its first line, a part of a command.

type File

type File struct {
	Shell string
	Data  []byte
	Cut   bool
}

File is the end of a history file as read: its shell, its bytes, and whether its start was cut, which leaves its first line a part.

type History

type History struct {
	Entries []Entry
	Shells  []string
	Login   string
}

History is what a host's history files hold, the newest command first, and the login shell of its user ("" when unknown).

func Merge

func Merge(files []File, max int) History

Merge is the commands of files, the newest first, each once: where it ran last, with how many times it ran. A command of a file without times takes the time of the last timed one before it in its file, so that the order of each file stays; one with none sorts after the timed.

func ReadLocal

func ReadLocal(cands []Candidate, login string) History

ReadLocal reads this computer's history files, those of cands there.

func (History) Has

func (h History) Has(shell string) bool

Has reports whether the history holds commands of shell.

func (History) Timed

func (h History) Timed(shell string) bool

Timed reports whether any command of shell ("" any) has a time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL