Skip to content

Commit

Permalink
fix ctrl r bindings in zsh, polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
curusarn committed Jan 20, 2020
1 parent 5293c21 commit b8be59c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions cmd/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/user"
"path/filepath"
"strings"

"github.com/BurntSushi/toml"
"github.com/curusarn/resh/pkg/cfg"
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/control/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -55,6 +55,7 @@ var statusCmd = &cobra.Command{
} else {
fmt.Println(" * zsh future sessions: DISABLED (not recommended)")
}

exitCode = status.ReshStatus
},
}
Expand Down
1 change: 1 addition & 0 deletions conf/config-dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ sesshistInitHistorySize = 1000
debug = true
bindArrowKeysBash = false
bindArrowKeysZsh = true
bindControlR = true
1 change: 1 addition & 0 deletions conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ sesshistInitHistorySize = 1000
debug = true
bindArrowKeysBash = false
bindArrowKeysZsh = true
bindControlR = false
37 changes: 26 additions & 11 deletions scripts/reshctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
;;
Expand Down
1 change: 1 addition & 0 deletions scripts/shellrc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/widgets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8be59c

Please sign in to comment.