diff --git a/Makefile b/Makefile index 616b057..9c3fe80 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ build: submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect bi install: build conf/config-dev.toml scripts/install.sh # Dev config - cp -f conf/config-dev.toml ~/.config/ + cp -f conf/config-dev.toml ~/.config/resh.toml test_go: # Running tests diff --git a/cmd/config/main.go b/cmd/config/main.go index 49fe9ee..1a9b407 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -6,6 +6,7 @@ import ( "os" "os/user" "path/filepath" + "strings" "github.com/BurntSushi/toml" "github.com/curusarn/resh/pkg/cfg" @@ -31,15 +32,14 @@ func main() { os.Exit(1) } + *configKey = strings.ToLower(*configKey) switch *configKey { - case "BindArrowKeysBash": - fallthrough - case "bindArrowKeysBash": + case "bindarrowkeysbash": printBoolNormalized(config.BindArrowKeysBash) - case "BindArrowKeysZsh": - fallthrough - case "bindArrowKeysZsh": + case "bindarrowkeyszsh": printBoolNormalized(config.BindArrowKeysZsh) + case "bindcontrolr": + printBoolNormalized(config.BindControlR) default: fmt.Println("Error: illegal --key!") os.Exit(1) diff --git a/cmd/control/cmd/status.go b/cmd/control/cmd/status.go index a4ea064..5cfbf1d 100644 --- a/cmd/control/cmd/status.go +++ b/cmd/control/cmd/status.go @@ -44,7 +44,7 @@ var statusCmd = &cobra.Command{ } fmt.Println() - fmt.Println("Arrow key bindnigs ...") + fmt.Println("Arrow key bindings ...") if config.BindArrowKeysBash { fmt.Println(" * bash future sessions: ENABLED (not recommended)") } else { @@ -55,6 +55,7 @@ var statusCmd = &cobra.Command{ } else { fmt.Println(" * zsh future sessions: DISABLED (not recommended)") } + exitCode = status.ReshStatus }, } diff --git a/conf/config-dev.toml b/conf/config-dev.toml index 7dc647c..2c0031d 100644 --- a/conf/config-dev.toml +++ b/conf/config-dev.toml @@ -4,3 +4,4 @@ sesshistInitHistorySize = 1000 debug = true bindArrowKeysBash = false bindArrowKeysZsh = true +bindControlR = true diff --git a/conf/config.toml b/conf/config.toml index 7dc647c..fb1b618 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -4,3 +4,4 @@ sesshistInitHistorySize = 1000 debug = true bindArrowKeysBash = false bindArrowKeysZsh = true +bindControlR = false diff --git a/scripts/reshctl.sh b/scripts/reshctl.sh index 7a0a6dc..6bbe5ac 100644 --- a/scripts/reshctl.sh +++ b/scripts/reshctl.sh @@ -97,17 +97,20 @@ __resh_unbind_all() { __resh_unbind_control_R } -# wrapper for resh-cli -# meant to be launched on ctrl+R +# wrapper for resh-cli for calling resh directly resh() { - # TODO: rewrite this based on the widget - if resh-cli --sessionID "$__RESH_SESSION_ID" --pwd "$PWD" > ~/.resh/cli_last_run_out.txt 2>&1; then - # insert on cmdline - cat ~/.resh/cli_last_run_out.txt - eval "$(cat ~/.resh/cli_last_run_out.txt)" - # TODO: get rid of eval + local buffer + buffer=$(resh-cli --sessionID "$__RESH_SESSION_ID" --pwd "$PWD") + status_code=$? + if [ $status_code = 111 ]; then + # execute + echo "$buffer" + eval "$buffer" + elif [ $status_code = 0 ]; then + # paste + echo "$buffer" else - # print errors + echo "$buffer" > ~/.resh/cli_last_run_out.txt echo "resh-cli ERROR:" cat ~/.resh/cli_last_run_out.txt fi @@ -176,9 +179,21 @@ reshctl() { 202) # show status if [ "${__RESH_arrow_keys_bind_enabled-0}" != 0 ]; then - echo " * this session: ENABLED" + echo ' * this session: ENABLED' + else + echo ' * this session: DISABLED' + fi + echo + echo 'Control R binding ...' + if [ "$(resh-config --key BindControlR)" = true ]; then + echo ' * future sessions: ENABLED (experimental)' + else + echo ' * future sessions: DISABLED (recommended)' + fi + if [ "${__RESH_control_R_bind_enabled-0}" != 0 ]; then + echo ' * this session: ENABLED' else - echo " * this session: DISABLED" + echo ' * this session: DISABLED' fi return 0 ;; diff --git a/scripts/shellrc.sh b/scripts/shellrc.sh index 7144cb5..cde8ff9 100644 --- a/scripts/shellrc.sh +++ b/scripts/shellrc.sh @@ -96,6 +96,7 @@ if [ -z "${__RESH_INIT_DONE+x}" ]; then echo "RESH error: unknown shell (init)" echo "$__RESH_SHELL" fi + [ "$(resh-config --key BindControlR)" = true ] && reshctl enable ctrl_r_binding __RESH_INIT_DONE=1 fi diff --git a/scripts/widgets.sh b/scripts/widgets.sh index 1d67513..0c1b849 100644 --- a/scripts/widgets.sh +++ b/scripts/widgets.sh @@ -102,14 +102,14 @@ __resh_widget_control_R() { # zsh zle accept-line elif [ -n "${BASH_VERSION-}" ]; then - echo "BASH is not currently not supported" + echo "BASH is not currently not supported for control R binding - sorry" # bash # TODO set chained keyseq to accept-line true fi elif [ $status_code = 0 ]; then if [ -n "${BASH_VERSION-}" ]; then - echo "BASH is not currently not supported" + echo "BASH is not currently not supported for control R binding - sorry" # bash # TODO set chained keyseq to nothing true