mirror of
https://github.com/frappe/bench.git
synced 2025-01-04 22:55:25 +00:00
Autocompletion for bench (zsh and bash)
This commit is contained in:
parent
9062a75c15
commit
9b80abffc0
@ -1,11 +1,37 @@
|
|||||||
_setup_bench_tab_completion () {
|
_bench_completion() {
|
||||||
if [ -n "$BASH" ] ; then
|
# Complete commands using click bashcomplete
|
||||||
eval "$(_BENCH_COMPLETE=source bench)"
|
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
|
||||||
elif [ -n "$ZSH_VERSION" ]; then
|
COMP_CWORD=$COMP_CWORD \
|
||||||
autoload bashcompinit
|
_BENCH_COMPLETE=complete $1 ) )
|
||||||
bashcompinit
|
if [ -d "sites" ]; then
|
||||||
eval "$(_BENCH_COMPLETE=source bench)"
|
# Also add frappe commands if present
|
||||||
fi
|
|
||||||
|
# bench_helper.py expects to be executed from "sites" directory
|
||||||
|
cd sites
|
||||||
|
|
||||||
|
# All frappe commands are subcommands under "bench frappe"
|
||||||
|
# Frappe is only installed in virtualenv "env" so use appropriate python executable
|
||||||
|
COMPREPLY+=( $( COMP_WORDS="bench frappe "${COMP_WORDS[@]:1} \
|
||||||
|
COMP_CWORD=$(($COMP_CWORD+1)) \
|
||||||
|
_BENCH_COMPLETE=complete ../env/bin/python ../apps/frappe/frappe/utils/bench_helper.py ) )
|
||||||
|
|
||||||
|
# If the word before the current cursor position in command typed so far is "--site" then only list sites
|
||||||
|
if [ ${COMP_WORDS[COMP_CWORD-1]} == "--site" ]; then
|
||||||
|
COMPREPLY=( $( ls -d ./*/site_config.json | cut -f 2 -d "/" | xargs echo ) )
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get out of sites directory now
|
||||||
|
cd ..
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_setup_bench_tab_completion
|
# Only support bash and zsh
|
||||||
|
if [ -n "$BASH" ] ; then
|
||||||
|
complete -F _bench_completion -o default bench;
|
||||||
|
elif [ -n "$ZSH_VERSION" ]; then
|
||||||
|
# Use zsh in bash compatibility mode
|
||||||
|
autoload bashcompinit
|
||||||
|
bashcompinit
|
||||||
|
complete -F _bench_completion -o default bench;
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user