diff --git a/Makefile b/Makefile index 4249809..da01a7a 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ sanitize: # # -build: submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect bin/resh-daemon bin/resh-evaluate bin/resh-sanitize bin/resh-control +build: submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect bin/resh-daemon bin/resh-evaluate bin/resh-sanitize bin/resh-control bin/resh-config test_go: # Running tests diff --git a/cmd/config/main.go b/cmd/config/main.go new file mode 100644 index 0000000..49fe9ee --- /dev/null +++ b/cmd/config/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "flag" + "fmt" + "os" + "os/user" + "path/filepath" + + "github.com/BurntSushi/toml" + "github.com/curusarn/resh/pkg/cfg" +) + +func main() { + usr, _ := user.Current() + dir := usr.HomeDir + configPath := filepath.Join(dir, ".config/resh.toml") + + var config cfg.Config + _, err := toml.DecodeFile(configPath, &config) + if err != nil { + fmt.Println("Error reading config", err) + os.Exit(1) + } + + configKey := flag.String("key", "", "Key of the requested config entry") + flag.Parse() + + if *configKey == "" { + fmt.Println("Error: expected option --key!") + os.Exit(1) + } + + switch *configKey { + case "BindArrowKeysBash": + fallthrough + case "bindArrowKeysBash": + printBoolNormalized(config.BindArrowKeysBash) + case "BindArrowKeysZsh": + fallthrough + case "bindArrowKeysZsh": + printBoolNormalized(config.BindArrowKeysZsh) + default: + fmt.Println("Error: illegal --key!") + os.Exit(1) + } +} + +// this might be unnecessary but I'm too lazy to look it up +func printBoolNormalized(x bool) { + if x { + fmt.Println("true") + } else { + fmt.Println("false") + } +} diff --git a/conf/config.toml b/conf/config.toml index 51c0d40..7dc647c 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -2,5 +2,5 @@ port = 2627 sesswatchPeriodSeconds = 120 sesshistInitHistorySize = 1000 debug = true -bindArrowKeysBash = true +bindArrowKeysBash = false bindArrowKeysZsh = true diff --git a/scripts/shellrc.sh b/scripts/shellrc.sh index e447fc7..a6b9ebc 100644 --- a/scripts/shellrc.sh +++ b/scripts/shellrc.sh @@ -86,5 +86,14 @@ if [ -z "${__RESH_INIT_DONE+x}" ]; then __resh_reset_variables + if [ "$__RESH_SHELL" = bash ] ; then + [ "$(resh-config --key BindArrowKeysBash)" = true ] && reshctl enable arrow_key_bindings + elif [ "$__RESH_SHELL" = zsh ] ; then + [ "$(resh-config --key BindArrowKeysZsh)" = true ] && reshctl enable arrow_key_bindings + else + echo "RESH error: unknown shell (init)" + echo "$__RESH_SHELL" + fi + __RESH_INIT_DONE=1 fi