update reshctl version to use output package

pull/184/head
Simon Let 3 years ago
parent 5e0af13e62
commit baf7cdedc5
  1. 24
      README.md
  2. 4
      cmd/collect/main.go
  3. 18
      cmd/control/cmd/version.go
  4. 4
      cmd/postcollect/main.go
  5. 4
      cmd/session-init/main.go
  6. 28
      internal/output/output.go

@ -17,15 +17,15 @@ Context-based replacement/enhancement for zsh and bash shell history
<!-- Better zsh history --> <!-- Better zsh history -->
<!-- PWD Directory --> <!-- PWD Directory -->
**Search your history by commands and get relevant results based on current directory, git repo, exit status, and host.** **Search your history by commands or arguments and get relevant results based on current directory, git repo, exit status, and device.**
## Installation ## Installation
### Prerequisites ### Prerequisites
Standard stuff: `bash(4.3+)`, `curl`, `tar`, ... Nohup
Bash completions will only work if you have `bash-completion` installed Standard stuff: `bash(4.3+)`, `curl`, `tar`, ...
MacOS: `coreutils` (`brew install coreutils`) MacOS: `coreutils` (`brew install coreutils`)
@ -62,7 +62,7 @@ reshctl update
This is the most important part of this project. This is the most important part of this project.
RESH SEARCH app 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 device, directories, git remote, and exit status to show you relevant results first.
All this context is not in the regular shell history. RESH records shell history with context to use it when searching. All this context is not in the regular shell history. RESH records shell history with context to use it when searching.
@ -74,7 +74,7 @@ Eventually most of your history will have context and RESH SEARCH app will get m
![resh search app](img/screen-resh-cli-v2-7.png) ![resh search app](img/screen-resh-cli-v2-7.png)
Without a query, RESH SEARCH app shows you the latest history based on the current context (host, directory, git). Without a query, RESH SEARCH app shows you the latest history based on the current context (device, directory, git).
![resh search app](img/screen-resh-cli-v2-7-no-query.png) ![resh search app](img/screen-resh-cli-v2-7-no-query.png)
@ -99,13 +99,15 @@ reshctl disable ctrl_r_binding
### View the recorded history ### View the recorded history
Resh history is saved to `~/.resh_history.json` FIXME: redo/update this section
Resh history is saved to: `~/.resh_history.json`
Each line is a JSON that represents one executed command line. Each line is a versioned JSON that represents one executed command line.
This is how I view it `tail -f ~/.resh_history.json | jq` or `jq < ~/.resh_history.json`. This is how I view it `tail -f ~/.resh_history.json | jq` or `jq < ~/.resh_history.json`.
You can install `jq` using your favourite package manager or you can use other JSON parser to view the history. You can install `jq` using your favorite package manager or you can use other JSON parser to view the history.
![screenshot](img/screen.png) ![screenshot](img/screen.png)
@ -115,13 +117,13 @@ You can install `jq` using your favourite package manager or you can use other J
### Q: I use bash on macOS and resh doesn't work ### Q: I use bash on macOS and resh doesn't work
**A:** You have to add `[ -f ~/.bashrc ] && . ~/.bashrc` to your `~/.bash_profile`. **A:** Add line `[ -f ~/.bashrc ] && . ~/.bashrc` to your `~/.bash_profile`.
**Long Answer:** Under macOS bash shell only loads `~/.bash_profile` because every shell runs as login shell. I will definitely work around this in the future but since this doesn't affect many people I decided to not solve this issue at the moment. **Long Answer:** Under macOS bash shell only loads `~/.bash_profile` because every shell runs as login shell.
## Issues and ideas ## Issues and ideas
Please do create issues if you encounter any problems or if you have a suggestions: https://github.com/curusarn/resh/issues Please do create issues if you encounter any problems or if you have suggestions: https://github.com/curusarn/resh/issues
## Uninstallation ## Uninstallation

