update readme, install info, error mesages, minor fix, minor score tweak

pull/143/head v2.7.0-rc1
Simon Let 6 years ago
parent 09dff916df
commit a9ef6453d1
  1. 4
      Makefile
  2. 57
      README.md
  3. 2
      cmd/cli/item.go
  4. 11
      cmd/cli/main.go
  5. 102
      cmd/control/cmd/enable.go
  6. 4
      cmd/control/cmd/root.go
  7. 2
      cmd/inspect/main.go
  8. 7
      conf/config-dev.toml
  9. BIN
      img/screen-resh-cli-v2-7-init.png
  10. BIN
      img/screen-resh-cli-v2-7-no-query.png
  11. BIN
      img/screen-resh-cli-v2-7.png
  12. 4
      pkg/collect/collect.go
  13. 95
      scripts/install.sh
  14. 8
      scripts/reshctl.sh
  15. 6
      scripts/shellrc.sh
  16. 4
      scripts/widgets.sh

@ -8,10 +8,8 @@ GOFLAGS=-ldflags "-X main.version=${VERSION} -X main.commit=${REVISION}"
build: submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect bin/resh-daemon\
bin/resh-evaluate bin/resh-sanitize bin/resh-control bin/resh-config bin/resh-inspect bin/resh-cli
install: build conf/config-dev.toml
install: build
scripts/install.sh
# Dev config
# cp -f conf/config-dev.toml ~/.config/resh.toml
test_go:
# Running tests

@ -59,17 +59,18 @@ Imagine being able to search your shell history based on both the command itself
- :heavy_check_mark: search by keywords
- :heavy_check_mark: relevant results show up first based on context (host, directory, git, exit status)
- :heavy_check_mark: allow searching completely without context ("raw" mode)
- :white_check_mark: include a help page with keybindings and onboarding in the app
- :x: import and search history from before RESH was installed
- :heavy_check_mark: import and search history from before RESH was installed
- :white_check_mark: include a help with keybindings
- :x: allow listing details for individual commands
- :x: allow explicitly searching by metadata
- :white_check_mark: Provide bindings for arrow keys
- :heavy_check_mark: imitate default behaviour
- :heavy_check_mark: save additional metadata (e.g. command was recalled using arrow keys)
- :heavy_check_mark: imitate default behaviour (serve recent history)
- :heavy_check_mark: built-in prefix search
- :heavy_check_mark: serve fully dedupicated history
- :x: use arrow down for easy sequence repeating
- :heavy_check_mark: zsh
- :white_check_mark: bash *(performance issues)*
- :white_check_mark: bash *(off by deafult because of bash performance issues)*
- :heavy_check_mark: Provide a `reshctl` utility to control and interact with the project
- :heavy_check_mark: turn on/off resh key bindings
@ -125,47 +126,47 @@ Check for updates and update
reshctl update
```
### RESH CLI tool
### RESH SEARCH application
RESH CLI searches your history by commands. It uses host, directories, git remote, and exit status to show you relevant results first.
RESH SEARCH app searches your history by commands. It uses host, directories, git remote, and exit status to show you relevant results first.
All this context is not in the regular shell history. RESH CLI will only search shell history that was recorded after you install this project.
All this context is not in the regular shell history. RESH records shell history with context to use it when searching.
*I use RESH CLI everyday but please remember that it is still a prototype.*
At first, the search application will look something like this. Some history with context and most of it without. As you can see, you can still search the history just fine.
![resh cli](img/screen-resh-cli-v2-6.png)
![resh search app](img/screen-resh-cli-v2-7-init.png)
Without query, RESH CLI shows you the latest history based on the current context (host, directory, git).
Eventually most of your history will have context and RESH SEARCH app will get more useful.
![resh cli](img/screen-resh-cli-v2-6-no-query.png)
![resh search app](img/screen-resh-cli-v2-7.png)
RESH CLI tool can be bound to ctrl+R (recommended) or executed directly.
Without a query, RESH SEARCH app shows you the latest history based on the current context (host, directory, git).
Enable/disable ctrl+R binding for THIS shell session:
![resh search app](img/screen-resh-cli-v2-7-no-query.png)
```sh
reshctl enable ctrl_r_binding
reshctl disable ctrl_r_binding
```
RESH SEARCH app replaces the standard reverse search - launch it using Ctrl+R.
Enable/disable for FUTURE shell sessions:
Enable/disable the Ctrl+R keybinding:
```sh
reshctl enable ctrl_r_binding_global
reshctl disable ctrl_r_binding_global
reshctl enable ctrl_r_binding
reshctl disable ctrl_r_binding
```
Run the RESH CLI tool as a one-off:
You can also run the RESH SEARCH app directly as a one-off:
```sh
resh
```
NOTE: One feature is not available when running RESH SEARCH app directly - arrow right won't paste the selected command onto the command line for editing.
### Arrow key bindings
Resh provides arrow key bindings.
These bindings do regular stepping through history and prefix search.
These bindings provide regular stepping through history and prefix search.
They also fully deduplicate the served history.
They allow resh to record bindings usage metadata.
@ -175,7 +176,7 @@ They allow resh to record bindings usage metadata.
Arrow key bindings are enabled by default in zsh and they are disabled by default in bash because there are some performance issues.
Enable/disable arrow key bindings for THIS shell session:
Enable/disable arrow key bindings:
```sh
reshctl enable arrow_key_bindings
@ -183,14 +184,6 @@ reshctl enable arrow_key_bindings
reshctl disable arrow_key_bindings
```
Enable/disable for FUTURE shell sessions:
```sh
reshctl enable arrow_key_bindings_global
reshctl disable arrow_key_bindings_global
```
See what your current setting is:
```sh

