diff --git a/README.md b/README.md index 22d9080..da7063e 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,7 @@ apk add hs9001 Add this to .bashrc ``` -if [ -n "$PS1" ] ; then - PROMPT_COMMAND='hs9001 add -ret $? "$(history 1)"' -fi +eval "$(hs9001 bash-enable)" ``` 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. diff --git a/main.go b/main.go index 51a2db7..a726e4d 100644 --- a/main.go +++ b/main.go @@ -234,7 +234,7 @@ func exists(path string) (bool, error) { } func printUsage() { - fmt.Fprintf(os.Stderr, "Usage: ./hs9001 \n") + fmt.Fprintf(os.Stderr, "Usage: ./hs9001 \n") } func main() { @@ -266,8 +266,14 @@ func main() { migrateDatabase(conn, fetchDBVersion(conn)) switch cmd { - case "nolog": - fmt.Printf("Run this command to disable logging for the current shell:\n\tunset PROMPT_COMMAND\n") + 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": var ret int addCmd.IntVar(&ret, "ret", 0, "Return value of the command to add")