2022-08-23 16:48:33 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Name: Statique Littérateur
|
|
|
|
# Type: Aucocompletion for STL
|
|
|
|
# file: stl
|
|
|
|
# Folder: /usr/share/bash-completion/completions/
|
|
|
|
# By echolib (XMPP: im@echolib.re)
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
|
|
#------------
|
|
|
|
# funny stats
|
|
|
|
#------------
|
|
|
|
# lines: 265
|
|
|
|
# functions: 10
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#**********************************************************************
|
|
|
|
|
|
|
|
# when arguments are used, do not show again
|
|
|
|
|
|
|
|
|
|
|
|
# Ensure good work dir, source conf, to get max sidebar items, and more
|
|
|
|
if [[ -f ".stl.conf" ]];then
|
|
|
|
source ".stl.conf"
|
|
|
|
|
|
|
|
else
|
|
|
|
nodomain=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Arguments available
|
|
|
|
#======================================================================
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# First argument command
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
_stl_arg1() {
|
|
|
|
if [[ $nodomain ]];then
|
|
|
|
cat <<EOL
|
|
|
|
domain
|
|
|
|
help
|
|
|
|
license
|
|
|
|
log
|
|
|
|
version
|
|
|
|
EOL
|
|
|
|
|
|
|
|
else
|
|
|
|
cat <<EOL
|
|
|
|
check
|
|
|
|
domain
|
|
|
|
edit
|
|
|
|
help
|
|
|
|
license
|
|
|
|
log
|
|
|
|
read
|
|
|
|
sidebar
|
|
|
|
publish
|
|
|
|
remove
|
|
|
|
update
|
|
|
|
version
|
|
|
|
wip
|
|
|
|
EOL
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Specifics for edit and read
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
_stl_arg_editread() {
|
|
|
|
[[ $nodomain ]] && return 0
|
|
|
|
cat << EOL
|
|
|
|
conf
|
|
|
|
sidebar
|
|
|
|
$(_stl_articles)
|
|
|
|
EOL
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Specifics for sidebar
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Second argument for sidebar
|
|
|
|
# ---------------------------
|
|
|
|
_stl_arg_sidebar() {
|
|
|
|
[[ $nodomain ]] && return 0
|
|
|
|
[[ $arg_sidebar_opt ]] && return 0
|
|
|
|
|
|
|
|
cat <<EOL
|
|
|
|
add
|
|
|
|
load
|
|
|
|
create
|
|
|
|
latest
|
|
|
|
oldest
|
|
|
|
EOL
|
|
|
|
arg_sidebar_opt=true
|
|
|
|
}
|
|
|
|
|
|
|
|
# Third argument for sidebar
|
|
|
|
#---------------------------
|
|
|
|
_stl_arg_sidebar_nbr() {
|
|
|
|
[[ $nodomain ]] && return 0
|
|
|
|
[[ $arg_item_nbr ]] && return 0
|
|
|
|
|
|
|
|
for i in `seq 1 $domain_sidebar_items`
|
|
|
|
do
|
|
|
|
echo "$i"
|
|
|
|
done
|
|
|
|
arg_item_nbr=true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Specifics for remove
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
_stl_arg_remove() {
|
|
|
|
cat <<EOL
|
|
|
|
wip
|
|
|
|
www
|
|
|
|
EOL
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Specifics for wip
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Third argument wip
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
_stl_arg_wip_sidebar_nbr() {
|
|
|
|
[[ $nodomain ]] && return 0
|
|
|
|
[[ $arg_sidebar_nbr ]] && return 0
|
|
|
|
|
|
|
|
for i in `seq 1 $domain_sidebar_items`
|
|
|
|
do
|
|
|
|
echo "sidebar=$i"
|
|
|
|
done
|
|
|
|
arg_sidebar_nbr=true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# All .stl articles (with URI)
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
_stl_articles() {
|
|
|
|
[[ $nodomain ]] && return 0
|
|
|
|
[[ $arg_articles ]] && return 0
|
|
|
|
|
|
|
|
find . -type f -name "*.stl" 2>/dev/null \
|
|
|
|
| awk -F"./articles/" '{print $2}'
|
|
|
|
arg_articles=true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Specifics for domain
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Second argument for domain
|
|
|
|
# --------------------------
|
|
|
|
_stl_arg_domain() {
|
|
|
|
if [[ $nodomain ]];then
|
|
|
|
echo 'new'
|
|
|
|
new
|
|
|
|
|
|
|
|
else
|
|
|
|
echo 'edit'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Third argument for convenience domain
|
|
|
|
#--------------------------------------
|
|
|
|
_stl_arg_domain_url() {
|
|
|
|
echo 'https://www.example.com'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Aucocompletion script according to position
|
|
|
|
#======================================================================
|
|
|
|
_stl_completions() {
|
|
|
|
local cur
|
2022-07-20 19:37:21 +02:00
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
|
2022-08-23 16:48:33 +02:00
|
|
|
case $COMP_CWORD in
|
|
|
|
1)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg1)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
2)
|
|
|
|
case "${COMP_WORDS[COMP_CWORD-1]}" in
|
|
|
|
edit|read)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg_editread)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
sidebar)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg_sidebar)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
wip)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_articles)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
domain)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg_domain)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
remove)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg_remove)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_articles)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
3)
|
|
|
|
case "${COMP_WORDS[COMP_CWORD-1]}" in
|
|
|
|
add)
|
|
|
|
# sidebar
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg_sidebar_nbr)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
sidebar)
|
|
|
|
# usually wip sidebar (shortcut for stl sidebar create)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
new)
|
|
|
|
# domain
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg_domain_url)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "${COMP_WORDS[COMP_CWORD-2]}" in
|
|
|
|
wip)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_arg_wip_sidebar_nbr)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
remove)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_articles)" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
COMPREPLY=( $(compgen -W "$(_stl_articles)" -- ${cur}) )
|
2022-07-20 19:37:21 +02:00
|
|
|
return 0
|
2022-08-23 16:48:33 +02:00
|
|
|
;;
|
|
|
|
esac
|
2022-07-20 19:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _stl_completions 'stl'
|