mirror of
				https://github.com/quitesimpleorg/hs9001.git
				synced 2025-11-04 01:19:29 +01:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			v0.5
			...
			WIP/sane_t
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ac9aab63bd | |||
| d0e07640e8 | 
							
								
								
									
										13
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								README.md
									
									
									
									
									
								
							@@ -20,12 +20,13 @@ hs -cwd .
 | 
				
			|||||||
Lists all commands ever entered in this directory
 | 
					Lists all commands ever entered in this directory
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
hs -after yesterday -cwd . git
 | 
					hs -today -cwd . git
 | 
				
			||||||
``` 
 | 
					``` 
 | 
				
			||||||
Lists all git commands in the current directory which have been entered today.
 | 
					Lists all git commands in the current directory which have been entered today.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Also, it (by default) replaces bash's built-in CTRL-R mechanism, so hs9001's database will be used instead
 | 
					Also, it (by default) replaces bash's built-in CTRL-R mechanism, so hs9001's database will be used instead of bash's limited history files.
 | 
				
			||||||
of bash's limited history files. 
 | 
					
 | 
				
			||||||
 | 
					When in reverse-search mode, you can only search the history of the current directory by pressing CTRL+A and then "w".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Install
 | 
					## Install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -51,9 +52,6 @@ apk add hs9001
 | 
				
			|||||||
go build
 | 
					go build
 | 
				
			||||||
#move hs9001 to a PATH location
 | 
					#move hs9001 to a PATH location
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					 | 
				
			||||||
## Setup / Config
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Add this to .bashrc
 | 
					Add this to .bashrc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
@@ -62,8 +60,7 @@ eval "$(hs9001 bash-enable)"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
This will also create a `hs`alias so you have to type less in everyday usage.
 | 
					This will also create a `hs`alias so you have to type less in everyday usage.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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.
 | 
					 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
export HS9001_DB_PATH="/home/db/history.sqlite"
 | 
					export HS9001_DB_PATH="/home/db/history.sqlite"
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								main.go
									
									
									
									
									
								
							@@ -66,6 +66,11 @@ func migrateDatabase(conn *sql.DB, currentVersion int) {
 | 
				
			|||||||
	migrations := []string{
 | 
						migrations := []string{
 | 
				
			||||||
		"ALTER TABLE history ADD COLUMN workdir varchar(4096) DEFAULT ''",
 | 
							"ALTER TABLE history ADD COLUMN workdir varchar(4096) DEFAULT ''",
 | 
				
			||||||
		"ALTER TABLE history ADD COLUMN retval integer DEFAULT -9001",
 | 
							"ALTER TABLE history ADD COLUMN retval integer DEFAULT -9001",
 | 
				
			||||||
 | 
							"ALTER TABLE history ADD COLUMN unix_tmp integer",
 | 
				
			||||||
 | 
							"UPDATE history SET unix_tmp = strftime('%s', timestamp)",
 | 
				
			||||||
 | 
							"DROP VIEW count_by_date",
 | 
				
			||||||
 | 
							"ALTER TABLE history DROP COLUMN timestamp",
 | 
				
			||||||
 | 
							"ALTER TABLE history RENAME COLUMN unix_tmp TO timestamp",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !(len(migrations) > currentVersion) {
 | 
						if !(len(migrations) > currentVersion) {
 | 
				
			||||||
@@ -164,7 +169,7 @@ type searchopts struct {
 | 
				
			|||||||
func search(conn *sql.DB, opts searchopts) list.List {
 | 
					func search(conn *sql.DB, opts searchopts) list.List {
 | 
				
			||||||
	args := make([]interface{}, 0)
 | 
						args := make([]interface{}, 0)
 | 
				
			||||||
	var sb strings.Builder
 | 
						var sb strings.Builder
 | 
				
			||||||
	sb.WriteString("SELECT id, command, workdir, user, hostname, retval, strftime(\"%s\", timestamp) ")
 | 
						sb.WriteString("SELECT id, command, workdir, user, hostname, retval, timestamp ")
 | 
				
			||||||
	sb.WriteString("FROM history ")
 | 
						sb.WriteString("FROM history ")
 | 
				
			||||||
	sb.WriteString("WHERE 1=1 ") //1=1 so we can append as many AND foo as we want, or none
 | 
						sb.WriteString("WHERE 1=1 ") //1=1 so we can append as many AND foo as we want, or none
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -177,11 +182,11 @@ func search(conn *sql.DB, opts searchopts) list.List {
 | 
				
			|||||||
		args = append(args, opts.workdir)
 | 
							args = append(args, opts.workdir)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if opts.after != nil {
 | 
						if opts.after != nil {
 | 
				
			||||||
		sb.WriteString("AND timestamp > datetime(?, 'unixepoch') ")
 | 
							sb.WriteString("AND timestamp > ? ")
 | 
				
			||||||
		args = append(args, opts.after.Unix())
 | 
							args = append(args, opts.after.Unix())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if opts.before != nil {
 | 
						if opts.before != nil {
 | 
				
			||||||
		sb.WriteString("AND timestamp < datetime(?, 'unixepoch') ")
 | 
							sb.WriteString("AND timestamp < ? ")
 | 
				
			||||||
		args = append(args, opts.before.Unix())
 | 
							args = append(args, opts.before.Unix())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if opts.retval != nil {
 | 
						if opts.retval != nil {
 | 
				
			||||||
@@ -234,7 +239,7 @@ func delete(conn *sql.DB, entryId uint32) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func add(conn *sql.DB, entry HistoryEntry) {
 | 
					func add(conn *sql.DB, entry HistoryEntry) {
 | 
				
			||||||
	stmt, err := conn.Prepare("INSERT INTO history (user, command, hostname, workdir, timestamp, retval) VALUES (?, ?, ?, ?, datetime(?, 'unixepoch'),?)")
 | 
						stmt, err := conn.Prepare("INSERT INTO history (user, command, hostname, workdir, timestamp, retval) VALUES (?, ?, ?, ?, ?,?)")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Panic(err)
 | 
							log.Panic(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user