Explorar el Código

Add basic comments

Edvinas Valatka hace 10 años
padre
commit
b77e13de76
Se han modificado 1 ficheros con 9 adiciones y 0 borrados
  1. 9 0
      main.go

+ 9 - 0
main.go

@@ -7,10 +7,13 @@ import (
 	"strings"
 )
 
+// map for old history records
 var history = make(map[string]int)
 
+// path ${HOME}/.bash_history
 var h Hfile
 
+// path /tmp/.bash_history******/.bash_history
 var t Tmpfile
 
 func init() {
@@ -24,6 +27,7 @@ func init() {
 }
 
 func main() {
+	//read old history
 	scanner := bufio.NewScanner(h.handle)
 	var i = 0
 	for scanner.Scan() {
@@ -34,11 +38,14 @@ func main() {
 	delete(history, "")
 	h.handle.Close()
 
+	// push history to temp slice
+	// and sort by last entry position number
 	var ah = make([]string, i)
 	for key, val := range history {
 		ah[val] = key
 	}
 
+	// write not empty lines to temp file
 	i = 0
 	for _, key := range ah {
 		if len(key) > 0 {
@@ -48,11 +55,13 @@ func main() {
 	}
 	t.handle.Close()
 
+	//copy from temp file to home
 	_, err := CopyFile(t.path, h.path)
 	if err != nil {
 		fmt.Println(err)
 	}
 
+	//finnaly remove temp folder
 	err = os.RemoveAll(t.dir)
 	if err != nil {
 		fmt.Print(err)