Further simplify shell files, minor readme changes

pull/184/head
Simon Let 3 years ago
parent fcd8c8bfed
commit 585cafa1ab
  1. 5
      README.md
  2. 2
      roadmap.md
  3. 69
      scripts/hooks.sh
  4. 4
      scripts/install.sh
  5. 71
      scripts/reshctl.sh
  6. 2
      scripts/shellrc.sh
  7. 2
      scripts/test.sh

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

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

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

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

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

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

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

Loading…
Cancel
Save