mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-10 04:27:45 -05:00
Virtual machine monitor programs (e.g. QEMU, Cloud Hypervisor) expose guest consoles as PTYs. With this patch, foot can access these guest consoles. Usually, the program used for accessing these PTYs is screen, but screen is barely developed, doesn't support resizing, and has a bunch of other unrelated stuff going on. It would be nice to have a terminal emulator that properly supported opening an existing PTY. The VMM controls the master end of the PTY, so to the other end (in this case foot), it just behaves like any application running in a directly-opened PTY, and all that's needed is to change foot's code to support opening an existing PTY rather than creating one. Co-authored-by: tanto <tanto@ccc.ac>
89 lines
2.7 KiB
Text
89 lines
2.7 KiB
Text
# Bash completion script for foot
|
|
_foot()
|
|
{
|
|
COMPREPLY=()
|
|
|
|
local cur prev flags word commands match previous_words i offset
|
|
flags=(
|
|
"--app-id"
|
|
"--check-config"
|
|
"--config"
|
|
"--font"
|
|
"--fullscreen"
|
|
"--help"
|
|
"--hold"
|
|
"--log-colorize"
|
|
"--log-level"
|
|
"--log-no-syslog"
|
|
"--login-shell"
|
|
"--maximized"
|
|
"--override"
|
|
"--print-pid"
|
|
"--pty"
|
|
"--server"
|
|
"--term"
|
|
"--title"
|
|
"--version"
|
|
"--window-size-pixels"
|
|
"--window-size-chars"
|
|
"--working-directory"
|
|
)
|
|
flags="${flags[@]}"
|
|
cur=${COMP_WORDS[COMP_CWORD]}
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
|
|
# Check if positional argument is completed
|
|
previous_words=( "${COMP_WORDS[@]}" )
|
|
unset previous_words[-1]
|
|
commands=$(compgen -c | grep -vFx "$(compgen -k)" | grep -vE '^([.:[]|foot)$' | sort -u)
|
|
i=0
|
|
for word in "${previous_words[@]}" ; do
|
|
match=$(printf "$commands" | grep -Fx "$word" 2>/dev/null)
|
|
if [[ ! -z "$match" ]] ; then
|
|
if [[ ${COMP_WORDS[i-1]} =~ ^(--app-id|--config|--font|--log-level|--pty|--term|--title|--window-size-pixels|--window-size-chars|--working-directory)$ ]] ; then
|
|
(( i++ ))
|
|
continue
|
|
fi
|
|
# Positional argument found
|
|
offset=$i
|
|
fi
|
|
(( i++ ))
|
|
done
|
|
|
|
if [[ ! -z "$offset" ]] ; then
|
|
# Depends on bash_completion being available
|
|
declare -F _command_offset >/dev/null || return 1
|
|
_command_offset $offset
|
|
return 0
|
|
elif [[ ${cur} == --* ]] ; then
|
|
COMPREPLY=( $(compgen -W "${flags}" -- ${cur}) )
|
|
return 0
|
|
fi
|
|
|
|
case "$prev" in
|
|
--config|--print-pid|--server|-[cps])
|
|
compopt -o default ;;
|
|
--working-directory|-D)
|
|
compopt -o dirnames ;;
|
|
--term|-t)
|
|
command -v toe > /dev/null || return 1
|
|
COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 !~ /[+]/ {print $1}')" -- ${cur}) ) ;;
|
|
--font|-f)
|
|
command -v fc-list > /dev/null || return 1
|
|
COMPREPLY=( $(compgen -W "$(fc-list : family | sed 's/,/\n/g' | uniq | tr -d ' ')" -- ${cur}) ) ;;
|
|
--log-level|-d)
|
|
COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) ) ;;
|
|
--log-colorize|-l)
|
|
COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) ) ;;
|
|
--app-id|--help|--override|--pty|--title|--version|--window-size-chars|--window-size-pixels|--check-config|-[ahoTvWwC])
|
|
# Don't autocomplete for these flags
|
|
: ;;
|
|
*)
|
|
# Complete commands from $PATH
|
|
COMPREPLY=( $(compgen -c -- ${cur}) ) ;;
|
|
esac
|
|
|
|
return 0
|
|
}
|
|
|
|
complete -F _foot foot
|