From 916d2621d513e7ef42089e9554fc9a11e82cb80f Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Tue, 14 Feb 2023 08:57:55 +0200 Subject: [PATCH] feat: more autocompletions --- completions/_prj | 15 +++++++++++++++ completions/_src | 22 ++++++++++++++++++++++ functions.sh | 3 ++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 completions/_prj create mode 100755 completions/_src diff --git a/completions/_prj b/completions/_prj new file mode 100755 index 00000000..56b8542e --- /dev/null +++ b/completions/_prj @@ -0,0 +1,15 @@ +#compdef prj +prjpath="$(wd path dv)" +names=($(ls $prjpath)) + +if [[ -z $names ]]; then + return 1 +fi + +out=() + +for i in $names; do + out+=("$i:$prjpath/$i") +done + +_describe 'project' out diff --git a/completions/_src b/completions/_src new file mode 100755 index 00000000..5e5ff361 --- /dev/null +++ b/completions/_src @@ -0,0 +1,22 @@ +#compdef src rc +dfpath="$(wd path df)" + +out=() + +__read_dir() { + dir="$1" + res=($(find $1 -print | sed "s/${1//\//\\/}\///")) + + for i in $res; do + # echo "checking path: $1/$i" + if [[ -f "$1/$i" ]] && [[ ! $i =~ \b\.git\b ]]; then + out+=("$i") + fi + done +} + +cd "$dfpath" +__read_dir . + +_describe 'dotfile' out +# echo $out diff --git a/functions.sh b/functions.sh index d10f8a58..b7c68df1 100644 --- a/functions.sh +++ b/functions.sh @@ -53,7 +53,6 @@ ucase() { echo "$@" | tr '[:lower:]' '[:upper:]' } - int_res() { # get all but last c=$(($# - 1)) @@ -262,3 +261,5 @@ docker-volume-cd() { autoload _docker-exec autoload _docker-volume-path +autoload _prj +autoload _src