improve reshctl subcommands, add disable for arrow key binds

pull/30/head
Simon Let 6 years ago
parent aac6540d68
commit 992178a9c8
  1. 2
      Makefile
  2. 26
      cmd/control/cmd/disable.go
  3. 26
      cmd/control/cmd/enable.go
  4. 6
      cmd/control/cmd/root.go
  5. 8
      cmd/control/status/status.go
  6. 54
      scripts/reshctl.sh
  7. 4
      scripts/shellrc.sh

@ -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

@ -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
},
}

@ -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
},
}

@ -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)

@ -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
)

@ -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)

@ -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"

Loading…
Cancel
Save