// Save a readline history file. // The default filename is ~/.history. func WriteHistoryFile(s string) error { p := C.CString(s) defer C.free(unsafe.Pointer(p)) errno := C.write_history(p) if errno == 0 && HistoryLength >= 0 { errno = C.history_truncate_file(p, C.int(HistoryLength)) } if errno == 0 { return nil } return syscall.Errno(errno) }
// TruncateHistoryFile truncates the history file filename, leaving only the last nlines lines. // If filename is "", then `~/.history' is truncated. // (See history_truncate_file http://cnswww.cns.cwru.edu/php/chet/readline/history.html#IDX31) func TruncateHistoryFile(filename string, nlines int32) error { var cfilename *C.char if len(filename) != 0 { cfilename = C.CString(filename) } err := C.history_truncate_file(cfilename, C.int(nlines)) if cfilename != nil { C.free(unsafe.Pointer(cfilename)) } if err != 0 { return syscall.Errno(err) } return nil }
func TruncateHistoryFile(fileName string, left int) { cFileName := C.CString(fileName) cLeft := C.int(left) C.history_truncate_file(cFileName, cLeft) C.free(unsafe.Pointer(cFileName)) }