Skip to content

Commit

Permalink
Merge pull request #184 from curusarn/reduction
Browse files Browse the repository at this point in the history
v3 prerelease
  • Loading branch information
curusarn authored Feb 26, 2023
2 parents 7ae8e34 + e269bd5 commit ebfc456
Show file tree
Hide file tree
Showing 126 changed files with 4,355 additions and 8,558 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v2
- name: Checkout
uses: actions/checkout@v3
with:
go-version: 1.16
fetch-depth: 0

- name: Get Go version
run: echo "GO_VERSION=$(grep '^go ' go.mod | cut -d ' ' -f 2)" >> $GITHUB_ENV && cat $GITHUB_ENV

- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Test
run: go test -v ./...
Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,30 @@ on:
jobs:

goreleaser:
name: Goreleaser
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Checkout submodules
run: git submodule update --init --recursive
- name: Get Go version
run: echo "GO_VERSION=$(grep '^go ' go.mod | cut -d ' ' -f 2)" >> $GITHUB_ENV && cat $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: ${{ env.GO_VERSION }}

- name: Checkout submodules
run: git submodule update --init --recursive

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 5 additions & 3 deletions .github/workflows/sh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up
run: sudo apt-get install -y shellcheck zsh

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Test
run: scripts/test.sh
45 changes: 18 additions & 27 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,55 +76,46 @@ builds:
- arm
- arm64
-
id: "evaluate"
main: ./cmd/evaluate
binary: bin/resh-evaluate
goarch:
- 386
- amd64
- arm
- arm64
-
id: "event"
main: ./cmd/event
binary: bin/resh-event
id: "postcollect"
main: ./cmd/postcollect
binary: bin/resh-postcollect
goarch:
- 386
- amd64
- arm
- arm64
-
id: "inspect"
main: ./cmd/inspect
binary: bin/resh-inspect
id: "session-init"
main: ./cmd/session-init
binary: bin/resh-session-init
goarch:
- 386
- amd64
- arm
- arm64
-
id: "postcollect"
main: ./cmd/postcollect
binary: bin/resh-postcollect
goarch:
id: "install-utils"
main: ./cmd/install-utils
binary: bin/resh-install-utils
goarch:
- 386
- amd64
- arm
- arm64
-
id: "sanitize"
main: ./cmd/sanitize
binary: bin/resh-sanitize
goarch:
id: "generate-uuid"
main: ./cmd/generate-uuid
binary: bin/resh-generate-uuid
goarch:
- 386
- amd64
- arm
- arm64
-
id: "session-init"
main: ./cmd/session-init
binary: bin/resh-session-init
goarch:
id: "get-epochtime"
main: ./cmd/get-epochtime
binary: bin/resh-get-epochtime
goarch:
- 386
- amd64
- arm
Expand Down
29 changes: 19 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
SHELL=/bin/bash
LATEST_TAG=$(shell git describe --tags)
REVISION=$(shell [ -z "$(git status --untracked-files=no --porcelain)" ] && git rev-parse --short=12 HEAD || echo "no_revision")
VERSION="${LATEST_TAG}-DEV"
GOFLAGS=-ldflags "-X main.version=${VERSION} -X main.commit=${REVISION}"
VERSION:="${LATEST_TAG}-$(shell date +%s)"
COMMIT:=$(shell [ -z "$(git status --untracked-files=no --porcelain)" ] && git rev-parse --short=12 HEAD || echo "no_commit")
GOFLAGS=-ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.development=true"

build: submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect\
bin/resh-daemon bin/resh-control bin/resh-config bin/resh-cli\
bin/resh-install-utils bin/resh-generate-uuid bin/resh-get-epochtime

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

# We disable jobserver for the actual installation because we want it to run serially
# Make waits to the daemon process we launch during install and hangs
install: build
scripts/install.sh

# Rebuild binaries and install
# Very useful to ensure that all binaries get new VERSION variable which is used for shell config reloading
clean_install:
make clean
make build
make install

test:
go test -v ./...
go vet ./...
Expand All @@ -21,19 +30,19 @@ rebuild:
make build

clean:
rm -f bin/resh-*
rm -f -- bin/*

uninstall:
# Uninstalling ...
-rm -rf ~/.resh/
-rm -rf -- ~/.resh/

bin/resh-%: cmd/%/*.go pkg/*/*.go cmd/control/cmd/*.go cmd/control/status/status.go
go_files = $(shell find -name '*.go')
bin/resh-%: $(go_files)
grep $@ .goreleaser.yml -q # all build targets need to be included in .goreleaser.yml
go build ${GOFLAGS} -o $@ cmd/$*/*.go

.PHONY: submodules build install rebuild uninstall clean test


submodules: | submodules/bash-preexec/bash-preexec.sh submodules/bash-zsh-compat-widgets/bindfunc.sh
@# sets submodule.recurse to true if unset
@# sets status.submoduleSummary to true if unset
Expand Down
129 changes: 28 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@

