From 3b01025006c63ad54b6bca9af40c5cb1636c3093 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 31 Mar 2021 23:31:05 -0400 Subject: [PATCH] Hack together a quick way to execute using local bindirs (#1) --- Makefile | 8 ++++++-- bin/, | 25 +++++++++++++++++++++++++ functions | 6 ++++++ zsh-completions/_comma | 17 +++++++++++++++++ zshrc | 2 ++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100755 bin/, create mode 100644 zsh-completions/_comma diff --git a/Makefile b/Makefile index 241b9e9..7809810 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,15 @@ excludes = -I Makefile -I README.md -symlinks = $(shell find . \( ! -iname "Makefile" ! -iname "README.md" ! -iname ".*" ! -path "./.git/*" ! -path "./zsh/*" ! -path "./nvim/*" ! -iname "nvim" \) | sed 's|./||') +symlinks = $(shell find . -maxdepth 1 \( ! -iname "Makefile" ! -iname "README.md" ! -iname ".*" ! -name "bin" ! -iname "nvim" \) | sed 's|./||') .PHONY: $(symlinks) nvim all: install -install: plug-vim $(symlinks) +install: install-bin plug-vim $(symlinks) + +install-bin: + mkdir -p $$HOME/bin + cp bin/* $$HOME/bin nvim: mkdir -p ~/.config/nvim diff --git a/bin/, b/bin/, new file mode 100755 index 0000000..785848e --- /dev/null +++ b/bin/, @@ -0,0 +1,25 @@ +#!/bin/bash + +function find-local-bin { + local readonly prefix=$1; shift + local bin_dir="$prefix-bin" + local found_bin_dir="" + + current_dir=$(pwd) + found_bin_dir=$current_dir/$bin_dir + while [ ! -d $found_bin_dir ]; do + if [[ $current_dir == $HOME ]]; then + found_bin_dir=$HOME/bin + break + fi + + current_dir=$(realpath "$current_dir/..") + found_bin_dir=$current_dir/$bin_dir + done + + echo $found_bin_dir +} + +dir=$(find-local-bin aet) + +exec $dir/$@ diff --git a/functions b/functions index cf964b5..54481b8 100644 --- a/functions +++ b/functions @@ -7,6 +7,12 @@ function aws-profile { fi } +function aet-bin-exec { + local readonly script=$1; shift + + ./aet-bin/$script $@ +} + function fix-permissions { find . -type d -print0 | xargs -0 chmod 0755 find . -type f -print0 | xargs -0 chmod 0644 diff --git a/zsh-completions/_comma b/zsh-completions/_comma new file mode 100644 index 0000000..a2b1beb --- /dev/null +++ b/zsh-completions/_comma @@ -0,0 +1,17 @@ +#compdef , +local bin_dir="aet-bin" +local found_bin_dir="" + +current_dir=$(pwd) +found_bin_dir=$current_dir/$bin_dir +while [ ! -d $found_bin_dir ]; do + if [[ $current_dir == $HOME ]]; then + found_bin_dir=$HOME/bin + break + fi + + current_dir=$(realpath "$current_dir/..") + found_bin_dir=$current_dir/$bin_dir +done + +_files -g "^," -W $found_bin_dir diff --git a/zshrc b/zshrc index f3f06ac..a4402e0 100644 --- a/zshrc +++ b/zshrc @@ -48,7 +48,9 @@ if which direnv > /dev/null; then fi # completion +fpath=($HOME/.zsh-completions $fpath) autoload -U compinit +autoload bashcompinit && bashcompinit compinit setopt completeinword zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'