mirror of
https://github.com/logseq/logseq.git
synced 2026-05-20 19:02:23 +00:00
Also fix zsh eval support by replacing `_logseq "$@"` with `compdef _logseq logseq` so `eval "$(logseq completion zsh)"` works in ~/.zshrc without the "_arguments: can only be called from completion function" error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
275 lines
7.8 KiB
Bash
275 lines
7.8 KiB
Bash
# Auto-generated by `logseq completion bash` — do not edit manually.
|
|
|
|
# --- dynamic helpers ---
|
|
|
|
_logseq_json_names_bash() {
|
|
python3 -c "
|
|
import sys, json
|
|
field = sys.argv[1]
|
|
try:
|
|
data = json.load(sys.stdin)
|
|
if isinstance(data, list):
|
|
for item in data:
|
|
v = item.get(field)
|
|
if isinstance(v, str) and v:
|
|
print(v)
|
|
except Exception:
|
|
pass
|
|
" "$1" 2>/dev/null
|
|
}
|
|
|
|
_logseq_current_graph_bash() {
|
|
local i
|
|
for (( i = 1; i < ${#COMP_WORDS[@]}; i++ )); do
|
|
if [[ "${COMP_WORDS[i]}" == '--graph' && -n "${COMP_WORDS[i+1]}" ]]; then
|
|
printf '%s' "${COMP_WORDS[i+1]}"
|
|
return
|
|
fi
|
|
done
|
|
}
|
|
|
|
_logseq_graphs_bash() {
|
|
logseq graph list --output json 2>/dev/null | _logseq_json_names_bash name
|
|
}
|
|
|
|
_logseq_pages_bash() {
|
|
logseq list page --graph "$1" --output json 2>/dev/null | _logseq_json_names_bash title
|
|
}
|
|
|
|
_logseq_queries_bash() {
|
|
logseq query list --graph "$1" --output json 2>/dev/null | _logseq_json_names_bash name
|
|
}
|
|
|
|
_logseq_compadd_lines() {
|
|
local cur="$1" source_fn="$2"; shift 2
|
|
while IFS= read -r item; do
|
|
[[ "$item" == "$cur"* ]] && COMPREPLY+=( "$item" )
|
|
done < <("$source_fn" "$@")
|
|
}
|
|
|
|
# --- generated helpers ---
|
|
|
|
_logseq_is_value_opt() {
|
|
case "$1" in
|
|
--blocks|--blocks-file|--cardinality|--config|--content|--created-after|--data-dir|--fields|--file|--graph|--id|--input|--inputs|--level|--limit|--name|--offset|--order|--output|--page|--pos|--query|--remove-properties|--remove-tags|--shell|--sort|--status|--target-id|--target-page|--target-uuid|--timeout-ms|--type|--update-properties|--update-tags|--updated-after|--uuid)
|
|
return 0 ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
_logseq_cmd_and_subcmd() {
|
|
local i skip=0
|
|
__cmd='' __subcmd=''
|
|
for (( i = 1; i < COMP_CWORD; i++ )); do
|
|
local w="${COMP_WORDS[i]}"
|
|
if (( skip )); then skip=0; continue; fi
|
|
if [[ "$w" == -* ]]; then
|
|
_logseq_is_value_opt "$w" && skip=1
|
|
continue
|
|
fi
|
|
if [[ -z "$__cmd" ]]; then
|
|
__cmd="$w"
|
|
elif [[ -z "$__subcmd" ]]; then
|
|
__subcmd="$w"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# --- option wordlists ---
|
|
|
|
_logseq_opts_for() {
|
|
local cmd="$1" subcmd="$2"
|
|
local opts="--help -h --version --config --graph --data-dir --timeout-ms --output --verbose"
|
|
|
|
case "$cmd" in
|
|
completion) opts+=' --shell' ;;
|
|
doctor) opts+=' --dev-script' ;;
|
|
graph)
|
|
case "$subcmd" in
|
|
list) opts+=' ' ;;
|
|
create) opts+=' ' ;;
|
|
switch) opts+=' ' ;;
|
|
remove) opts+=' ' ;;
|
|
validate) opts+=' ' ;;
|
|
info) opts+=' ' ;;
|
|
export) opts+=' --file --type' ;;
|
|
import) opts+=' --type --input' ;;
|
|
esac
|
|
;;
|
|
list)
|
|
case "$subcmd" in
|
|
page) opts+=' --created-after --updated-after --limit --offset --fields --journal-only --order --include-hidden --expand --sort --include-journal' ;;
|
|
tag) opts+=' --limit --offset --include-built-in --fields --order --with-extends --expand --with-properties --sort' ;;
|
|
property) opts+=' --limit --offset --include-built-in --fields --order --with-type --expand --sort --with-classes' ;;
|
|
esac
|
|
;;
|
|
query)
|
|
opts+=' --name --inputs --query'
|
|
case "$subcmd" in
|
|
list) opts+=' ' ;;
|
|
esac
|
|
;;
|
|
remove)
|
|
case "$subcmd" in
|
|
block) opts+=' --id --uuid' ;;
|
|
page) opts+=' --name' ;;
|
|
tag) opts+=' --name --id' ;;
|
|
property) opts+=' --name --id' ;;
|
|
esac
|
|
;;
|
|
server)
|
|
case "$subcmd" in
|
|
list) opts+=' ' ;;
|
|
status) opts+=' ' ;;
|
|
start) opts+=' ' ;;
|
|
stop) opts+=' ' ;;
|
|
restart) opts+=' ' ;;
|
|
esac
|
|
;;
|
|
show) opts+=' --linked-references --page --level --id --uuid' ;;
|
|
upsert)
|
|
case "$subcmd" in
|
|
block) opts+=' --blocks-file --target-page --content --remove-tags --target-uuid --pos --target-id --update-tags --status --update-properties --id --blocks --uuid --remove-properties' ;;
|
|
page) opts+=' --remove-tags --page --update-tags --update-properties --id --remove-properties' ;;
|
|
tag) opts+=' --name --id' ;;
|
|
property) opts+=' --name --public --type --hide --id --cardinality' ;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
printf '%s' "$opts"
|
|
}
|
|
|
|
# --- main function ---
|
|
|
|
_logseq() {
|
|
local cur prev
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
COMPREPLY=()
|
|
|
|
local __cmd __subcmd
|
|
_logseq_cmd_and_subcmd
|
|
|
|
# --- Option value completion ---
|
|
case "$prev" in
|
|
--blocks-file)
|
|
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
return ;;
|
|
|
|
--target-page)
|
|
local graph
|
|
graph="$(_logseq_current_graph_bash)"
|
|
[[ -n "$graph" ]] && _logseq_compadd_lines "$cur" _logseq_pages_bash "$graph"
|
|
return ;;
|
|
|
|
--config)
|
|
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
return ;;
|
|
|
|
--file)
|
|
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
return ;;
|
|
|
|
--pos)
|
|
COMPREPLY=( $(compgen -W 'first-child last-child sibling' -- "$cur") )
|
|
return ;;
|
|
|
|
--type)
|
|
COMPREPLY=( $(compgen -W 'default number date datetime checkbox url node json string' -- "$cur") )
|
|
return ;;
|
|
|
|
--page)
|
|
local graph
|
|
graph="$(_logseq_current_graph_bash)"
|
|
[[ -n "$graph" ]] && _logseq_compadd_lines "$cur" _logseq_pages_bash "$graph"
|
|
return ;;
|
|
|
|
--output)
|
|
COMPREPLY=( $(compgen -W 'human json edn' -- "$cur") )
|
|
return ;;
|
|
|
|
--data-dir)
|
|
COMPREPLY=( $(compgen -d -- "$cur") )
|
|
return ;;
|
|
|
|
--status)
|
|
COMPREPLY=( $(compgen -W 'todo doing done now later wait waiting backlog canceled cancelled in-review in-progress' -- "$cur") )
|
|
return ;;
|
|
|
|
--graph)
|
|
_logseq_compadd_lines "$cur" _logseq_graphs_bash
|
|
return ;;
|
|
|
|
--order)
|
|
COMPREPLY=( $(compgen -W 'asc desc' -- "$cur") )
|
|
return ;;
|
|
|
|
--input)
|
|
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
return ;;
|
|
|
|
--cardinality)
|
|
COMPREPLY=( $(compgen -W 'one many' -- "$cur") )
|
|
return ;;
|
|
|
|
--shell)
|
|
COMPREPLY=( $(compgen -W 'zsh bash' -- "$cur") )
|
|
return ;;
|
|
|
|
--name)
|
|
if [[ "$__cmd" == 'remove' && "$__subcmd" == 'page' ]]; then
|
|
local graph
|
|
graph="$(_logseq_current_graph_bash)"
|
|
[[ -n "$graph" ]] && _logseq_compadd_lines "$cur" _logseq_pages_bash "$graph"
|
|
fi
|
|
if [[ "$__cmd" == 'query' ]]; then
|
|
local graph
|
|
graph="$(_logseq_current_graph_bash)"
|
|
[[ -n "$graph" ]] && _logseq_compadd_lines "$cur" _logseq_queries_bash "$graph"
|
|
fi
|
|
return ;;
|
|
|
|
--sort)
|
|
if [[ "$__cmd" == 'list' && "$__subcmd" == 'page' ]]; then
|
|
COMPREPLY=( $(compgen -W 'title created-at updated-at' -- "$cur") )
|
|
return
|
|
fi
|
|
if [[ "$__cmd" == 'list' && "$__subcmd" == 'tag' ]]; then
|
|
COMPREPLY=( $(compgen -W 'name title' -- "$cur") )
|
|
return
|
|
fi
|
|
if [[ "$__cmd" == 'list' && "$__subcmd" == 'property' ]]; then
|
|
COMPREPLY=( $(compgen -W 'name title' -- "$cur") )
|
|
return
|
|
fi
|
|
return ;;
|
|
esac
|
|
|
|
# --- Flag / positional completion ---
|
|
if [[ "$cur" == -* ]]; then
|
|
# shellcheck disable=SC2046
|
|
COMPREPLY=( $(compgen -W "$(_logseq_opts_for "$__cmd" "$__subcmd")" -- "$cur") )
|
|
return
|
|
fi
|
|
|
|
if [[ -z "$__cmd" ]]; then
|
|
COMPREPLY=( $(compgen -W 'completion doctor graph list query remove server show upsert' -- "$cur") )
|
|
return
|
|
fi
|
|
|
|
if [[ -z "$__subcmd" ]]; then
|
|
case "$__cmd" in
|
|
graph) COMPREPLY=( $(compgen -W 'list create switch remove validate info export import' -- "$cur") ) ;;
|
|
list) COMPREPLY=( $(compgen -W 'page tag property' -- "$cur") ) ;;
|
|
query) COMPREPLY=( $(compgen -W 'list' -- "$cur") ) ;;
|
|
remove) COMPREPLY=( $(compgen -W 'block page tag property' -- "$cur") ) ;;
|
|
server) COMPREPLY=( $(compgen -W 'list status start stop restart' -- "$cur") ) ;;
|
|
upsert) COMPREPLY=( $(compgen -W 'block page tag property' -- "$cur") ) ;;
|
|
esac
|
|
return
|
|
fi
|
|
}
|
|
|
|
complete -F _logseq logseq
|