Compare commits

..

3 Commits

Author SHA1 Message Date
TorchedSammy 54689b7dd1
docs: add newline after aur badge 2021-12-19 22:41:04 -04:00
TorchedSammy 740adf27f3
docs: change sizes of some headers and link to aur package 2021-12-19 22:40:25 -04:00
TorchedSammy 40578d9d5f
fix: use a rwmutex for aliases map 2021-12-19 22:37:44 -04:00
2 changed files with 20 additions and 7 deletions

View File

@ -31,7 +31,7 @@ it to be.
# Installation # Installation
**NOTE:** Hilbish is currently only officially supported and tested on Linux **NOTE:** Hilbish is currently only officially supported and tested on Linux
### Prebuilt binaries ## Prebuilt binaries
Binaries are provided for the latest commit. Binaries are provided for the latest commit.
**Note that these use Hilbiline, not readline, and may be missing functionality **Note that these use Hilbiline, not readline, and may be missing functionality
@ -44,24 +44,25 @@ Then click on the artifacts drop down, and download artifact for your platform,
like what is highlighted in the screenshot. like what is highlighted in the screenshot.
<br><img src="https://modeus.is-inside.me/KJ0Puceb.png"><br> <br><img src="https://modeus.is-inside.me/KJ0Puceb.png"><br>
### AUR ## AUR
![AUR maintainer](https://img.shields.io/aur/maintainer/hilbish?logo=arch-linux&style=flat-square) [![AUR maintainer](https://img.shields.io/aur/maintainer/hilbish?logo=arch-linux&style=flat-square)](https://aur.archlinux.org/packages/hilbish)
Arch Linux users can install Hilbish from the AUR with the following command: Arch Linux users can install Hilbish from the AUR with the following command:
```sh ```sh
yay -S hilbish yay -S hilbish
``` ```
[![AUR maintainer](https://img.shields.io/aur/maintainer/hilbish?logo=arch-linux&style=flat-square)](https://aur.archlinux.org/packages/hilbish-git)
Or from the latest `master` commit with: Or from the latest `master` commit with:
```sh ```sh
yay -S hilbish-git yay -S hilbish-git
``` ```
### Nixpkgs ## Nixpkgs
Nix/NixOS users can install Hilbish from the central repository, nixpkgs, through the usual ways. Nix/NixOS users can install Hilbish from the central repository, nixpkgs, through the usual ways.
If you're new to nix you should probably read up on how to do that [here](https://nixos.wiki/wiki/Cheatsheet). If you're new to nix you should probably read up on how to do that [here](https://nixos.wiki/wiki/Cheatsheet).
### Manual Build ## Manual Build
#### Prerequisites ### Prerequisites
- [Go 1.16+](https://go.dev) - [Go 1.16+](https://go.dev)
- GNU Readline - GNU Readline

View File

@ -2,6 +2,7 @@ package main
import ( import (
"strings" "strings"
"sync"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
) )
@ -10,16 +11,21 @@ var aliases *hilbishAliases
type hilbishAliases struct { type hilbishAliases struct {
aliases map[string]string aliases map[string]string
mu *sync.RWMutex
} }
// initialize aliases map // initialize aliases map
func NewAliases() *hilbishAliases { func NewAliases() *hilbishAliases {
return &hilbishAliases{ return &hilbishAliases{
aliases: make(map[string]string), aliases: make(map[string]string),
mu: &sync.RWMutex{},
} }
} }
func (h *hilbishAliases) Add(alias, cmd string) { func (h *hilbishAliases) Add(alias, cmd string) {
h.mu.Lock()
defer h.mu.Unlock()
h.aliases[alias] = cmd h.aliases[alias] = cmd
} }
@ -28,10 +34,16 @@ func (h *hilbishAliases) All() map[string]string {
} }
func (h *hilbishAliases) Delete(alias string) { func (h *hilbishAliases) Delete(alias string) {
h.mu.Lock()
defer h.mu.Unlock()
delete(h.aliases, alias) delete(h.aliases, alias)
} }
func (h *hilbishAliases) Resolve(cmdstr string) string { func (h *hilbishAliases) Resolve(cmdstr string) string {
h.mu.RLock()
defer h.mu.RUnlock()
args := strings.Split(cmdstr, " ") args := strings.Split(cmdstr, " ")
for h.aliases[args[0]] != "" { for h.aliases[args[0]] != "" {
alias := h.aliases[args[0]] alias := h.aliases[args[0]]