@ -69,11 +69,11 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if *requireVersion != "" && *requireVersion != version { if *requireVersion != "" && *requireVersion != version {
out.FatalVersionMismatch(version, *requireVersion) out.FatalTerminalVersionMismatch(version, *requireVersion)
} }
if *requireRevision != "" && *requireRevision != commit { if *requireRevision != "" && *requireRevision != commit {
// this is only relevant for dev versions so we can reuse FatalVersionMismatch() // this is only relevant for dev versions so we can reuse FatalVersionMismatch()
out.FatalVersionMismatch("revision "+commit, "revision "+*requireVersion) out.FatalTerminalVersionMismatch("revision "+commit, "revision "+*requireVersion)
} }
time, err := strconv.ParseFloat(*time_, 64) time, err := strconv.ParseFloat(*time_, 64)

@ -3,7 +3,7 @@ package cmd
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@ -22,27 +22,19 @@ var versionCmd = &cobra.Command{
commitEnv := getEnvVarWithDefault("__RESH_REVISION", "<unknown>") commitEnv := getEnvVarWithDefault("__RESH_REVISION", "<unknown>")
printVersion("This terminal session", versionEnv, commitEnv) printVersion("This terminal session", versionEnv, commitEnv)
// TODO: use output.Output.Error... for these
resp, err := getDaemonStatus(config.Port) resp, err := getDaemonStatus(config.Port)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "\nERROR: Resh-daemon didn't respond - it's probably not running.\n\n") out.ErrorDaemonNotRunning(err)
fmt.Fprintf(os.Stderr, "-> Try restarting this terminal window to bring resh-daemon back up.\n")
fmt.Fprintf(os.Stderr, "-> If the problem persists you can check resh-daemon logs: ~/.resh/daemon.log\n")
fmt.Fprintf(os.Stderr, "-> You can file an issue at: https://github.com/curusarn/resh/issues\n")
return return
} }
printVersion("Currently running daemon", resp.Version, resp.Commit) printVersion("Currently running daemon", resp.Version, resp.Commit)
if version != resp.Version { if version != resp.Version {
fmt.Fprintf(os.Stderr, "\nWARN: Resh-daemon is running in different version than is installed now - it looks like something went wrong during resh update.\n\n") out.ErrorDaemonVersionMismatch(version, resp.Version)
fmt.Fprintf(os.Stderr, "-> Kill resh-daemon and then launch a new terminal window to fix that.\n")
fmt.Fprintf(os.Stderr, " $ pkill resh-daemon\n")
fmt.Fprintf(os.Stderr, "-> You can file an issue at: https://github.com/curusarn/resh/issues\n")
return return
} }
if version != versionEnv { if version != versionEnv {
fmt.Fprintf(os.Stderr, "\nWARN: This terminal session was started with different resh version than is installed now - it looks like you updated resh and didn't restart this terminal.\n\n") out.ErrorTerminalVersionMismatch(version, versionEnv)
fmt.Fprintf(os.Stderr, "-> Restart this terminal window to fix that.\n")
return return
} }
@ -69,7 +61,7 @@ func getDaemonStatus(port int) (msg.StatusResponse, error) {
return mess, err return mess, err
} }
defer resp.Body.Close() defer resp.Body.Close()
jsn, err := ioutil.ReadAll(resp.Body) jsn, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
out.Fatal("Error while reading 'daemon /status' response", err) out.Fatal("Error while reading 'daemon /status' response", err)
} }

@ -57,11 +57,11 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if *requireVersion != "" && *requireVersion != version { if *requireVersion != "" && *requireVersion != version {
out.FatalVersionMismatch(version, *requireVersion) out.FatalTerminalVersionMismatch(version, *requireVersion)
} }
if *requireRevision != "" && *requireRevision != commit { if *requireRevision != "" && *requireRevision != commit {
// this is only relevant for dev versions so we can reuse FatalVersionMismatch() // this is only relevant for dev versions so we can reuse FatalVersionMismatch()
out.FatalVersionMismatch("revision "+commit, "revision "+*requireVersion) out.FatalTerminalVersionMismatch("revision "+commit, "revision "+*requireVersion)
} }
timeAfter, err := strconv.ParseFloat(*rta, 64) timeAfter, err := strconv.ParseFloat(*rta, 64)

