mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-02 04:37:49 +02:00
Add omarchy CLI (#5477)
* Add omarchy CLI * Remove outdated or internal * Add bash completions for command * Add omarchy command documentation * Add missing docs * Correct to what's now right * Fix tests --------- Co-authored-by: David Heinemeier Hansson <david@hey.com>
This commit is contained in:
co-authored by
David Heinemeier Hansson
parent
cdb9694360
commit
d2a4cc0c4d
@@ -0,0 +1,53 @@
|
||||
_omarchy_complete() {
|
||||
COMPREPLY=()
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
local omarchy_path bin_dir
|
||||
omarchy_path=$(command -v omarchy 2>/dev/null) || return 0
|
||||
bin_dir=$(dirname -- "$(readlink -f -- "$omarchy_path" 2>/dev/null || printf '%s' "$omarchy_path")")
|
||||
[[ -d $bin_dir ]] || return 0
|
||||
|
||||
local prefix="omarchy"
|
||||
local i part
|
||||
for ((i = 1; i < COMP_CWORD; i++)); do
|
||||
part="${COMP_WORDS[i]}"
|
||||
[[ -z $part || $part == -* ]] && continue
|
||||
prefix+="-$part"
|
||||
done
|
||||
|
||||
local -A seen=()
|
||||
local candidates=()
|
||||
local file basename rest next
|
||||
|
||||
shopt -s nullglob
|
||||
for file in "$bin_dir/$prefix"-*; do
|
||||
[[ -f $file && -x $file ]] || continue
|
||||
basename="${file##*/}"
|
||||
rest="${basename#"$prefix"-}"
|
||||
next="${rest%%-*}"
|
||||
if [[ -n $next && -z ${seen[$next]:-} ]]; then
|
||||
seen[$next]=1
|
||||
candidates+=("$next")
|
||||
fi
|
||||
done
|
||||
shopt -u nullglob
|
||||
|
||||
if (( COMP_CWORD == 1 )); then
|
||||
candidates+=("commands")
|
||||
fi
|
||||
|
||||
if [[ ${COMP_WORDS[1]:-} == "commands" ]] && (( COMP_CWORD >= 2 )); then
|
||||
candidates+=("--all" "--json" "--markdown" "--check")
|
||||
fi
|
||||
|
||||
if [[ -x $bin_dir/$prefix || ${#candidates[@]} -gt 0 ]]; then
|
||||
candidates+=("--help")
|
||||
fi
|
||||
|
||||
if (( ${#candidates[@]} > 0 )); then
|
||||
local IFS=$'\n'
|
||||
COMPREPLY=($(compgen -W "${candidates[*]}" -- "$cur"))
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _omarchy_complete omarchy
|
||||
@@ -26,3 +26,5 @@ if command -v fzf &> /dev/null; then
|
||||
source /usr/share/fzf/key-bindings.bash
|
||||
fi
|
||||
fi
|
||||
|
||||
source "$OMARCHY_PATH/default/bash/completions"
|
||||
|
||||
Reference in New Issue
Block a user