Commit af26039
Eric Bower
·
2026-09-19 19:20:52 -0400 EDT
parent d557546
feat(yash): completions for pa, task, zmx
4 files changed,
+237,
-3
+96,
-0
| ... | ... | @@ -0,0 +1,96 @@ | |
| 1 | + | # Completion script for the "pa" command. | |
| 2 | + | # https://github.com/biox/pa or similar simple password manager | |
| 3 | + | ||
| 4 | + | function completion/pa { | |
| 5 | + | typeset OPTIONS ARGOPT PREFIX | |
| 6 | + | OPTIONS=( #># | |
| 7 | + | "--help; show usage information" | |
| 8 | + | ) #<# | |
| 9 | + | ||
| 10 | + | command -f completion//parseoptions -e | |
| 11 | + | case $ARGOPT in | |
| 12 | + | (-) | |
| 13 | + | command -f completion//completeoptions | |
| 14 | + | ;; | |
| 15 | + | ("") | |
| 16 | + | if [ ${WORDS[#]} -le 1 ]; then | |
| 17 | + | command -f completion/pa::completecmd | |
| 18 | + | else | |
| 19 | + | typeset pacmd="${WORDS[2]}" | |
| 20 | + | case $pacmd in | |
| 21 | + | (g|git|g*) | |
| 22 | + | WORDS=(git "${WORDS[3,-1]}") | |
| 23 | + | command -f completion//reexecute | |
| 24 | + | return | |
| 25 | + | ;; | |
| 26 | + | esac | |
| 27 | + | ||
| 28 | + | command -f completion//getoperands | |
| 29 | + | case $pacmd in | |
| 30 | + | (a|add|a*) | |
| 31 | + | if [ ${WORDS[#]} -eq 1 ]; then | |
| 32 | + | command -f completion/pa::categories | |
| 33 | + | command -f completion/pa::passwords | |
| 34 | + | fi | |
| 35 | + | ;; | |
| 36 | + | (d|del|d*|e|edit|e*|s|show|s*) | |
| 37 | + | if [ ${WORDS[#]} -eq 1 ]; then | |
| 38 | + | command -f completion/pa::passwords | |
| 39 | + | fi | |
| 40 | + | ;; | |
| 41 | + | (l|list|l*) | |
| 42 | + | if [ ${WORDS[#]} -eq 1 ]; then | |
| 43 | + | command -f completion/pa::categories | |
| 44 | + | fi | |
| 45 | + | ;; | |
| 46 | + | (m|move|m*) | |
| 47 | + | if [ ${WORDS[#]} -eq 1 ]; then | |
| 48 | + | command -f completion/pa::passwords | |
| 49 | + | elif [ ${WORDS[#]} -eq 2 ]; then | |
| 50 | + | command -f completion/pa::categories | |
| 51 | + | command -f completion/pa::passwords | |
| 52 | + | fi | |
| 53 | + | ;; | |
| 54 | + | esac | |
| 55 | + | fi | |
| 56 | + | ;; | |
| 57 | + | esac | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | function completion/pa::completecmd { | |
| 61 | + | complete -P "$PREFIX" -D "Add a password entry" add | |
| 62 | + | complete -P "$PREFIX" -D "Delete a password entry" del | |
| 63 | + | complete -P "$PREFIX" -D "Edit a password entry" edit | |
| 64 | + | complete -P "$PREFIX" -D "Run git command in password dir" git | |
| 65 | + | complete -P "$PREFIX" -D "List all entries in a category" list | |
| 66 | + | complete -P "$PREFIX" -D "Show password for an entry" show | |
| 67 | + | complete -P "$PREFIX" -D "Rename a password entry" move | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | function completion/pa::passwords { | |
| 71 | + | typeset padir="${PA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/pa}/passwords" | |
| 72 | + | if [ -d "$padir" ]; then | |
| 73 | + | typeset list | |
| 74 | + | typeset IFS=' | |
| 75 | + | ' | |
| 76 | + | list=($(find -L "$padir" -name .git -prune -o -name "*.age" -type f -print 2>/dev/null | sed -e "s#^${padir}/##" -e "s/\.age$//" | sort)) | |
| 77 | + | if [ ${list[#]} -gt 0 ]; then | |
| 78 | + | complete -P "$PREFIX" -- "$list" | |
| 79 | + | fi | |
| 80 | + | fi | |
| 81 | + | } | |
| 82 | + | ||
| 83 | + | function completion/pa::categories { | |
| 84 | + | typeset padir="${PA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/pa}/passwords" | |
| 85 | + | if [ -d "$padir" ]; then | |
| 86 | + | typeset list | |
| 87 | + | typeset IFS=' | |
| 88 | + | ' | |
| 89 | + | list=($(find -L "$padir" -mindepth 1 -name .git -prune -o -type d -print 2>/dev/null | sed -e "s#^${padir}/##" | sort)) | |
| 90 | + | if [ ${list[#]} -gt 0 ]; then | |
| 91 | + | complete -P "$PREFIX" -S / -T -- "$list" | |
| 92 | + | fi | |
| 93 | + | fi | |
| 94 | + | } | |
| 95 | + | ||
| 96 | + | # kak: filetype=sh |
+7,
-0
| ... | ... | @@ -0,0 +1,7 @@ | |
| 1 | + | # Completion script for the "pp" command (alias for pa). | |
| 2 | + | ||
| 3 | + | function completion/pp { | |
| 4 | + | command -f completion//reexecute pa | |
| 5 | + | } | |
| 6 | + | ||
| 7 | + | # kak: filetype=sh |
+130,
-0
| ... | ... | @@ -0,0 +1,130 @@ | |
| 1 | + | # Completion script for the "task" (Taskfile / go-task) command. | |
| 2 | + | # https://taskfile.dev | |
| 3 | + | ||
| 4 | + | function completion/task { | |
| 5 | + | typeset OPTIONS ARGOPT PREFIX | |
| 6 | + | OPTIONS=( #># | |
| 7 | + | "a --list-all; list tasks with or without a description" | |
| 8 | + | "c --color; colored output (default true)" | |
| 9 | + | "--completion:; generate shell completion script" | |
| 10 | + | "C: --concurrency:; limit number of tasks to run concurrently" | |
| 11 | + | "d: --dir:; set directory of execution" | |
| 12 | + | "--disable-fuzzy; disable fuzzy matching for task names" | |
| 13 | + | "n --dry; compile and print tasks without executing them" | |
| 14 | + | "x --exit-code; pass-through exit code of task command" | |
| 15 | + | "--experiments; list available experiments" | |
| 16 | + | "F --failfast; stop all tasks if one fails" | |
| 17 | + | "f --force; force execution even when task is up-to-date" | |
| 18 | + | "g --global; run global Taskfile from home directory" | |
| 19 | + | "h --help; show help" | |
| 20 | + | "i --init; create a new Taskfile.yml in current folder" | |
| 21 | + | "--insecure; allow downloading Taskfiles over insecure connections" | |
| 22 | + | "--interactive; prompt for missing required variables" | |
| 23 | + | "I: --interval:; interval to watch for changes" | |
| 24 | + | "j --json; format task list as JSON" | |
| 25 | + | "l --list; list tasks with description" | |
| 26 | + | "--nested; nest namespaces when listing as JSON" | |
| 27 | + | "--no-status; ignore status when listing as JSON" | |
| 28 | + | "o: --output:; set output style (interleaved, group, prefixed)" | |
| 29 | + | "--output-group-begin:; message template before grouped output" | |
| 30 | + | "--output-group-end:; message template after grouped output" | |
| 31 | + | "--output-group-error-only; swallow output from successful tasks" | |
| 32 | + | "p --parallel; execute tasks in parallel" | |
| 33 | + | "s --silent; disable echoing" | |
| 34 | + | "--sort:; sort order (default, alphanumeric, none)" | |
| 35 | + | "--status; exit non-zero if tasks are not up-to-date" | |
| 36 | + | "--summary; show summary about a task" | |
| 37 | + | "t: --taskfile:; choose Taskfile to run" | |
| 38 | + | "v --verbose; enable verbose mode" | |
| 39 | + | "--version; show version" | |
| 40 | + | "w --watch; enable watch mode" | |
| 41 | + | "y --yes; assume yes to all prompts" | |
| 42 | + | ) #<# | |
| 43 | + | ||
| 44 | + | # If -- is already present in WORDS, subsequent words are CLI_ARGS; do not complete | |
| 45 | + | typeset w | |
| 46 | + | for w in "$WORDS"; do | |
| 47 | + | if [ "$w" = "--" ]; then | |
| 48 | + | return | |
| 49 | + | fi | |
| 50 | + | done | |
| 51 | + | ||
| 52 | + | command -f completion//parseoptions -en | |
| 53 | + | case $ARGOPT in | |
| 54 | + | (-) | |
| 55 | + | command -f completion//completeoptions | |
| 56 | + | ;; | |
| 57 | + | (d|--dir) | |
| 58 | + | complete -P "$PREFIX" -d | |
| 59 | + | ;; | |
| 60 | + | (t|--taskfile) | |
| 61 | + | complete -P "$PREFIX" -f | |
| 62 | + | ;; | |
| 63 | + | (o|--output) | |
| 64 | + | complete -P "$PREFIX" -D "Interleaved output" interleaved | |
| 65 | + | complete -P "$PREFIX" -D "Grouped output" group | |
| 66 | + | complete -P "$PREFIX" -D "Prefixed output" prefixed | |
| 67 | + | ;; | |
| 68 | + | (--sort) | |
| 69 | + | complete -P "$PREFIX" -D "Default sort order" default | |
| 70 | + | complete -P "$PREFIX" -D "Alphanumeric sort" alphanumeric | |
| 71 | + | complete -P "$PREFIX" -D "No sorting" none | |
| 72 | + | ;; | |
| 73 | + | (--completion) | |
| 74 | + | complete -P "$PREFIX" -- bash zsh fish powershell | |
| 75 | + | ;; | |
| 76 | + | (*) | |
| 77 | + | command -f completion/task::tasks | |
| 78 | + | ;; | |
| 79 | + | esac | |
| 80 | + | } | |
| 81 | + | ||
| 82 | + | function completion/task::tasks { | |
| 83 | + | # Extract directory, taskfile, or global flags from WORDS so task can locate the Taskfile | |
| 84 | + | typeset task_args | |
| 85 | + | task_args=() | |
| 86 | + | typeset i=2 | |
| 87 | + | while [ $i -le ${WORDS[#]} ]; do | |
| 88 | + | case "${WORDS[i]}" in | |
| 89 | + | (-g|--global) | |
| 90 | + | task_args=("$task_args" "${WORDS[i]}") | |
| 91 | + | ;; | |
| 92 | + | (-d|--dir|-t|--taskfile) | |
| 93 | + | if [ $((i+1)) -le ${WORDS[#]} ]; then | |
| 94 | + | task_args=("$task_args" "${WORDS[i]}" "${WORDS[i+1]}") | |
| 95 | + | i=$((i+1)) | |
| 96 | + | fi | |
| 97 | + | ;; | |
| 98 | + | (--dir=*|--taskfile=*) | |
| 99 | + | task_args=("$task_args" "${WORDS[i]}") | |
| 100 | + | ;; | |
| 101 | + | (-d*|-t*) | |
| 102 | + | task_args=("$task_args" "${WORDS[i]}") | |
| 103 | + | ;; | |
| 104 | + | esac | |
| 105 | + | i=$((i+1)) | |
| 106 | + | done | |
| 107 | + | ||
| 108 | + | # Extract tasks with descriptions | |
| 109 | + | typeset line name desc | |
| 110 | + | typeset IFS=' | |
| 111 | + | ' | |
| 112 | + | for line in $(task "$task_args" --list-all 2>/dev/null | sed -n 's/^\* \([^:]*\):[[:space:]]*\(.*\)/\1\t\2/p'); do | |
| 113 | + | name="${line%% *}" | |
| 114 | + | desc="${line#* }" | |
| 115 | + | if [ "$desc" ]; then | |
| 116 | + | complete -P "$PREFIX" -D "$desc" -- "$name" | |
| 117 | + | else | |
| 118 | + | complete -P "$PREFIX" -- "$name" | |
| 119 | + | fi | |
| 120 | + | done | |
| 121 | + | ||
| 122 | + | # Also complete any task aliases or tasks without descriptions | |
| 123 | + | typeset tasks | |
| 124 | + | tasks=($(task "$task_args" --silent --list-all 2>/dev/null)) | |
| 125 | + | if [ ${tasks[#]} -gt 0 ]; then | |
| 126 | + | complete -P "$PREFIX" -- "$tasks" | |
| 127 | + | fi | |
| 128 | + | } | |
| 129 | + | ||
| 130 | + | # kak: filetype=sh |
+4,
-3
| ... | ... | @@ -19,6 +19,7 @@ export PA_LENGTH=20 | |
| 19 | 19 | export PA_PATTERN="A-Za-z0-9_-" | |
| 20 | 20 | export LANG="en_US.UTF-8" | |
| 21 | 21 | export LESS="-FRX" | |
| 22 | + | export YASH_LOADPATH="${XDG_CONFIG_HOME:-$HOME/.config}/yash${YASH_LOADPATH:+:$YASH_LOADPATH}" | |
| 22 | 23 | ||
| 23 | 24 | alias pushall='git remote | xargs -I R git push R' | |
| 24 | 25 | alias sway='XDG_CURRENT_DESKTOP=sway sway' |
| ... | ... | @@ -56,8 +57,8 @@ if test -n "${ZMX_SESSION:-}"; then | |
| 56 | 57 | export YASH_PS1="[$ZMX_SESSION] ${YASH_PS1}" | |
| 57 | 58 | fi | |
| 58 | 59 | ||
| 59 | - | # if command -v zmx >/dev/null 2>&1; then | |
| 60 | - | # eval "$(zmx completions bash)" | |
| 61 | - | # fi | |
| 60 | + | if command -v zmx >/dev/null 2>&1; then | |
| 61 | + | eval "$(zmx completions yash)" | |
| 62 | + | fi | |
| 62 | 63 | ||
| 63 | 64 | # kak: filetype=sh |