@ -49,11 +49,11 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if *requireVersion != "" && *requireVersion != version { if *requireVersion != "" && *requireVersion != version {
out.FatalVersionMismatch(version, *requireVersion) out.FatalTerminalVersionMismatch(version, *requireVersion)
} }
if *requireRevision != "" && *requireRevision != commit { if *requireRevision != "" && *requireRevision != commit {
// this is only relevant for dev versions so we can reuse FatalVersionMismatch() // this is only relevant for dev versions so we can reuse FatalVersionMismatch()
out.FatalVersionMismatch("revision "+commit, "revision "+*requireVersion) out.FatalTerminalVersionMismatch("revision "+commit, "revision "+*requireVersion)
} }
rec := recordint.SessionInit{ rec := recordint.SessionInit{

@ -55,6 +55,14 @@ It looks like you updated resh and didn't restart this terminal.
` `
var msgDaemonVersionMismatch = `Resh-daemon is running in different version than is installed now.
It looks like something went wrong during resh update.
-> Kill resh-daemon and then launch a new terminal window to fix that: pkill resh-daemon
-> You can create an issue at: https://github.com/curusarn/resh/issues
`
func (f *Output) ErrorDaemonNotRunning(err error) { func (f *Output) ErrorDaemonNotRunning(err error) {
fmt.Fprintf(os.Stderr, "%s: %s", f.ErrPrefix, msgDaemonNotRunning) fmt.Fprintf(os.Stderr, "%s: %s", f.ErrPrefix, msgDaemonNotRunning)
f.Logger.Error("Daemon is not running", zap.Error(err)) f.Logger.Error("Daemon is not running", zap.Error(err))
@ -65,7 +73,7 @@ func (f *Output) FatalDaemonNotRunning(err error) {
f.Logger.Fatal("Daemon is not running", zap.Error(err)) f.Logger.Fatal("Daemon is not running", zap.Error(err))
} }
func (f *Output) ErrorVersionMismatch(installedVer, terminalVer string) { func (f *Output) ErrorTerminalVersionMismatch(installedVer, terminalVer string) {
fmt.Fprintf(os.Stderr, "%s: %s\n\n(installed version: %s, this terminal version: %s)", fmt.Fprintf(os.Stderr, "%s: %s\n\n(installed version: %s, this terminal version: %s)",
f.ErrPrefix, msgVersionMismatch, installedVer, terminalVer) f.ErrPrefix, msgVersionMismatch, installedVer, terminalVer)
f.Logger.Fatal("Version mismatch", f.Logger.Fatal("Version mismatch",
@ -73,10 +81,26 @@ func (f *Output) ErrorVersionMismatch(installedVer, terminalVer string) {
zap.String("terminal", terminalVer)) zap.String("terminal", terminalVer))
} }
func (f *Output) FatalVersionMismatch(installedVer, terminalVer string) { func (f *Output) FatalTerminalVersionMismatch(installedVer, terminalVer string) {
fmt.Fprintf(os.Stderr, "%s: %s\n(installed version: %s, this terminal version: %s)\n", fmt.Fprintf(os.Stderr, "%s: %s\n(installed version: %s, this terminal version: %s)\n",
f.ErrPrefix, msgVersionMismatch, installedVer, terminalVer) f.ErrPrefix, msgVersionMismatch, installedVer, terminalVer)
f.Logger.Fatal("Version mismatch", f.Logger.Fatal("Version mismatch",
zap.String("installed", installedVer), zap.String("installed", installedVer),
zap.String("terminal", terminalVer)) zap.String("terminal", terminalVer))
} }
func (f *Output) ErrorDaemonVersionMismatch(installedVer, daemonVer string) {
fmt.Fprintf(os.Stderr, "%s: %s\n(installed version: %s, running daemon version: %s)\n",
f.ErrPrefix, msgDaemonVersionMismatch, installedVer, daemonVer)
f.Logger.Error("Version mismatch",
zap.String("installed", installedVer),
zap.String("daemon", daemonVer))
}
func (f *Output) FatalDaemonVersionMismatch(installedVer, daemonVer string) {
fmt.Fprintf(os.Stderr, "%s: %s\n(installed version: %s, running daemon version: %s)\n",
f.ErrPrefix, msgDaemonVersionMismatch, installedVer, daemonVer)
f.Logger.Fatal("Version mismatch",
zap.String("installed", installedVer),
zap.String("daemon", daemonVer))
}

Loading…
Cancel
Save