mirror of
				https://github.com/quitesimpleorg/hs9001.git
				synced 2025-11-04 01:19:29 +01:00 
			
		
		
		
	Compare commits
	
		
			6 Commits
		
	
	
		
			v0.3
			...
			a8f35951f1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					a8f35951f1 | ||
| 
						 | 
					b9e3a3629b | ||
| 
						 | 
					16752411e1 | ||
| 
						 | 
					c480519fca | ||
| 
						 | 
					70e66f47ba | ||
| 216e59747c | 
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					GIT_COMMIT=$(shell git rev-list -1 HEAD)
 | 
				
			||||||
 | 
					GIT_TAG=$(shell git tag --sort="-version:refname" | head -n 1)
 | 
				
			||||||
 | 
					all:
 | 
				
			||||||
 | 
						go build -ldflags "-X main.GitCommit=${GIT_COMMIT} -X main.GitTag=${GIT_TAG}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -34,9 +34,7 @@ apk add hs9001
 | 
				
			|||||||
Add this to .bashrc
 | 
					Add this to .bashrc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
if [ -n "$PS1" ] ; then
 | 
					eval "$(hs9001 bash-enable)"
 | 
				
			||||||
    PROMPT_COMMAND='hs9001 add -ret $? "$(history 1)"'
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
By default, every system user gets his own database. You can override this by setting the environment variable
 | 
					By default, every system user gets his own database. You can override this by setting the environment variable
 | 
				
			||||||
for all users that should write to your unified database.
 | 
					for all users that should write to your unified database.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								main.go
									
									
									
									
									
								
							@@ -27,6 +27,9 @@ type HistoryEntry struct {
 | 
				
			|||||||
	timestamp time.Time
 | 
						timestamp time.Time
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var GitTag string
 | 
				
			||||||
 | 
					var GitCommit string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func databaseLocation() string {
 | 
					func databaseLocation() string {
 | 
				
			||||||
	envOverride := os.Getenv("HS9001_DB_PATH")
 | 
						envOverride := os.Getenv("HS9001_DB_PATH")
 | 
				
			||||||
	if envOverride != "" {
 | 
						if envOverride != "" {
 | 
				
			||||||
@@ -231,7 +234,7 @@ func exists(path string) (bool, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func printUsage() {
 | 
					func printUsage() {
 | 
				
			||||||
	fmt.Fprintf(os.Stderr, "Usage:   ./hs9001 <add/search/import>\n")
 | 
						fmt.Fprintf(os.Stderr, "Usage:   ./hs9001 <add/search/import/nolog/bash-enable>\n")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
@@ -263,6 +266,14 @@ func main() {
 | 
				
			|||||||
	migrateDatabase(conn, fetchDBVersion(conn))
 | 
						migrateDatabase(conn, fetchDBVersion(conn))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch cmd {
 | 
						switch cmd {
 | 
				
			||||||
 | 
						case "bash-enable":
 | 
				
			||||||
 | 
							fmt.Printf(`
 | 
				
			||||||
 | 
								if [ -n "$PS1" ] ; then
 | 
				
			||||||
 | 
									PROMPT_COMMAND='hs9001 add -ret $? "$(history 1)"'
 | 
				
			||||||
 | 
								fi
 | 
				
			||||||
 | 
							`)
 | 
				
			||||||
 | 
						case "bash-disable":
 | 
				
			||||||
 | 
							fmt.Printf("unset PROMPT_COMMAND\n")
 | 
				
			||||||
	case "add":
 | 
						case "add":
 | 
				
			||||||
		var ret int
 | 
							var ret int
 | 
				
			||||||
		addCmd.IntVar(&ret, "ret", 0, "Return value of the command to add")
 | 
							addCmd.IntVar(&ret, "ret", 0, "Return value of the command to add")
 | 
				
			||||||
@@ -277,7 +288,7 @@ func main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		historycmd := args[0]
 | 
							historycmd := args[0]
 | 
				
			||||||
		var rgx = regexp.MustCompile("\\s+\\d+\\s+(.*)")
 | 
							var rgx = regexp.MustCompile(`\s+\d+\s+(.*)`)
 | 
				
			||||||
		rs := rgx.FindStringSubmatch(historycmd)
 | 
							rs := rgx.FindStringSubmatch(historycmd)
 | 
				
			||||||
		if len(rs) == 2 {
 | 
							if len(rs) == 2 {
 | 
				
			||||||
			add(conn, NewHistoryEntry(rs[1], ret))
 | 
								add(conn, NewHistoryEntry(rs[1], ret))
 | 
				
			||||||
@@ -290,7 +301,7 @@ func main() {
 | 
				
			|||||||
		var endTime string
 | 
							var endTime string
 | 
				
			||||||
		var distinct bool = true
 | 
							var distinct bool = true
 | 
				
			||||||
		var retVal int
 | 
							var retVal int
 | 
				
			||||||
		searchCmd.StringVar(&workDir, "workdir", "%", "Search only within this workdir")
 | 
							searchCmd.StringVar(&workDir, "cwd", "%", "Search only within this workdir")
 | 
				
			||||||
		searchCmd.StringVar(&beginTime, "begin", "50 years ago", "Start searching from this timeframe")
 | 
							searchCmd.StringVar(&beginTime, "begin", "50 years ago", "Start searching from this timeframe")
 | 
				
			||||||
		searchCmd.StringVar(&endTime, "end", "now", "End searching from this timeframe")
 | 
							searchCmd.StringVar(&endTime, "end", "now", "End searching from this timeframe")
 | 
				
			||||||
		searchCmd.BoolVar(&distinct, "distinct", true, "Remove consecutive duplicate commands from output")
 | 
							searchCmd.BoolVar(&distinct, "distinct", true, "Remove consecutive duplicate commands from output")
 | 
				
			||||||
@@ -311,6 +322,13 @@ func main() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		q := strings.Join(args, " ")
 | 
							q := strings.Join(args, " ")
 | 
				
			||||||
 | 
							if workDir != "%" {
 | 
				
			||||||
 | 
								workDir, err = filepath.Abs(workDir)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									fmt.Fprintf(os.Stderr, "Failed parse working directory path: %s\n", err.Error())
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		results := search(conn, "%"+q+"%", workDir, beginTimestamp, endTimeStamp, retVal)
 | 
							results := search(conn, "%"+q+"%", workDir, beginTimestamp, endTimeStamp, retVal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		previousCmd := ""
 | 
							previousCmd := ""
 | 
				
			||||||
@@ -354,6 +372,8 @@ func main() {
 | 
				
			|||||||
		os.Exit(23)
 | 
							os.Exit(23)
 | 
				
			||||||
	case "import":
 | 
						case "import":
 | 
				
			||||||
		importFromStdin(conn)
 | 
							importFromStdin(conn)
 | 
				
			||||||
 | 
						case "version":
 | 
				
			||||||
 | 
							fmt.Fprintf(os.Stdout, "Git Tag: %s\nGit Commit: %s\n", GitTag, GitCommit)
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		fmt.Fprintf(os.Stderr, "Error: Unknown subcommand '%s' supplied\n\n", cmd)
 | 
							fmt.Fprintf(os.Stderr, "Error: Unknown subcommand '%s' supplied\n\n", cmd)
 | 
				
			||||||
		printUsage()
 | 
							printUsage()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user