diff --git a/.envrc b/.envrc index 4606812..574ad12 100644 --- a/.envrc +++ b/.envrc @@ -7,4 +7,8 @@ fi use flake PATH_add bin dotenv ./.env +if [ -f ./bin/completion ]; then + source ./bin/completion +fi +watch_dir bin watch_dir nix diff --git a/Makefile b/Makefile index 7474c2e..1290bfb 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ help: ## Display this help screen @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +SHELL := /bin/bash BIN_DIR := bin API_NAME := acmcsuf-api CLI_NAME := acmcsuf-cli @@ -31,6 +32,8 @@ build: generate ## Build the api and cli binaries @mkdir -p $(BIN_DIR) go build -ldflags "-X main.Version=$(VERSION)" -o $(BIN_DIR)/$(API_NAME) ./cmd/$(API_NAME) go build -ldflags "-X cli.Version=$(VERSION)" -o $(BIN_DIR)/$(CLI_NAME) ./cmd/$(CLI_NAME) + cd $(BIN_DIR) && ./$(CLI_NAME) completion bash > completion + chmod +x $(BIN_DIR)/completion vet: ## Vet all go files go vet ./... diff --git a/nix/shell.nix b/nix/shell.nix index 82165a2..8cd9e59 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -13,6 +13,8 @@ go-swag, cobra-cli, go-tools, + bash, + bash-completion, }: mkShell { packages = [ @@ -29,9 +31,26 @@ mkShell { jq go-swag cobra-cli - ]; + bash + bash-completion + ]; shellHook = '' + # Shell auto complete + source ${bash-completion}/etc/profile.d/bash_completion.sh + + if [ ! -d bin ]; then + mkdir bin # Nix blows up if bin isnt here + fi + + COMPLETION_FILE=./bin/completion + if [ -f "$COMPLETION_FILE" ]; then + source "$COMPLETION_FILE" + else + echo "Note: Your cli has no autocomplete, remember to source completion in ./bin or restart the shell when it is generated!" + fi + + export CGO_ENABLED=0 # cgo compiler flags cause issues with delve when using Nix if [ ! -f .env ]; then echo ".env file not found! Creating one from .env.example for you..."