1
0
Fork 0
master
Philip O'Toole 2 years ago
parent 5e6f46ca99
commit 33d754a2bc

@ -10,6 +10,7 @@ import (
const historyFile = ".rqlite_history"
// Reader returns a reader of the history file.
func Reader() io.ReadCloser {
hdir, err := os.UserHomeDir()
if err != nil {
@ -23,6 +24,7 @@ func Reader() io.ReadCloser {
return f
}
// Writer returns a writer for the history file.
func Writer() io.WriteCloser {
hdir, err := os.UserHomeDir()
if err != nil {

@ -23,6 +23,7 @@ func setHidden(path string) error {
return nil
}
// Reader returns a reader of the history file.
func Reader() io.ReadCloser {
hdir, err := os.UserHomeDir()
if err != nil {
@ -36,6 +37,7 @@ func Reader() io.ReadCloser {
return f
}
// Writer returns a writer for the history file.
func Writer() io.WriteCloser {
hdir, err := os.UserHomeDir()
if err != nil {

@ -10,6 +10,7 @@ import (
const MaxHistSize = 100
// Size returns the max number of commands that should be stored in history.
func Size() int {
maxSize := MaxHistSize
maxSizeStr := os.Getenv("RQLITE_HISTFILESIZE")
@ -22,6 +23,7 @@ func Size() int {
return maxSize
}
// Dedupe returns a copy of the slice with contigous dupes removed.
func Dedupe(s []string) []string {
if s == nil {
return nil
@ -36,6 +38,8 @@ func Dedupe(s []string) []string {
return o
}
// Filter returns a copy of the slice with empty and whitespace-only elements
// removed.
func Filter(s []string) []string {
if s == nil {
return nil
@ -50,6 +54,7 @@ func Filter(s []string) []string {
return o
}
// Read reads the command history from the reader.
func Read(r io.Reader) ([]string, error) {
if r == nil {
return nil, nil
@ -64,6 +69,7 @@ func Read(r io.Reader) ([]string, error) {
return Filter(cmds), scanner.Err()
}
// Write writes the command history to the writer.
func Write(j []string, maxSz int, w io.Writer) error {
if len(j) == 0 {
return nil

Loading…
Cancel
Save