@ -267,7 +267,7 @@ func properMatch(str, term, padChar string) bool {
func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool) (item, error) {
// Use numbers that won't add up to same score for any number of query words
const hitScore = 1.307
const properMatchScore = 0.603
const properMatchScore = 0.503
const hitScoreConsecutive = 0.002
// Host penalty

@ -378,9 +378,9 @@ func (m manager) Layout(g *gocui.Gui) error {
v.Editable = true
v.Editor = m
if m.s.rawMode {
v.Title = " RESH CLI - NON-CONTEXTUAL \"RAW\" MODE - (CTRL+R to switch BACK) "
v.Title = " RESH SEARCH - NON-CONTEXTUAL \"RAW\" MODE - (CTRL+R to switch BACK) "
} else {
v.Title = " RESH CLI - CONTEXTUAL MODE - (CTRL+R to switch to RAW MODE) "
v.Title = " RESH SEARCH - CONTEXTUAL MODE - (CTRL+R to switch to RAW MODE) "
}
g.SetCurrentView("input")
@ -488,11 +488,12 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
realLineLength := maxX - 2
printedLineLength := maxX - 4
statusLine := m.s.data[m.s.highlightedItem].drawStatusLine(compactRenderingMode, printedLineLength, realLineLength)
var statusLineHeight int = len(statusLine) + 1 // help line
var statusLineHeight int = len(statusLine)
helpLineHeight := 1
const helpLine = "HELP: type to search, UP/DOWN to select, RIGHT to edit, ENTER to execute, CTRL+G to abort, CTRL+C/D to quit; " +
"TIP: when resh-cli is launched command line is used as initial search query"
"FLAGS: G = this git repo, E# = exit status #"
// "TIP: when resh-cli is launched command line is used as initial search query"
mainViewHeight := maxY - topBoxHeight - statusLineHeight - helpLineHeight
m.s.displayedItemsCount = mainViewHeight
@ -605,7 +606,7 @@ func SendCliMsg(m msg.CliMsg, port string) msg.CliResponse {
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal("resh-daemon is not running :(")
log.Fatal("resh-daemon is not running - try restarting this terminal")
}
defer resp.Body.Close()

@ -21,36 +21,26 @@ var enableCmd = &cobra.Command{
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.EnableArrowKeyBindings
},
}
var enableArrowKeyBindingsGlobalCmd = &cobra.Command{
Use: "arrow_key_bindings_global",
Short: "enable bindings for arrow keys (up/down) FOR FUTURE SHELL SESSIONS",
Long: "Enable bindings for arrow keys (up/down) FOR FUTURE SHELL SESSIONS.\n" +
Short: "enable bindings for arrow keys (up/down)",
Long: "Enable bindings for arrow keys (up/down)\n" +
"Note that this only affects sessions of the same shell.\n" +
"(e.g. running this in zsh will only affect future zsh sessions)",
"(e.g. running this in zsh will only enable the keybinding in zsh)",
Run: func(cmd *cobra.Command, args []string) {
exitCode = enableDisableArrowKeyBindingsGlobally(true)
if exitCode == status.Success {
exitCode = status.EnableArrowKeyBindings
}
},
}
var enableControlRBindingCmd = &cobra.Command{
Use: "ctrl_r_binding",
Short: "enable binding for control+R FOR THIS SHELL SESSION",
Run: func(cmd *cobra.Command, args []string) {
exitCode = status.EnableControlRBinding
},
}
var enableControlRBindingGlobalCmd = &cobra.Command{
Use: "ctrl_r_binding_global",
Short: "enable bindings for control+R FOR FUTURE SHELL SESSIONS",
Short: "enable RESH-CLI binding for Ctrl+R",
Run: func(cmd *cobra.Command, args []string) {
exitCode = enableDisableControlRBindingGlobally(true)
if exitCode == status.Success {
exitCode = status.EnableControlRBinding
}
},
}
@ -63,36 +53,26 @@ var disableCmd = &cobra.Command{
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.DisableArrowKeyBindings
},
}
var disableArrowKeyBindingsGlobalCmd = &cobra.Command{
Use: "arrow_key_bindings_global",
Short: "disable bindings for arrow keys (up/down) FOR FUTURE SHELL SESSIONS",
Long: "Disable bindings for arrow keys (up/down) FOR FUTURE SHELL SESSIONS.\n" +
Short: "disable bindings for arrow keys (up/down)",
Long: "Disable bindings for arrow keys (up/down)\n" +
"Note that this only affects sessions of the same shell.\n" +
"(e.g. running this in zsh will only affect future zsh sessions)",
"(e.g. running this in zsh will only enable the keybinding in zsh)",
Run: func(cmd *cobra.Command, args []string) {
exitCode = enableDisableArrowKeyBindingsGlobally(false)
if exitCode == status.Success {
exitCode = status.DisableArrowKeyBindings
}
},
}
var disableControlRBindingCmd = &cobra.Command{
Use: "ctrl_r_binding",
Short: "disable binding for control+R FOR THIS SHELL SESSION",
Run: func(cmd *cobra.Command, args []string) {
exitCode = status.DisableControlRBinding
},
}
var disableControlRBindingGlobalCmd = &cobra.Command{
Use: "ctrl_r_binding_global",
Short: "disable bindings for control+R FOR FUTURE SHELL SESSIONS",
Short: "disable RESH-CLI binding for Ctrl+R",
Run: func(cmd *cobra.Command, args []string) {
exitCode = enableDisableControlRBindingGlobally(false)
if exitCode == status.Success {
exitCode = status.DisableControlRBinding
}
},
}
@ -131,19 +111,7 @@ func enableDisableArrowKeyBindingsGlobally(value bool) status.Code {
// I don't like the interface this function has - passing both config structure and a part of it feels wrong
// It's ugly and could lead to future errors
func setConfigBindArrowKey(configPath string, config *cfg.Config, configField *bool, shell string, value bool) error {
if *configField == value {
if value {
fmt.Println("The RESH arrow key bindings are ALREADY GLOBALLY ENABLED for all future " + shell + " sessions - nothing to do - exiting.")
} else {
fmt.Println("The RESH arrow key bindings are ALREADY GLOBALLY DISABLED for all future " + shell + " sessions - nothing to do - exiting.")
}
return nil
}
if value {
fmt.Println("ENABLING the RESH arrow key bindings GLOBALLY (in " + shell + ") ...")
} else {
fmt.Println("DISABLING the RESH arrow key bindings GLOBALLY (in " + shell + ") ...")
}
if *configField != value {
*configField = value
f, err := os.Create(configPath)
@ -156,12 +124,11 @@ func setConfigBindArrowKey(configPath string, config *cfg.Config, configField *b
fmt.Println("Error: Failed to encode and write the config values to hdd. error:", err)
return err
}
}
if value {
fmt.Println("SUCCESSFULLY ENABLED the RESH arrow key bindings GLOBALLY (in " + shell + ") " +
"- every new (" + shell + ") session will start with enabled RESH arrow key bindings!")
fmt.Println("RESH arrow key bindings: ENABLED (in " + shell + ")")
} else {
fmt.Println("SUCCESSFULLY DISABLED the RESH arrow key bindings GLOBALLY (in " + shell + ") " +
"- every new (" + shell + ") session will start with " + shell + " default arrow key bindings!")
fmt.Println("RESH arrow key bindings: DISABLED (in " + shell + ")")
}
return nil
}
@ -175,19 +142,7 @@ func enableDisableControlRBindingGlobally(value bool) status.Code {
fmt.Println("Error reading config", err)
return status.Fail
}
if config.BindControlR == value {
if value {
fmt.Println("The RESH control+R binding is ALREADY GLOBALLY ENABLED for all future shell sessions - nothing to do - exiting.")
} else {
fmt.Println("The RESH control+R binding is ALREADY GLOBALLY DISABLED for all future shell sessions - nothing to do - exiting.")
}
return status.Fail
}
if value {
fmt.Println("ENABLING the RESH arrow key bindings GLOBALLY ...")
} else {
fmt.Println("DISABLING the RESH arrow key bindings GLOBALLY ...")
}
if config.BindControlR != value {
config.BindControlR = value
f, err := os.Create(configPath)
@ -200,12 +155,11 @@ func enableDisableControlRBindingGlobally(value bool) status.Code {
fmt.Println("Error: Failed to encode and write the config values to hdd. error:", err)
return status.Fail
}
}
if value {
fmt.Println("SUCCESSFULLY ENABLED the RESH arrow key bindings GLOBALLY " +
"- every new shell session will start with enabled RESH CLI control+R binding!")
fmt.Println("RESH SEARCH app Ctrl+R binding: ENABLED")
} else {
fmt.Println("SUCCESSFULLY DISABLED the RESH arrow key bindings GLOBALLY " +
"- every new shell session will start with your orignal control+R key binding!")
fmt.Println("RESH SEARCH app Ctrl+R binding: DISABLED")
}
return status.Success
}

