Skip to content

Commit

Permalink
Merge pull request #6 from lzambarda/develop
Browse files Browse the repository at this point in the history
fix(zsh): send request with correct arguments
  • Loading branch information
lzambarda authored Nov 2, 2022
2 parents 8060a20 + 7274da4 commit 20582f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions graph/naive/naive.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//nolint:godox // Okay for now.
// Package naive contains a simplistic implementation of a suggestion graph.
// Nothing too fancy.
//
//nolint:godox // Okay for now.
package naive

import (
Expand All @@ -21,8 +22,9 @@ type edge struct {
To *node `json:"t"`
}

//nolint:govet // Prefer this order of memory efficiency.
// cmd -> node.
//
//nolint:govet // Prefer this order of memory efficiency.
type node struct {
id int
edges map[string]*edge
Expand All @@ -38,7 +40,7 @@ func (c *cmdEdge) String() string {
}

func (n *node) getSortedEdges() []*cmdEdge {
var sorted = make([]*cmdEdge, 0, len(n.edges))
sorted := make([]*cmdEdge, 0, len(n.edges))
for cmd, e := range n.edges {
sorted = append(sorted, &cmdEdge{cmd, e.Hits})
}
Expand All @@ -49,7 +51,7 @@ func (n *node) getSortedEdges() []*cmdEdge {
}

func (n *node) getBestCommand() string {
var max = -1
max := -1
var best string
for cmd, e := range n.edges {
if e.Hits > max {
Expand Down Expand Up @@ -82,6 +84,7 @@ func (w walker) progress(next *walkerNode) walker {
// Graph is a naive implementation of a heuristic system.
// The zero value of this structure cannot be used. Please use NewGraph to
// obtain a valid one.
//
//nolint:govet // Prefer this order of memory efficiency.
type Graph struct {
// wd -> node
Expand Down
5 changes: 3 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func handleConnection(c net.Conn, g Graph) {
}
result, err := ProcessCommand(args, g)
if err != nil {
println(err)
fmt.Println(err)
return
}
if result != "" {
_, err = c.Write([]byte(result))
if err != nil {
println(err)
fmt.Println(err)
}
}
}
Expand All @@ -109,6 +109,7 @@ func ProcessCommand(args []string, g Graph) (result string, err error) {
if len(args) == 0 {
return "", errors.New("missing command")
}

switch args[0] {
case "track":
if len(args) != 4 {
Expand Down
2 changes: 1 addition & 1 deletion zsh/hbt.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ add-zsh-hook preexec _hbt_track
# or complete words, that are before cursor only (like in tcsh)
function _hbt_search () {
if [[ -z ${LBUFFER// } ]]; then
suggestion=$(echo -n "hint\n$$\n$(pwd)\n$1" | nc localhost $HBT_PORT)
suggestion=$(echo -n "hint\n$$\n$(pwd)" | nc localhost $HBT_PORT)
POSTDISPLAY="${suggestion#$BUFFER}"
_zsh_autosuggest_highlight_reset
_zsh_autosuggest_highlight_apply
Expand Down

0 comments on commit 20582f8

Please sign in to comment.