![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/curusarn/resh?sort=semver)
![Go test](https://github.com/curusarn/resh/actions/workflows/go.yaml/badge.svg)
![Shell test](https://github.com/curusarn/resh/actions/workflows/sh.yaml/badge.svg)
[![Latest version](https://img.shields.io/github/v/tag/curusarn/resh?sort=semver)](https://github.com/curusarn/resh/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/curusarn/resh)](https://goreportcard.com/report/github.com/curusarn/resh)
[![Go test](https://github.com/curusarn/resh/actions/workflows/go.yaml/badge.svg)](https://github.com/curusarn/resh/actions/workflows/go.yaml)
[![Shell test](https://github.com/curusarn/resh/actions/workflows/sh.yaml/badge.svg)](https://github.com/curusarn/resh/actions/workflows/sh.yaml)

# Rich Enhanced Shell History
# RESH

Context-based replacement for `zsh` and `bash` shell history.

**Full-text search your shell history.**
Relevant results are displayed first based on current directory, git repo, and exit status.

Context-based replacement/enhancement for zsh and bash shell history
<!-- Contextual shell history -->
<!-- Contextual bash history -->
<!-- Contextual zsh history -->
Expand All @@ -17,114 +22,36 @@ Context-based replacement/enhancement for zsh and bash shell history
<!-- Better zsh history -->
<!-- PWD Directory -->

**Search your history by commands and get relevant results based on current directory, git repo, exit status, and host.**

## Installation

### Prerequisites

Standard stuff: `bash(4.3+)`, `curl`, `tar`, ...

Bash completions will only work if you have `bash-completion` installed
## Install

MacOS: `coreutils` (`brew install coreutils`)

### Simplest installation

Run this command.
Install RESH with one command:

```sh
curl -fsSL https://raw.githubusercontent.com/curusarn/resh/master/scripts/rawinstall.sh | bash
curl -fsSL https://raw.githubusercontent.com/curusarn/resh/master/scripts/rawinstall.sh | sh
```

### Simple installation

Run

```shell
git clone https://github.com/curusarn/resh.git
cd resh && scripts/rawinstall.sh
```

### Update

Check for updates and update

```sh
reshctl update
```

## Roadmap

[Overview of the features of the project](./roadmap.md)

## RESH SEARCH application

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.
ℹ️ You will need to have `curl` and `tar` installed.

All this context is not in the regular shell history. RESH records shell history with context to use it when searching.
More options on [Installation page ⇗](./installation.md)

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.
## Search your history

![resh search app](img/screen-resh-cli-v2-7-init.png)
Press <kbd>Ctrl</kbd> + <kbd>R</kbd> to search:

Eventually most of your history will have context and RESH SEARCH app will get more useful.

![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).

![resh search app](img/screen-resh-cli-v2-7-no-query.png)

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
```
<img width="906" alt="RESH search app screenshot" src="https://user-images.githubusercontent.com/10132717/221371937-d4ba64e0-ede6-4bfa-8b74-529252bf73a3.png">

### In-app key bindings

- Type to search/filter
- Up/Down or Ctrl+P/Ctrl+N to select results
- Right to paste selected command onto the command line so you can edit it before execution
- Enter to execute
- Ctrl+C/Ctrl+D to quit
- Ctrl+G to abort and paste the current query onto the command line
- Ctrl+R to switch between RAW and NORMAL mode

### View the recorded history

Resh history is saved to `~/.resh_history.json`

Each line is a JSON that represents one executed command line.

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.

![screenshot](img/screen.png)

*Recorded metadata will be reduced to only include useful information in the future.*

## Known issues

### Q: I use bash on macOS and resh doesn't work

**A:** You have to add `[ -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.

## Issues and ideas

Please do create issues if you encounter any problems or if you have a suggestions: https://github.com/curusarn/resh/issues
- Type to search
- <kbd>Up</kbd> / <kbd>Down</kbd> or <kbd>Ctrl</kbd> + <kbd>P</kbd> / <kbd>Ctrl</kbd> + <kbd>N</kbd> to select results
- <kbd>Enter</kbd> to execute selected command
- <kbd>Right</kbd> to paste selected command onto the command line so you can edit it before execution
- <kbd>Ctrl</kbd> + <kbd>C</kbd> or <kbd>Ctrl</kbd> + <kbd>D</kbd> to quit
- <kbd>Ctrl</kbd> + <kbd>G</kbd> to abort and paste the current query onto the command line
- <kbd>Ctrl</kbd> + <kbd>R</kbd> to search without context (toggle)

## Uninstallation
## Issues & ideas

You can uninstall this project at any time by running `rm -rf ~/.resh/`.
Find help on [Troubleshooting page ⇗](./troubleshooting.md)

You won't lose any recorded history by removing `~/.resh` directory because history is saved in `~/.resh_history.json`.
Problem persists? [Create an issue ⇗](https://github.com/curusarn/resh/issues)
Loading

0 comments on commit ebfc456

Please sign in to comment.