mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-19 11:36:47 +02:00
Add initial cobra implementation for config-*
This commit is contained in:
parent
49a1035169
commit
342a02a843
@ -76,7 +76,7 @@ hishtory config-set displayed-columns CWD Command
|
|||||||
You can create custom column definitions that are populated from arbitrary commands. For example, if you want to create a new column named `git_remote` that contains the git remote if the cwd is in a git directory, you can run:
|
You can create custom column definitions that are populated from arbitrary commands. For example, if you want to create a new column named `git_remote` that contains the git remote if the cwd is in a git directory, you can run:
|
||||||
|
|
||||||
```
|
```
|
||||||
hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'
|
hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'
|
||||||
hishtory config-add displayed-columns git_remote
|
hishtory config-add displayed-columns git_remote
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
@ -1641,17 +1641,17 @@ func testConfigGetSet(t *testing.T, tester shellTester) {
|
|||||||
|
|
||||||
// Config-get and set for enable-control-r
|
// Config-get and set for enable-control-r
|
||||||
out := tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
out := tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
||||||
if out != "true" {
|
if out != "true\n" {
|
||||||
t.Fatalf("unexpected config-get output: %#v", out)
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
}
|
}
|
||||||
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r false`)
|
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r false`)
|
||||||
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
||||||
if out != "false" {
|
if out != "false\n" {
|
||||||
t.Fatalf("unexpected config-get output: %#v", out)
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
}
|
}
|
||||||
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r true`)
|
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r true`)
|
||||||
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
||||||
if out != "true" {
|
if out != "true\n" {
|
||||||
t.Fatalf("unexpected config-get output: %#v", out)
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2073,7 +2073,7 @@ echo baz`)
|
|||||||
compareGoldens(t, out, "testCustomColumns-initHistory")
|
compareGoldens(t, out, "testCustomColumns-initHistory")
|
||||||
|
|
||||||
// Configure a custom column
|
// Configure a custom column
|
||||||
tester.RunInteractiveShell(t, `hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'`)
|
tester.RunInteractiveShell(t, `hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'`)
|
||||||
|
|
||||||
// Run a few commands, some of which will have a git_remote
|
// Run a few commands, some of which will have a git_remote
|
||||||
out = tester.RunInteractiveShell(t, `echo foo
|
out = tester.RunInteractiveShell(t, `echo foo
|
||||||
|
51
client/cmd/configAdd.go
Normal file
51
client/cmd/configAdd.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
|
"github.com/ddworken/hishtory/client/lib"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configAddCmd = &cobra.Command{
|
||||||
|
Use: "config-add",
|
||||||
|
Short: "Add a config option",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var addCustomColumnsCmd = &cobra.Command{
|
||||||
|
Use: "custom-columns",
|
||||||
|
Short: "Add a custom column",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
columnName := args[0]
|
||||||
|
command := args[1]
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
if config.CustomColumns == nil {
|
||||||
|
config.CustomColumns = make([]hctx.CustomColumnDefinition, 0)
|
||||||
|
}
|
||||||
|
config.CustomColumns = append(config.CustomColumns, hctx.CustomColumnDefinition{ColumnName: columnName, ColumnCommand: command})
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var addDisplayedColumnsCmd = &cobra.Command{
|
||||||
|
Use: "displayed-columns",
|
||||||
|
Short: "Add a column to be displayed",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
vals := args
|
||||||
|
config.DisplayedColumns = append(config.DisplayedColumns, vals...)
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(configAddCmd)
|
||||||
|
configAddCmd.AddCommand(addCustomColumnsCmd)
|
||||||
|
configAddCmd.AddCommand(addDisplayedColumnsCmd)
|
||||||
|
}
|
73
client/cmd/configDelete.go
Normal file
73
client/cmd/configDelete.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
|
"github.com/ddworken/hishtory/client/lib"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configDeleteCmd = &cobra.Command{
|
||||||
|
Use: "config-delete",
|
||||||
|
Short: "Delete a config option",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var deleteCustomColumnsCmd = &cobra.Command{
|
||||||
|
Use: "custom-columns",
|
||||||
|
Short: "Delete a custom column",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
columnName := args[0]
|
||||||
|
if config.CustomColumns == nil {
|
||||||
|
log.Fatalf("Did not find a column with name %#v to delete (current columns = %#v)", columnName, config.CustomColumns)
|
||||||
|
}
|
||||||
|
newColumns := make([]hctx.CustomColumnDefinition, 0)
|
||||||
|
deletedColumns := false
|
||||||
|
for _, c := range config.CustomColumns {
|
||||||
|
if c.ColumnName != columnName {
|
||||||
|
newColumns = append(newColumns, c)
|
||||||
|
deletedColumns = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !deletedColumns {
|
||||||
|
log.Fatalf("Did not find a column with name %#v to delete (current columns = %#v)", columnName, config.CustomColumns)
|
||||||
|
}
|
||||||
|
config.CustomColumns = newColumns
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
var deleteDisplayedColumnCommand = &cobra.Command{
|
||||||
|
Use: "displayed-columns",
|
||||||
|
Short: "Delete a displayed column",
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
deletedColumns := args
|
||||||
|
newColumns := make([]string, 0)
|
||||||
|
for _, c := range config.DisplayedColumns {
|
||||||
|
isDeleted := false
|
||||||
|
for _, d := range deletedColumns {
|
||||||
|
if c == d {
|
||||||
|
isDeleted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isDeleted {
|
||||||
|
newColumns = append(newColumns, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.DisplayedColumns = newColumns
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(configDeleteCmd)
|
||||||
|
configDeleteCmd.AddCommand(deleteCustomColumnsCmd)
|
||||||
|
}
|
86
client/cmd/configGet.go
Normal file
86
client/cmd/configGet.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configGetCmd = &cobra.Command{
|
||||||
|
Use: "config-get",
|
||||||
|
Short: "Get the value of a config option",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var getEnableControlRCmd = &cobra.Command{
|
||||||
|
Use: "enable-control-r",
|
||||||
|
Short: "Whether hishtory replaces your shell's default control-r",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
fmt.Println(config.ControlRSearchEnabled)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var getFilterDuplicateCommandsCmd = &cobra.Command{
|
||||||
|
Use: "filter-duplicate-commands",
|
||||||
|
Short: "Whether hishtory filters out duplicate commands when displaying your history",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
fmt.Println(config.FilterDuplicateCommands)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var getDisplayedColumnsCmd = &cobra.Command{
|
||||||
|
Use: "displayed-columns",
|
||||||
|
Short: "The list of columns that hishtory displays",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
for _, col := range config.DisplayedColumns {
|
||||||
|
if strings.Contains(col, " ") {
|
||||||
|
fmt.Printf("%q ", col)
|
||||||
|
} else {
|
||||||
|
fmt.Print(col + " ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Print("\n")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var getTimestampFormatCmd = &cobra.Command{
|
||||||
|
Use: "timestamp-format",
|
||||||
|
Short: "The go format string to use for formatting the timestamp",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
fmt.Println(config.TimestampFormat)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var getCustomColumnsCmd = &cobra.Command{
|
||||||
|
Use: "custom-columns",
|
||||||
|
Short: "The list of custom columns that hishtory is tracking",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
for _, cc := range config.CustomColumns {
|
||||||
|
fmt.Println(cc.ColumnName + ": " + cc.ColumnCommand)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(configGetCmd)
|
||||||
|
configGetCmd.AddCommand(getEnableControlRCmd)
|
||||||
|
configGetCmd.AddCommand(getFilterDuplicateCommandsCmd)
|
||||||
|
configGetCmd.AddCommand(getDisplayedColumnsCmd)
|
||||||
|
configGetCmd.AddCommand(getTimestampFormatCmd)
|
||||||
|
configGetCmd.AddCommand(getCustomColumnsCmd)
|
||||||
|
}
|
92
client/cmd/configSet.go
Normal file
92
client/cmd/configSet.go
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
|
"github.com/ddworken/hishtory/client/lib"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configSetCmd = &cobra.Command{
|
||||||
|
Use: "config-set",
|
||||||
|
Short: "Set the value of a config option",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var setEnableControlRCmd = &cobra.Command{
|
||||||
|
Use: "enable-control-r",
|
||||||
|
Short: "Whether hishtory replaces your shell's default control-r",
|
||||||
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||||
|
ValidArgs: []string{"true", "false"},
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
val := args[0]
|
||||||
|
if val != "true" && val != "false" {
|
||||||
|
log.Fatalf("Unexpected config value %s, must be one of: true, false", val)
|
||||||
|
}
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
config.ControlRSearchEnabled = (val == "true")
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var setFilterDuplicateCommandsCmd = &cobra.Command{
|
||||||
|
Use: "filter-duplicate-commands",
|
||||||
|
Short: "Whether hishtory filters out duplicate commands when displaying your history",
|
||||||
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||||
|
ValidArgs: []string{"true", "false"},
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
val := args[0]
|
||||||
|
if val != "true" && val != "false" {
|
||||||
|
log.Fatalf("Unexpected config value %s, must be one of: true, false", val)
|
||||||
|
}
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
config.FilterDuplicateCommands = (val == "true")
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var setDisplayedColumnsCmd = &cobra.Command{
|
||||||
|
Use: "displayed-columns",
|
||||||
|
Short: "The list of columns that hishtory displays",
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
config.DisplayedColumns = args
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var setTimestampFormatCmd = &cobra.Command{
|
||||||
|
Use: "timestamp-format",
|
||||||
|
Short: "The go format string to use for formatting the timestamp",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
config.TimestampFormat = args[0]
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var setCustomColumnsCmd = &cobra.Command{
|
||||||
|
Use: "custom-columns",
|
||||||
|
Short: "The list of custom columns that hishtory is tracking",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
log.Fatalf("Please use config-add and config-delete to interact with custom-columns")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(configSetCmd)
|
||||||
|
configSetCmd.AddCommand(setEnableControlRCmd)
|
||||||
|
configSetCmd.AddCommand(setFilterDuplicateCommandsCmd)
|
||||||
|
configSetCmd.AddCommand(setDisplayedColumnsCmd)
|
||||||
|
configSetCmd.AddCommand(setTimestampFormatCmd)
|
||||||
|
configSetCmd.AddCommand(setCustomColumnsCmd)
|
||||||
|
}
|
51
client/cmd/root.go
Normal file
51
client/cmd/root.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||||
|
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// rootCmd represents the base command when called without any subcommands
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "client",
|
||||||
|
Short: "A brief description of your application",
|
||||||
|
Long: `A longer description that spans multiple lines and likely contains
|
||||||
|
examples and usage of using your application. For example:
|
||||||
|
|
||||||
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
|
This application is a tool to generate the needed files
|
||||||
|
to quickly create a Cobra application.`,
|
||||||
|
// Uncomment the following line if your bare application
|
||||||
|
// has an action associated with it:
|
||||||
|
// Run: func(cmd *cobra.Command, args []string) { },
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
|
func Execute() {
|
||||||
|
err := rootCmd.Execute()
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Here you will define your flags and configuration settings.
|
||||||
|
// Cobra supports persistent flags, which, if defined here,
|
||||||
|
// will be global for your application.
|
||||||
|
|
||||||
|
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.client.yaml)")
|
||||||
|
|
||||||
|
// Cobra also supports local flags, which will only run
|
||||||
|
// when this action is called directly.
|
||||||
|
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
Exit Code git_remote Command
|
Exit Code git_remote Command
|
||||||
0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command
|
0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command
|
||||||
0 echo bar
|
0 echo bar
|
||||||
0 cd /
|
0 cd /
|
||||||
0 git@github.com:ddworken/hishtory.git echo foo
|
0 git@github.com:ddworken/hishtory.git echo foo
|
||||||
0 git@github.com:ddworken/hishtory.git hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'
|
0 git@github.com:ddworken/hishtory.git hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'
|
||||||
0 echo baz
|
0 echo baz
|
||||||
0 cd /
|
0 cd /
|
||||||
0 echo $FOOBAR world
|
0 echo $FOOBAR world
|
||||||
0 export FOOBAR='hello'
|
0 export FOOBAR='hello'
|
||||||
|
@ -3,7 +3,7 @@ Exit Code git_remote Command
|
|||||||
0 echo bar
|
0 echo bar
|
||||||
0 cd /
|
0 cd /
|
||||||
0 https://github.com/ddworken/hishtory echo foo
|
0 https://github.com/ddworken/hishtory echo foo
|
||||||
0 https://github.com/ddworken/hishtory hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'
|
0 https://github.com/ddworken/hishtory hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'
|
||||||
0 echo baz
|
0 echo baz
|
||||||
0 cd /
|
0 cd /
|
||||||
0 echo $FOOBAR world
|
0 echo $FOOBAR world
|
||||||
|
@ -5,27 +5,27 @@ bash-5.2$ hishtory tquery -pipefail
|
|||||||
|
|
||||||
Search Query: > -pipefail
|
Search Query: > -pipefail
|
||||||
|
|
||||||
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||||
│ Exit Code git_remote Command │
|
│ Exit Code git_remote Command │
|
||||||
│─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||||
│ 0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command │
|
│ 0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command │
|
||||||
│ 0 echo bar │
|
│ 0 echo bar │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 git@github.com:ddworken/hishtory.git echo foo │
|
│ 0 git@github.com:ddworken/hishtory.git echo foo │
|
||||||
│ 0 git@github.com:ddworken/hishtory.git hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
│ 0 git@github.com:ddworken/hishtory.git hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
||||||
│ 0 echo baz │
|
│ 0 echo baz │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 echo $FOOBAR world │
|
│ 0 echo $FOOBAR world │
|
||||||
│ 0 export FOOBAR='hello' │
|
│ 0 export FOOBAR='hello' │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
@ -12,7 +12,7 @@ Search Query: > -pipefail
|
|||||||
│ 0 echo bar │
|
│ 0 echo bar │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 https://github.com/ddworken/hishtory echo foo │
|
│ 0 https://github.com/ddworken/hishtory echo foo │
|
||||||
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
||||||
│ 0 echo baz │
|
│ 0 echo baz │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 echo $FOOBAR world │
|
│ 0 echo $FOOBAR world │
|
||||||
|
@ -12,7 +12,7 @@ Search Query: > -pipefail
|
|||||||
│ 0 echo bar │
|
│ 0 echo bar │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 https://github.com/ddworken/hishtory echo foo │
|
│ 0 https://github.com/ddworken/hishtory echo foo │
|
||||||
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
||||||
│ 0 echo baz │
|
│ 0 echo baz │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 echo $FOOBAR world │
|
│ 0 echo $FOOBAR world │
|
||||||
|
@ -11,7 +11,7 @@ Search Query: > -pipefail
|
|||||||
│ 0 echo bar │
|
│ 0 echo bar │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 git@github.com:ddworken/hishtory.git echo foo │
|
│ 0 git@github.com:ddworken/hishtory.git echo foo │
|
||||||
│ 0 git@github.com:ddworken/hishtory.git hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
│ 0 git@github.com:ddworken/hishtory.git hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
||||||
│ 0 echo baz │
|
│ 0 echo baz │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 echo $FOOBAR world │
|
│ 0 echo $FOOBAR world │
|
||||||
|
@ -11,7 +11,7 @@ Search Query: > -pipefail
|
|||||||
│ 0 echo bar │
|
│ 0 echo bar │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 https://github.com/ddworken/hishtory echo foo │
|
│ 0 https://github.com/ddworken/hishtory echo foo │
|
||||||
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
||||||
│ 0 echo baz │
|
│ 0 echo baz │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 echo $FOOBAR world │
|
│ 0 echo $FOOBAR world │
|
||||||
|
@ -11,7 +11,7 @@ Search Query: > -pipefail
|
|||||||
│ 0 echo bar │
|
│ 0 echo bar │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 https://github.com/ddworken/hishtory echo foo │
|
│ 0 https://github.com/ddworken/hishtory echo foo │
|
||||||
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
│ 0 https://github.com/ddworken/hishtory hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
||||||
│ 0 echo baz │
|
│ 0 echo baz │
|
||||||
│ 0 cd / │
|
│ 0 cd / │
|
||||||
│ 0 echo $FOOBAR world │
|
│ 0 echo $FOOBAR world │
|
||||||
|
3
go.mod
3
go.mod
@ -38,6 +38,7 @@ require (
|
|||||||
github.com/PaesslerAG/gval v1.0.0 // indirect
|
github.com/PaesslerAG/gval v1.0.0 // indirect
|
||||||
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
|
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
|
||||||
github.com/ThalesIgnite/crypto11 v1.2.5 // indirect
|
github.com/ThalesIgnite/crypto11 v1.2.5 // indirect
|
||||||
|
github.com/alecthomas/kong v0.7.1 // indirect
|
||||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect
|
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect
|
||||||
github.com/alibabacloud-go/cr-20160607 v1.0.1 // indirect
|
github.com/alibabacloud-go/cr-20160607 v1.0.1 // indirect
|
||||||
github.com/alibabacloud-go/cr-20181201 v1.0.10 // indirect
|
github.com/alibabacloud-go/cr-20181201 v1.0.10 // indirect
|
||||||
@ -211,7 +212,7 @@ require (
|
|||||||
github.com/soheilhy/cmux v0.1.5 // indirect
|
github.com/soheilhy/cmux v0.1.5 // indirect
|
||||||
github.com/spf13/afero v1.8.2 // indirect
|
github.com/spf13/afero v1.8.2 // indirect
|
||||||
github.com/spf13/cast v1.5.0 // indirect
|
github.com/spf13/cast v1.5.0 // indirect
|
||||||
github.com/spf13/cobra v1.6.0 // indirect
|
github.com/spf13/cobra v1.6.1 // indirect
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/spf13/viper v1.13.0 // indirect
|
github.com/spf13/viper v1.13.0 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -226,6 +226,8 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/
|
|||||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
||||||
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
|
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
|
||||||
|
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
|
||||||
|
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
@ -1955,6 +1957,8 @@ github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
|||||||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
|
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
|
||||||
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
|
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
|
||||||
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
||||||
|
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
||||||
|
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
||||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
|
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
|
||||||
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
|
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
|
||||||
|
128
hishtory.go
128
hishtory.go
@ -10,6 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ddworken/hishtory/client/cmd"
|
||||||
"github.com/ddworken/hishtory/client/data"
|
"github.com/ddworken/hishtory/client/data"
|
||||||
"github.com/ddworken/hishtory/client/hctx"
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
"github.com/ddworken/hishtory/client/lib"
|
"github.com/ddworken/hishtory/client/lib"
|
||||||
@ -135,131 +136,14 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to update hishtory: %v", err)
|
log.Fatalf("Failed to update hishtory: %v", err)
|
||||||
}
|
}
|
||||||
case "config-get":
|
|
||||||
ctx := hctx.MakeContext()
|
|
||||||
config := hctx.GetConf(ctx)
|
|
||||||
key := os.Args[2]
|
|
||||||
switch key {
|
|
||||||
case "enable-control-r":
|
|
||||||
fmt.Printf("%v", config.ControlRSearchEnabled)
|
|
||||||
case "filter-duplicate-commands":
|
|
||||||
fmt.Printf("%v", config.FilterDuplicateCommands)
|
|
||||||
case "displayed-columns":
|
|
||||||
for _, col := range config.DisplayedColumns {
|
|
||||||
if strings.Contains(col, " ") {
|
|
||||||
fmt.Printf("%q ", col)
|
|
||||||
} else {
|
|
||||||
fmt.Print(col + " ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Print("\n")
|
|
||||||
case "custom-columns":
|
|
||||||
for _, cc := range config.CustomColumns {
|
|
||||||
fmt.Println(cc.ColumnName + ": " + cc.ColumnCommand)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
log.Fatalf("Unrecognized config key: %s", key)
|
|
||||||
}
|
|
||||||
case "config-set":
|
case "config-set":
|
||||||
ctx := hctx.MakeContext()
|
fallthrough
|
||||||
config := hctx.GetConf(ctx)
|
case "config-get":
|
||||||
key := os.Args[2]
|
fallthrough
|
||||||
switch key {
|
|
||||||
case "enable-control-r":
|
|
||||||
val := os.Args[3]
|
|
||||||
if val != "true" && val != "false" {
|
|
||||||
log.Fatalf("Unexpected config value %s, must be one of: true, false", val)
|
|
||||||
}
|
|
||||||
config.ControlRSearchEnabled = (val == "true")
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
case "filter-duplicate-commands":
|
|
||||||
val := os.Args[3]
|
|
||||||
if val != "true" && val != "false" {
|
|
||||||
log.Fatalf("Unexpected config value %s, must be one of: true, false", val)
|
|
||||||
}
|
|
||||||
config.FilterDuplicateCommands = (val == "true")
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
case "displayed-columns":
|
|
||||||
vals := os.Args[3:]
|
|
||||||
config.DisplayedColumns = vals
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
case "timestamp-format":
|
|
||||||
val := os.Args[3]
|
|
||||||
config.TimestampFormat = val
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
case "custom-columns":
|
|
||||||
log.Fatalf("Please use config-add and config-delete to interact with custom-columns")
|
|
||||||
default:
|
|
||||||
log.Fatalf("Unrecognized config key: %s", key)
|
|
||||||
}
|
|
||||||
case "config-add":
|
case "config-add":
|
||||||
ctx := hctx.MakeContext()
|
fallthrough
|
||||||
config := hctx.GetConf(ctx)
|
|
||||||
key := os.Args[2]
|
|
||||||
switch key {
|
|
||||||
case "custom-column":
|
|
||||||
fallthrough
|
|
||||||
case "custom-columns":
|
|
||||||
columnName := os.Args[3]
|
|
||||||
command := os.Args[4]
|
|
||||||
ctx := hctx.MakeContext()
|
|
||||||
config := hctx.GetConf(ctx)
|
|
||||||
if config.CustomColumns == nil {
|
|
||||||
config.CustomColumns = make([]hctx.CustomColumnDefinition, 0)
|
|
||||||
}
|
|
||||||
config.CustomColumns = append(config.CustomColumns, hctx.CustomColumnDefinition{ColumnName: columnName, ColumnCommand: command})
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
case "displayed-columns":
|
|
||||||
vals := os.Args[3:]
|
|
||||||
config.DisplayedColumns = append(config.DisplayedColumns, vals...)
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
default:
|
|
||||||
log.Fatalf("Unrecognized config key: %s", key)
|
|
||||||
}
|
|
||||||
case "config-delete":
|
case "config-delete":
|
||||||
ctx := hctx.MakeContext()
|
cmd.Execute()
|
||||||
config := hctx.GetConf(ctx)
|
|
||||||
key := os.Args[2]
|
|
||||||
switch key {
|
|
||||||
case "custom-columns":
|
|
||||||
columnName := os.Args[2]
|
|
||||||
ctx := hctx.MakeContext()
|
|
||||||
config := hctx.GetConf(ctx)
|
|
||||||
if config.CustomColumns == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
newColumns := make([]hctx.CustomColumnDefinition, 0)
|
|
||||||
deletedColumns := false
|
|
||||||
for _, c := range config.CustomColumns {
|
|
||||||
if c.ColumnName != columnName {
|
|
||||||
newColumns = append(newColumns, c)
|
|
||||||
deletedColumns = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !deletedColumns {
|
|
||||||
log.Fatalf("Did not find a column with name %#v to delete (current columns = %#v)", columnName, config.CustomColumns)
|
|
||||||
}
|
|
||||||
config.CustomColumns = newColumns
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
case "displayed-columns":
|
|
||||||
deletedColumns := os.Args[3:]
|
|
||||||
newColumns := make([]string, 0)
|
|
||||||
for _, c := range config.DisplayedColumns {
|
|
||||||
isDeleted := false
|
|
||||||
for _, d := range deletedColumns {
|
|
||||||
if c == d {
|
|
||||||
isDeleted = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !isDeleted {
|
|
||||||
newColumns = append(newColumns, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
config.DisplayedColumns = newColumns
|
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
|
||||||
default:
|
|
||||||
log.Fatalf("Unrecognized config key: %s", key)
|
|
||||||
}
|
|
||||||
case "reupload":
|
case "reupload":
|
||||||
// Purposefully undocumented since this command is generally not necessary to run
|
// Purposefully undocumented since this command is generally not necessary to run
|
||||||
lib.CheckFatalError(lib.Reupload(hctx.MakeContext()))
|
lib.CheckFatalError(lib.Reupload(hctx.MakeContext()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user