From 585cafa1abcdd8010e4ef8f142bc4e59e8a6f9e4 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Sun, 8 Jan 2023 23:59:18 +0100 Subject: [PATCH] Further simplify shell files, minor readme changes --- README.md | 5 +--- roadmap.md | 2 ++ scripts/hooks.sh | 69 +++++++++++++++++++++++++++++++++++++++++++- scripts/install.sh | 4 +-- scripts/reshctl.sh | 71 ---------------------------------------------- scripts/shellrc.sh | 2 -- scripts/test.sh | 2 +- 7 files changed, 74 insertions(+), 81 deletions(-) delete mode 100644 scripts/reshctl.sh diff --git a/README.md b/README.md index f345f97..ca859d0 100644 --- a/README.md +++ b/README.md @@ -82,10 +82,7 @@ RESH SEARCH app replaces the standard reverse search - launch it using Ctrl+R. Enable/disable the Ctrl+R keybinding: -```sh -reshctl enable ctrl_r_binding -reshctl disable ctrl_r_binding -``` +TODO: how to enable disable keybindings ### In-app key bindings diff --git a/roadmap.md b/roadmap.md index e2be272..4bd400d 100644 --- a/roadmap.md +++ b/roadmap.md @@ -9,6 +9,8 @@ *NOTE: Features can change in the future* +TODO: Update this + - :heavy_check_mark: Record shell history with metadata - :heavy_check_mark: save it as JSON to `~/.resh_history.json` diff --git a/scripts/hooks.sh b/scripts/hooks.sh index 5ae52b5..6459bf7 100644 --- a/scripts/hooks.sh +++ b/scripts/hooks.sh @@ -155,6 +155,73 @@ __resh_widget_control_R() { CURSOR=${#BUFFER} } +# Wrapper for resh-cli for calling resh directly +resh() { + if [ "$(resh-cli -version)" != "$__RESH_VERSION" ] && [ -z "${__RESH_NO_RELOAD-}" ]; then + source ~/.resh/shellrc + # Show reload message from the updated shell files + __resh_reload_msg + # Rerun self but prevent another reload. Extra protection against infinite recursion. + __RESH_NO_RELOAD=1 resh "$@" + return $? + fi + local buffer + local git_remote; git_remote="$(git remote get-url origin 2>/dev/null)" + buffer=$(resh-cli -requireVersion "$__RESH_VERSION" \ + --git-origin-remote "$git_remote" \ + --pwd "$PWD" \ + --session-id "$__RESH_SESSION_ID" \ + "$@" + ) + status_code=$? + if [ $status_code = 111 ]; then + # execute + echo "$buffer" + eval "$buffer" + elif [ $status_code = 0 ]; then + # paste + echo "$buffer" + elif [ $status_code = 130 ]; then + true + else + printf "%s" "$buffer" >&2 + fi +} + __resh_widget_control_R_compat() { __bindfunc_compat_wrapper __resh_widget_control_R -} \ No newline at end of file +} + +__resh_nop() { + # does nothing + true +} + +# shellcheck source=../submodules/bash-zsh-compat-widgets/bindfunc.sh +. ~/.resh/bindfunc.sh + +__resh_bind_control_R() { + bindfunc --revert '\C-r' __resh_widget_control_R_compat + if [ "${__RESH_control_R_bind_enabled-0}" != 0 ]; then + # Re-binding is a valid usecase but it shouldn't happen much + # so this is a warning + # echo "Re-binding RESH SEARCH app to Ctrl+R ..." + else + # Only save original binding if resh binding was not enabled + __RESH_bindfunc_revert_control_R_bind=$_bindfunc_revert + fi + __RESH_control_R_bind_enabled=1 + if [ -n "${BASH_VERSION-}" ]; then + # fuck bash + bind '"\C-r": "\u[31~\u[32~"' + bind -x '"\u[31~": __resh_widget_control_R_compat' + + # execute + # bind '"\u[32~": accept-line' + + # just paste + # bind -x '"\u[32~": __resh_nop' + true + fi + return 0 +} diff --git a/scripts/install.sh b/scripts/install.sh index 9f8c845..ef82451 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -93,13 +93,13 @@ cp -f submodules/bash-zsh-compat-widgets/bindfunc.sh ~/.resh/bindfunc.sh cp -f scripts/shellrc.sh ~/.resh/shellrc cp -f scripts/resh-daemon-start.sh ~/.resh/bin/resh-daemon-start -cp -f scripts/reshctl.sh scripts/hooks.sh ~/.resh/ +cp -f scripts/hooks.sh ~/.resh/ cp -f scripts/rawinstall.sh ~/.resh/ # Copy all executables. We don't really need to omit install-utils from the bin directory echo "Copying more files ..." cp -f bin/resh-* ~/.resh/bin/ -# rename reshctl +# Rename reshctl mv ~/.resh/bin/resh-control ~/.resh/bin/reshctl # Shutting down resh daemon ... diff --git a/scripts/reshctl.sh b/scripts/reshctl.sh deleted file mode 100644 index 8d620d1..0000000 --- a/scripts/reshctl.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/hint/sh - -# shellcheck source=../submodules/bash-zsh-compat-widgets/bindfunc.sh -. ~/.resh/bindfunc.sh -# shellcheck source=hooks.sh -. ~/.resh/hooks.sh - -__resh_nop() { - # does nothing - true -} - -__resh_bind_control_R() { - bindfunc --revert '\C-r' __resh_widget_control_R_compat - if [ "${__RESH_control_R_bind_enabled-0}" != 0 ]; then - # Re-binding is a valid usecase but it shouldn't happen much - # so this is a warning - # echo "Re-binding RESH SEARCH app to Ctrl+R ..." - else - # Only save original binding if resh binding was not enabled - __RESH_bindfunc_revert_control_R_bind=$_bindfunc_revert - fi - __RESH_control_R_bind_enabled=1 - if [ -n "${BASH_VERSION-}" ]; then - # fuck bash - bind '"\C-r": "\u[31~\u[32~"' - bind -x '"\u[31~": __resh_widget_control_R_compat' - - # execute - # bind '"\u[32~": accept-line' - - # just paste - # bind -x '"\u[32~": __resh_nop' - true - fi - return 0 -} - -__resh_unbind_control_R() { - if [ "${__RESH_control_R_bind_enabled-0}" != 1 ]; then - echo "RESH SEARCH app Ctrl+R binding is already disabled!" - return 1 - fi - if [ -z "${__RESH_bindfunc_revert_control_R_bind+x}" ]; then - echo "Warn: Couldn't revert Ctrl+R binding because 'revert command' is empty." - else - eval "$__RESH_bindfunc_revert_control_R_bind" - fi - __RESH_control_R_bind_enabled=0 - return 0 -} - -# wrapper for resh-cli for calling resh directly -resh() { - local buffer - local git_remote; git_remote="$(git remote get-url origin 2>/dev/null)" - buffer=$(resh-cli --sessionID "$__RESH_SESSION_ID" --pwd "$PWD" --gitOriginRemote "$git_remote" "$@") - status_code=$? - if [ $status_code = 111 ]; then - # execute - echo "$buffer" - eval "$buffer" - elif [ $status_code = 0 ]; then - # paste - echo "$buffer" - elif [ $status_code = 130 ]; then - true - else - printf "%s" "$buffer" >&2 - fi -} \ No newline at end of file diff --git a/scripts/shellrc.sh b/scripts/shellrc.sh index 7a8a1e8..a641d6d 100644 --- a/scripts/shellrc.sh +++ b/scripts/shellrc.sh @@ -4,8 +4,6 @@ PATH=$PATH:~/.resh/bin # shellcheck source=hooks.sh . ~/.resh/hooks.sh -# shellcheck source=reshctl.sh -. ~/.resh/reshctl.sh if [ -n "${ZSH_VERSION-}" ]; then # shellcheck disable=SC1009 diff --git a/scripts/test.sh b/scripts/test.sh index b76cff2..bd2c810 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,7 +9,7 @@ for f in scripts/*.sh; do shellcheck "$f" --shell=bash --severity=error || exit 1 done -for f in scripts/{shellrc,reshctl,hooks}.sh; do +for f in scripts/{shellrc,hooks}.sh; do echo "Checking Zsh syntax of $f ..." ! zsh -n "$f" && echo "Zsh syntax check failed!" && exit 1 done