r

package module
v0.0.0-...-c351418 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0

README

#r Build Status

r stores all successfully executed commands per directory. Allowing you to easily see what command you last executed. You can also sort by most used commands, recently used and see commands from all directories.

Terminal Demo

Requirements

  • OS X / Linux
  • Bash

Installation

Homebrew:

brew tap jesselucas/r

brew install r

Go

  • go get -u github.com/jesselucas/r
  • r -install which will add .r.sh to home directory and source in .bashrc
  • or manually add .r.sh to your .bashrc
    • ex. . $GOPATH/src/github.com/jesselucas/r/.r.sh

Usage

By default r shows bash history per directory and is sorted by last used.

You can see all history by using the -global flag.

Usage of r:
  -install
    installs r.sh to .bashrc
  -global
    show all commands stored by r
  -g
    show all commands stored by r (shorthand)
  -u	sort commands by usage rather than last used (shorthand)
  -usage
    sort commands by usage rather than last used

Example

  • Type r in any directory and it will prompt r>.
  • Press tab key to see all history.
  • Or start typing command and press tab to filter history.
  • Use tab or arrow keys to navigate history items.

Notes

  • Set the Directory and Global history in your .bashrc
# r settings
export R_DIRHISTORY=30 # total to save for directory history
export R_GLOBALHISTORY=100 # total to save for global history
# export R_SORTBYUSAGE=1 # turn this on to default sorting by usage

TODOs

  • Write test!
  • Make history limit an environment variable
  • Create flag to see history for all directories
  • Create flag to sort by most used rather than the default last used.
  • Create brew formula
  • Improve stability of .r.sh
  • Make compatible with zsh

Special Thanks

Documentation

Index

Constants

View Source
const (

	// Version is semantic version for package r and cmd/r
	Version = "0.4.4"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name string
	Info *CommandInfo
}

Command struct stores the name and CommandInfo for each shell command stored in the r database

type CommandInfo

type CommandInfo struct {
	Time  time.Time
	Count int
}

CommandInfo struct is stored as the value to commands

func (*CommandInfo) NewFromString

func (ci *CommandInfo) NewFromString(ciString string) *CommandInfo

NewFromString creates a new CommandInfo struct from a string

func (*CommandInfo) String

func (ci *CommandInfo) String() string

func (*CommandInfo) Update

func (ci *CommandInfo) Update(ciString string)

Update method will update the time and count of CommandInfo

type Session

type Session struct {
	// Path to store and reference boltdb
	BoltPath string
	// Used to store the bool value from the r cmd global flag
	Global bool
	// SortUsagePtr used to check if the usage flag was used
	SortUsage bool
	// SortTimePtr used to check if the time flag was used
	SortTime bool
}

Session is created every time r cmd is ran

func (*Session) Add

func (s *Session) Add(path string, promptCmd string) error

Add checks if command being passed is in the listCommands then stores the command and workding directory

func (*Session) CheckForHistory

func (s *Session) CheckForHistory() error

CheckForHistory makes sure a directory has history or if the global bool is true it will make sure the global bucket has a history

func (*Session) PrintLastCommand

func (s *Session) PrintLastCommand() error

PrintLastCommand is used with the r cli --command flag it shows the last command selected from the readline prompt

func (*Session) Prune

func (s *Session) Prune(path string) error

Prune deletes commands from a directory bucket and overall bucket

func (*Session) ResetLastCommand

func (s *Session) ResetLastCommand() error

ResetLastCommand clears the value in the lastCommandBucket

func (*Session) ResultsDirectory

func (s *Session) ResultsDirectory(path string) ([]*Command, error)

ResultsDirectory reads the boltdb and returns the command history based on your current working directory

func (*Session) ResultsGlobal

func (s *Session) ResultsGlobal() ([]*Command, error)

ResultsGlobal returns all the results for the global commands bucket

func (*Session) StoreLastCommand

func (s *Session) StoreLastCommand(line string) error

StoreLastCommand takes the line string and stores it

Directories

Path Synopsis
cmd
r

Jump to

Keyboard shortcuts

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