@ -43,15 +43,11 @@ func Execute(ver, com string) status.Code {
rootCmd.AddCommand(enableCmd)
enableCmd.AddCommand(enableArrowKeyBindingsCmd)
enableCmd.AddCommand(enableArrowKeyBindingsGlobalCmd)
enableCmd.AddCommand(enableControlRBindingCmd)
enableCmd.AddCommand(enableControlRBindingGlobalCmd)
rootCmd.AddCommand(disableCmd)
disableCmd.AddCommand(disableArrowKeyBindingsCmd)
disableCmd.AddCommand(disableArrowKeyBindingsGlobalCmd)
disableCmd.AddCommand(disableControlRBindingCmd)
disableCmd.AddCommand(disableControlRBindingGlobalCmd)
rootCmd.AddCommand(completionCmd)
completionCmd.AddCommand(completionBashCmd)

@ -66,7 +66,7 @@ func SendInspectMsg(m msg.InspectMsg, port string) msg.MultiResponse {
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal("resh-daemon is not running :(")
log.Fatal("resh-daemon is not running - try restarting this terminal")
}
defer resp.Body.Close()

@ -1,7 +0,0 @@
port = 2627
sesswatchPeriodSeconds = 120
sesshistInitHistorySize = 1000
debug = true
bindArrowKeysBash = false
bindArrowKeysZsh = true
bindControlR = true

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

@ -36,7 +36,7 @@ func SendRecallRequest(r records.SlimRecord, port string) (string, bool) {
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal("resh-daemon is not running :(")
log.Fatal("resh-daemon is not running - try restarting this terminal")
}
defer resp.Body.Close()
@ -71,7 +71,7 @@ func SendRecord(r records.Record, port, path string) {
client := &http.Client{}
_, err = client.Do(req)
if err != nil {
log.Fatal("resh-daemon is not running :(")
log.Fatal("resh-daemon is not running - try restarting this terminal")
}
}

@ -193,64 +193,67 @@ fi
__resh_run_daemon
info="---- Scroll down using arrow keys ----
#####################################
# ____ _____ ____ _ _ #
# | _ \| ____/ ___|| | | | #
# | |_) | _| \___ \| |_| | #
# | _ <| |___ ___) | _ | #
# |_| \_\_____|____/|_| |_| #
# Rich Enhanced Shell History #
#####################################
"
echo "
##########################################################
# #
# SUCCESS - thank you for trying out this project! #
# #
##########################################################
HISTORY
Your resh history will be recorded to '~/.resh_history.json'
Look at it using e.g. following command (you might need to install jq)
$ tail -f ~/.resh_history.json | jq
Your default shell history will stay intact.
SANITIZATION
In sanitized history, all sensitive information is replaced with its SHA256 hashes.
To get a sanitized version of your shell history run:
$ reshctl sanitize
If you would consider supporting my research/thesis by giving me a sanitized version of your history then
please give me some contact info using this form: https://forms.gle/227SoyJ5c2iteKt98
ARROW KEY BINDINGS
Regular stepping through history and prefix search. There might be more features in the future.
They are enabled by default in zsh (and disabled in bash).
Enable/disable them using reshctl command:
$ reshctl enable ... / reshctl disable ...
RESH CLI - SEARCH THE RECORDED HISTORY
RESH CLI searches your history by commands and directories.
info="$info
RESH SEARCH APPLICATION = Redesigned reverse search that actually works
Directories are not in regular shell history. Because of that RESH CLI will only search shell history recorded by this project.
This means that you can enable RESH CLI now and use it as your history grows or you can wait for a little bit.
>>> Launch RESH SEARCH app by pressing CTRL+R <<<
(you will need to restart your teminal first)
Please remember that RESH CLI is still an early prototype.
Search your history by commands.
Host, directories, git remote, and exit status is used to display relevant results first.
RESH CLI tool can be bound to ctrl+R (recommended) or executed directly.
At first, the search application will use the standard shell history without context.
All history recorded from now on will have context which will by the RESH SEARCH app.
Enable/disable ctrl+R binding for THIS shell session:
Enable/disable Ctrl+R binding using reshctl command:
$ reshctl enable ctrl_r_binding
$ reshctl disable ctrl_r_binding
Enable/disable for FUTURE shell sessions:
$ reshctl enable ctrl_r_binding_global
$ reshctl disable ctrl_r_binding_global
ARROW KEY BINDINGS = Slightly better arrow key bindings for zsh
Run the RESH CLI tool as a one-off:
$ resh
Arrow keys behave as you are used to. Plus prefix search and the history is fully deduplicated.
They are enabled by default in zsh (and disabled in bash because they are slow in bash).
CHECK FOR UPDATES
To check for (and install) updates use:
Enable/disable arrow key bindings using reshctl command:
$ reshctl enable arrow_key_bindings
$ reshctl disable arrow_key_bindings
CHECK FOR UPDATES
To check for (and install) updates use reshctl command:
$ reshctl update
WARNING
It's recommended to RESTART all open terminal windows
HISTORY
Your resh history will be recorded to '~/.resh_history.json'
Look at it using e.g. following command (you might need to install jq)
$ tail -f ~/.resh_history.json | jq
ISSUES & FEEDBACK
ISSUES & FEEDBACK
Please report issues to: https://github.com/curusarn/resh/issues
Feedback and suggestions are also very welcome!
Feedback and suggestions are very welcome!
"
if [ -z "${__RESH_VERSION:-}" ]; then info="$info
##############################################################
# #
# Finish the installation by RESTARTING this terminal! #
# #
##############################################################
"
fi
info="$info
---- Close this by pressing Q ----"
echo "$info" | less

@ -32,7 +32,7 @@ __resh_nop() {
__resh_bind_control_R() {
if [ "${__RESH_control_R_bind_enabled-0}" != 0 ]; then
echo "Error: Can't enable control R binding because it is already enabled!"
echo "Error: Can't enable Ctrl+R binding because it is already enabled!"
return 1
fi
bindfunc --revert '\C-r' __resh_widget_control_R_compat
@ -83,11 +83,11 @@ __resh_unbind_arrows() {
__resh_unbind_control_R() {
if [ "${__RESH_control_R_bind_enabled-0}" != 1 ]; then
echo "Error: Can't disable control R binding because it is not enabled!"
echo "Error: Can't disable Ctrl+R binding because it is not enabled!"
return 1
fi
if [ -z "${__RESH_bindfunc_revert_control_R_bind+x}" ]; then
echo "Warn: Couldn't revert control R binding because 'revert command' is empty."
echo "Warn: Couldn't revert Ctrl+R binding because 'revert command' is empty."
else
eval "$__RESH_bindfunc_revert_control_R_bind"
fi
@ -109,7 +109,7 @@ __resh_unbind_all() {
resh() {
local buffer
local git_remote; git_remote="$(git remote get-url origin 2>/dev/null)"
buffer=$(resh-cli --sessionID "$__RESH_SESSION_ID" --host "$HOST" --pwd "$PWD" --gitOriginRemote "$git_remote")
buffer=$(resh-cli --sessionID "$__RESH_SESSION_ID" --host "$__RESH_HOST" --pwd "$PWD" --gitOriginRemote "$git_remote")
status_code=$?
if [ $status_code = 111 ]; then
# execute

@ -89,14 +89,14 @@ if [ -z "${__RESH_INIT_DONE+x}" ]; then
__resh_reset_variables
if [ "$__RESH_SHELL" = bash ] ; then
[ "$(resh-config --key BindArrowKeysBash)" = true ] && reshctl enable arrow_key_bindings
[ "$(resh-config --key BindArrowKeysBash)" = true ] && __resh_bind_arrows
elif [ "$__RESH_SHELL" = zsh ] ; then
[ "$(resh-config --key BindArrowKeysZsh)" = true ] && reshctl enable arrow_key_bindings
[ "$(resh-config --key BindArrowKeysZsh)" = true ] && __resh_bind_arrows
else
echo "RESH error: unknown shell (init)"
echo "$__RESH_SHELL"
fi
[ "$(resh-config --key BindControlR)" = true ] && reshctl enable ctrl_r_binding
[ "$(resh-config --key BindControlR)" = true ] && __resh_bind_control_R
__RESH_INIT_DONE=1
fi

@ -101,7 +101,7 @@ __resh_widget_control_R() {
local status_code
local git_remote; git_remote="$(git remote get-url origin 2>/dev/null)"
BUFFER=$(resh-cli --sessionID "$__RESH_SESSION_ID" --host "$HOST" --pwd "$PWD" --gitOriginRemote "$git_remote" --query "$BUFFER")
BUFFER=$(resh-cli --sessionID "$__RESH_SESSION_ID" --host "$__RESH_HOST" --pwd "$PWD" --gitOriginRemote "$git_remote" --query "$BUFFER")
status_code=$?
if [ $status_code = 111 ]; then
# execute
@ -123,7 +123,7 @@ __resh_widget_control_R() {
BUFFER="$PREVBUFFER"
else
echo "$BUFFER" >| ~/.resh/cli_last_run_out.txt
echo "# RESH cli failed - sorry for the inconvinience (error output was saved to ~/.resh/cli_last_run_out.txt)"
echo "# RESH SEARCH APP failed - sorry for the inconvinience (error output was saved to ~/.resh/cli_last_run_out.txt)"
BUFFER="$PREVBUFFER"
fi
CURSOR=${#BUFFER}

Loading…
Cancel
Save