Skip to content

Commit

Permalink
Remove go TCP client
Browse files Browse the repository at this point in the history
Clean up commands
Fix infinite recursion on hint
Clean up hbt.zsh
Add changelog
Improve Readme
  • Loading branch information
lzambarda committed Apr 11, 2021
1 parent 991a5db commit a5d18f7
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 162 deletions.
57 changes: 57 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# CHANGELOG

{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]
{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups }}
### {{ .Title }}
{{ range .Commits -}}
{{ if not (contains .Subject "<code>") -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }}
{{ end -}}
{{ end -}}
{{ end }}
{{ else }}
{{ range .Unreleased.Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }}
{{ end }}
{{ end -}}

{{- if .Unreleased.NoteGroups -}}
{{ range .Unreleased.NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ if .CommitGroups -}}
{{ range .CommitGroups }}
### {{ .Title }}
{{ range .Commits -}}
{{ if not (contains .Subject "<code>") -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }}
{{ end -}}
{{ end -}}
{{ end }}
{{ else }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
76 changes: 76 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/lzambarda/hbt

options:
commits:
# filters:
# Type:
# - feat
# - add
# - return
# - feature
# - fix
# - perf
# - refactor

commit_groups:
# group_by: Type

title_maps:
feat: Added
Feat: Added
add: Added
Add: Added
feature: New Feature
Feature: New Feature
fix: Fixed
Fix: Fixed
merge: Merged
Merge: Merged
perf: Performance Improvements
Perf: Performance Improvements
Performance Improvements: Performance Improvements
refactor: Code Refactoring
Refactor: Code Refactoring
Update: Code Refactoring

header:
# { header }
# {type}{scope} { subject }
# add(core): new feature to the thing (closes #666)
# We are ignoring paranteses around the scope.
pattern: "^((\\w+)(\\((\\w+)\\))?:?\\s(.+))$"
pattern_maps:
- Subject
- Type
-
- Scope

issues:
prefix:
- #

refs:
actions:
- Closes
- Fixes
- Refs

merges:
pattern: "^Merge branch '(\\w+)'$"
pattern_maps:
- Source

reverts:
pattern: "^Revert \"([\\s\\S]*)\"$"
pattern_maps:
- Header

notes:
keywords:
- BREAKING CHANGE
- IMPORTANT
- important
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
.PHONY: help
help: ## Show this
@grep -E '^[0-9a-zA-Z_-]+:(.*?## .*|[a-z _0-9]+)?$$' Makefile | sort | awk 'BEGIN {FS = ":(.*## |[\t ]*)"}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

NAME:=hbtsrv
BUILD_TAG:=$(shell git describe --tags)
BUILDFLAGS:="-s -w -X internal.Version=$(BUILD_TAG)"
BUILDFLAGS:="-s -w -X github.com/lzambarda/hbt/internal.Version=$(BUILD_TAG)"

.PHONY: dependencies
dependencies: ## Install dependencies requried for development operations.
@go get -u github.com/git-chglog/git-chglog/cmd/git-chglog
@go mod tidy


.PHONY: build
build:
go build -ldflags $(BUILDFLAGS) -o ./bin/$(NAME) ./main.go
@go build -ldflags $(BUILDFLAGS) -o ./bin/$(NAME) ./main.go

run="."
dir="./..."
Expand All @@ -13,3 +23,13 @@ short="-short"
test:
@go test --timeout=40s $(short) $(dir) -run $(run);

.PHONY: changelog
changelog: ## Update the changelog.
@git-chglog > CHANGELOG.md
@echo "Changelog has been updated."


.PHONY: changelog_release
changelog_release: ## Update the changelog with a release tag.
@git-chglog --next-tag $(tag) > CHANGELOG.md
@echo "Changelog has been updated."
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@ A heuristic command suggestion system for zsh.
2. Amend the environment variables in `zsh/hbt.zsh` to match where you store hbt (fancy the PATH?)
3. Make sure that `zsh/hbt.zsh` is loaded by your shell.

## Development

There is a `--debug` flag (or `HBT_DEBUG` env var) which can be used to print extra information.
By default the TCP server runs in the foreground. If you want to work on the same terminal you can use something like `nohup`.
Check out [`zsh/hbt.zsh`](./zsh/hbt.zsh) for an implementation of it.

You can change `HBT_BIN_PATH` to point to the binary in this repo.
It is usually better to run the built binary otherwise `hbt_stop` won't be able to find the running process and terminate it.

## Usage

The zsh bit of hbt talks to a locally spawned TCP server handled by a go binary.
Hbt will track every command that you type and store it into a graph.
Upon pressing TAB with an empty prompty buffer, it will try to hint at a good command, according to your typing history. Shrugs otherwise (seriously).

### Manual interaction with hbt

[`zsh/hbt.zsh`](./zsh/hbt.zsh) provides some functions you can use to interact with a running hbt server.

## Why the mix of go and shell functions?

At first I wanted to developed the whole thing in go, but for tracking and hinting I couldn't find an implementation faster than pure shell commands.
Given that the functions use zsh hooks which are executed at every command, I didn't want this to have a too significant impact on the terminal experience.

## Todo

- [x] Naive graph implementation
Expand All @@ -22,9 +40,10 @@ Upon pressing TAB with an empty prompty buffer, it will try to hint at a good co
This hasn't really been done the proper way, but it works.

- [x] Tests
- [ ] Migrate what can be migrated from zsh to go
- [x] Migrate what can be migrated from zsh to go
- [ ] Benchmarking
- [ ] R/B tree implementation???
- [ ] R/B tree / ngram tree implementation???
- [x] Partial path search
- [ ] Better error catching
- [ ] More dynamic graph parameters (env variables or flags)
- [ ] Do not store sensistive information (is it even possible to detect it?)
59 changes: 0 additions & 59 deletions client/client.go

This file was deleted.

Loading

0 comments on commit a5d18f7

Please sign in to comment.