Fix: issue #4 and #5 (#6)

- Issue #4: currently there is no official release yet so we cant
download from installer
- I added an installer debugger here to test
(f091dbf13bdf109b631951e2558651f560ca8b84)
- Issue #5: my another library
[fuzzy](https://github.com/versenilvis/fuzzy/) has a logic bug so it
causes crash, fix d479c6cb4d8453e50366c9839daaabb45a98a2df

- Other:
  -  remove unneeded comments (edd9d05fdd16e682b6b416913e2fa9c3f6599956)
  - Add some tests
  - Fix reload crash (3a76e78e655fd8daafb635ec0937667325f75ee4)
- New optimized build command (56a4a815f836271b861f32795d2df3b25a3dffc0)
This commit is contained in:
VERSE
2026-05-23 23:22:04 +07:00
committed by GitHub
parent aafd3cca93
commit d06526cf21
11 changed files with 267 additions and 61 deletions
+19 -7
View File
@@ -2,13 +2,19 @@ package core
import (
"strings"
"sync"
"github.com/versenilvis/iris/integration/shell"
)
var ShellAliases = map[string]string{}
var (
ShellAliases = map[string]string{}
shellAliasesMu sync.RWMutex
)
func GetAlias(name string) (string, bool) {
shellAliasesMu.RLock()
defer shellAliasesMu.RUnlock()
val, ok := ShellAliases[name]
return val, ok
}
@@ -19,9 +25,16 @@ func GetAlias(name string) (string, bool) {
// e.g. Lookup("git checkout ") -> suggests branch names via generator
func Lookup(input string) []Suggestion {
if shell.Current != nil {
ShellAliases = shell.Current.ScanAliases()
aliases := shell.Current.ScanAliases()
shellAliasesMu.Lock()
ShellAliases = aliases
shellAliasesMu.Unlock()
}
shellAliasesMu.RLock()
aliases := ShellAliases
shellAliasesMu.RUnlock()
if input == "" {
return nil
}
@@ -35,13 +48,12 @@ func Lookup(input string) []Suggestion {
// in the future, maybe we will write unit test or using Lookup in another module
// it will be safer because we maybe forget to check it in that module
pathCmds = make(map[string]bool)
scanExternalCommands()
// if you have an alias in your shell config like: alias gca="git commit -a"
// if the first word match it, IRIS will suggest "git commit -a"
if len(tokens) > 1 {
if target, ok := ShellAliases[tokens[0]]; ok {
if target, ok := aliases[tokens[0]]; ok {
aliasTokens := Tokenize(target)
if len(aliasTokens) > 0 && aliasTokens[len(aliasTokens)-1] == "" {
aliasTokens = aliasTokens[:len(aliasTokens)-1]
@@ -52,7 +64,7 @@ func Lookup(input string) []Suggestion {
if len(tokens) == 1 {
query := tokens[0]
results := topLevelSuggestions(query)
results := topLevelSuggestions(query, aliases)
if spec, exists := Registry[query]; exists {
hasTrailingSpace := query != "" && query[len(query)-1] == ' '
@@ -244,10 +256,10 @@ func Lookup(input string) []Suggestion {
return results
}
func topLevelSuggestions(query string) []Suggestion {
func topLevelSuggestions(query string, aliases map[string]string) []Suggestion {
results, seen := []Suggestion{}, make(map[string]bool)
for name, target := range ShellAliases {
for name, target := range aliases {
if !seen[name] && (query == "" || HasPrefix(name, query)) {
results = append(results, Suggestion{
Cmd: target, Desc: "alias: " + name, Icon: "root",
+8 -2
View File
@@ -3,13 +3,19 @@ package core
import (
"os"
"path/filepath"
"sync"
)
var pathCmds = make(map[string]bool)
var (
pathCmds = make(map[string]bool)
pathCmdsOnce sync.Once
)
// scanExternalCommands populates pathCmds with system executables
func scanExternalCommands() {
scanPath()
pathCmdsOnce.Do(func() {
scanPath()
})
}
// scanPath populates pathCmds with all executable files found in path environment variable