diff --git a/Makefile b/Makefile index 9b86acd..a63d529 100644 --- a/Makefile +++ b/Makefile @@ -131,7 +131,7 @@ uninstall: # Uninstalling ... -rm -rf ~/.resh/ -bin/resh-control: cmd/control/cmd/*.go +bin/resh-control: cmd/control/cmd/*.go cmd/control/status/*.go bin/resh-%: cmd/%/*.go pkg/*/*.go VERSION go build ${GOFLAGS} -o $@ cmd/$*/*.go diff --git a/cmd/control/cmd/disable.go b/cmd/control/cmd/disable.go index b0dead5..fbc72db 100644 --- a/cmd/control/cmd/disable.go +++ b/cmd/control/cmd/disable.go @@ -7,18 +7,22 @@ import ( var disableCmd = &cobra.Command{ Use: "disable", - Short: "disable RESH features", - Long: `Disables RESH bindings for arrows and C-R.`, + Short: "disable RESH features (arrow key bindings)", +} + +var disableArrowKeyBindingsCmd = &cobra.Command{ + Use: "arrow_key_bindings", + Short: "disable bindings for arrow keys (up/down) FOR THIS SHELL SESSION", Run: func(cmd *cobra.Command, args []string) { - exitCode = status.DisableAll + exitCode = status.DisableArrowKeyBindings }, } -// var disableRecallingCmd = &cobra.Command{ -// Use: "keybind", -// Short: "Disables RESH bindings for arrows and C-R.", -// Long: `Disables RESH bindings for arrows and C-R.`, -// Run: func(cmd *cobra.Command, args []string) { -// exitCode = status.DisableAll -// }, -// } +var disableArrowKeyBindingsGlobalCmd = &cobra.Command{ + Use: "arrow_key_bindings_global", + Short: "disable bindings for arrow keys (up/down) FOR THIS AND ALL FUTURE SHELL SESSIONS", + Run: func(cmd *cobra.Command, args []string) { + // TODO: config set arrow_key_bindings true + exitCode = status.DisableArrowKeyBindings + }, +} diff --git a/cmd/control/cmd/enable.go b/cmd/control/cmd/enable.go index ab4b144..0b62e78 100644 --- a/cmd/control/cmd/enable.go +++ b/cmd/control/cmd/enable.go @@ -7,18 +7,22 @@ import ( var enableCmd = &cobra.Command{ Use: "enable", - Short: "enable RESH features", - Long: `Enables RESH bindings for arrows and C-R.`, + Short: "enable RESH features (arrow key bindings)", +} + +var enableArrowKeyBindingsCmd = &cobra.Command{ + Use: "arrow_key_bindings", + Short: "enable bindings for arrow keys (up/down) FOR THIS SHELL SESSION", Run: func(cmd *cobra.Command, args []string) { - exitCode = status.EnableAll + exitCode = status.EnableArrowKeyBindings }, } -// var enableRecallingCmd = &cobra.Command{ -// Use: "keybind", -// Short: "Enables RESH bindings for arrows and C-R.", -// Long: `Enables RESH bindings for arrows and C-R.`, -// Run: func(cmd *cobra.Command, args []string) { -// exitCode = status.EnableAll -// }, -// } +var enableArrowKeyBindingsGlobalCmd = &cobra.Command{ + Use: "arrow_key_bindings_global", + Short: "enable bindings for arrow keys (up/down) FOR THIS AND ALL FUTURE SHELL SESSIONS", + Run: func(cmd *cobra.Command, args []string) { + // TODO: config set arrow_key_bindings true + exitCode = status.EnableArrowKeyBindings + }, +} diff --git a/cmd/control/cmd/root.go b/cmd/control/cmd/root.go index a00d342..a9e4c50 100644 --- a/cmd/control/cmd/root.go +++ b/cmd/control/cmd/root.go @@ -18,10 +18,12 @@ var rootCmd = &cobra.Command{ // Execute reshctl func Execute() status.Code { rootCmd.AddCommand(disableCmd) - // disableCmd.AddCommand(disableRecallingCmd) + disableCmd.AddCommand(disableArrowKeyBindingsCmd) + disableCmd.AddCommand(disableArrowKeyBindingsGlobalCmd) rootCmd.AddCommand(enableCmd) - // enableCmd.AddCommand(enableRecallingCmd) + enableCmd.AddCommand(enableArrowKeyBindingsCmd) + enableCmd.AddCommand(enableArrowKeyBindingsGlobalCmd) rootCmd.AddCommand(completionCmd) completionCmd.AddCommand(completionBashCmd) diff --git a/cmd/control/status/status.go b/cmd/control/status/status.go index 8b9eeec..97f9d68 100644 --- a/cmd/control/status/status.go +++ b/cmd/control/status/status.go @@ -8,10 +8,10 @@ const ( Success Code = 0 // Fail exit code Fail = 1 - // EnableAll exit code - tells reshctl() wrapper to enable_all - EnableAll = 100 - // DisableAll exit code - tells reshctl() wrapper to disable_all - DisableAll = 110 + // EnableArrowKeyBindings exit code - tells reshctl() wrapper to enable arrow key bindings + EnableArrowKeyBindings = 101 + // DisableArrowKeyBindings exit code - tells reshctl() wrapper to disable arrow key bindings + DisableArrowKeyBindings = 111 // ReloadRcFiles exit code - tells reshctl() wrapper to reload shellrc resh file ReloadRcFiles = 200 ) diff --git a/scripts/reshctl.sh b/scripts/reshctl.sh index 2656055..9f40bbc 100644 --- a/scripts/reshctl.sh +++ b/scripts/reshctl.sh @@ -5,22 +5,46 @@ . ~/.resh/widgets.sh __resh_bind_arrows() { - bindfunc '\e[A' __resh_widget_arrow_up_compat - bindfunc '\e[B' __resh_widget_arrow_down_compat + if [ "${__RESH_arrow_keys_bind_enabled-0}" != 0 ]; then + echo "Error: RESH arrow key bindings are already enabled!" + return 1 + fi + bindfunc --revert '\e[A' __resh_widget_arrow_up_compat + __RESH_bindfunc_revert_arrow_up_bind=$_bindfunc_revert + bindfunc --revert '\e[B' __resh_widget_arrow_down_compat + __RESH_bindfunc_revert_arrow_down_bind=$_bindfunc_revert + __RESH_arrow_keys_bind_enabled=1 return 0 } __resh_bind_control_R() { + # TODO echo "bindfunc __resh_widget_control_R_compat" return 0 } + __resh_unbind_arrows() { - echo "\ bindfunc __resh_widget_arrow_up_compat" - echo "\ bindfunc __resh_widget_arrow_down_compat" + if [ "${__RESH_arrow_keys_bind_enabled-0}" != 1 ]; then + echo "Error: Can't disable arrow key bindings because they are not enabled!" + return 1 + fi + if [ -z "${__RESH_bindfunc_revert_arrow_up_bind+x}" ]; then + echo "Warn: Couldn't revert arrow UP binding because 'revert command' is empty." + else + eval "$__RESH_bindfunc_revert_arrow_up_bind" + echo "RESH arrow up binding successfully disabled ✓" + fi + if [ -z "${__RESH_bindfunc_revert_arrow_down_bind+x}" ]; then + echo "Warn: Couldn't revert arrow DOWN binding because 'revert command' is empty." + else + eval "$__RESH_bindfunc_revert_arrow_down_bind" + echo "RESH arrow down binding successfully disabled ✓" + fi return 0 } __resh_unbind_control_R() { + # TODO echo "\ bindfunc __resh_widget_control_R_compat" return 0 } @@ -46,15 +70,25 @@ reshctl() { return "$_status" ;; # enable - 100) - # enable all - __resh_bind_all + # 100) + # # enable all + # __resh_bind_all + # return 0 + # ;; + 101) + # enable arrow keys + __resh_bind_arrows return 0 ;; # disable - 110) - # disable all - __resh_unbind_all + # 110) + # # disable all + # __resh_unbind_all + # return 0 + # ;; + 111) + # disable arrow keys + __resh_unbind_arrows return 0 ;; 200) diff --git a/scripts/shellrc.sh b/scripts/shellrc.sh index c4d3afc..e447fc7 100644 --- a/scripts/shellrc.sh +++ b/scripts/shellrc.sh @@ -23,13 +23,13 @@ else echo "resh PANIC unrecognized OS" fi -if [ -n "$ZSH_VERSION" ]; then +if [ -n "${ZSH_VERSION-}" ]; then # shellcheck disable=SC1009 __RESH_SHELL="zsh" __RESH_HOST="$HOST" __RESH_HOSTTYPE="$CPUTYPE" __resh_zsh_completion_init -elif [ -n "$BASH_VERSION" ]; then +elif [ -n "${BASH_VERSION-}" ]; then __RESH_SHELL="bash" __RESH_HOST="$HOSTNAME" __RESH_HOSTTYPE="$HOSTTYPE"