dotfiles/.config/fish/completions/lxc-attach.fish

65 lines
2.8 KiB
Fish

complete -c lxc-attach -f
# function __private_generate_piped_combinations
# ...
# end
function __private_concat_completions -d "Generate completions that are specified as pipe-separated values from stdin source"
set -l fish_trace on
type -q awk || return
set -l token (commandline -ct)
breakpoint
# We want to filter out suggestions the user has already entered.
set -l extant (string trim --chars=' \'"' -- $token | string split '|')
set -l filter (printf '^%s$\n' (printf '%s\n' $extant | string escape --style=regex) | string join '|')
# Work around the insanity of trying to read from stdin within a function. Note that we can't place the
# `read` call in between () to capture the output because that breaks its connection to stdin.
while read -l line
echo $line
end | string match -er '.' | string match -rv -- $filter | string replace -r '^' -- (string replace -rf -- '^(.+),.*$' '$1,' $token; or echo "")
return
# Verified compatible with bsd awk and gnu awk
awk '
{
lines[NR-1] = $0
}
END {
n = NR
for (k = 1; k <= n; k++) {
generate_permutations(lines, n, k)
}
}
function generate_permutations(arr, total_len, perm_len, prefix, _i, _swap) {
if (perm_len == 0) {
print prefix
return
}
for (_i = 0; _i < total_len; _i++) {
_swap = arr[total_len-1]; arr[total_len-1] = arr[_i]; arr[_i] = _swap
generate_permutations(arr, total_len-1, perm_len-1, prefix arr[total_len-1] (perm_len == 1 ? "" : "|"))
arr[_i] = arr[total_len-1]; arr[total_len-1] = _swap
}
}
'
end
complete -c lxc-attach -n '__fish_use_subcommand' -s n -l name -r -d 'Name of the container' -a "(lxc-ls --running | string split ' ')"
# complete -c lxc-attach -n '__fish_use_subcommand' -s e -l elevated-privileges -d 'Use elevated privileges instead of those of the container' -a '(printf "foo\nbar\nbaz" | __private_concat_completions)'
# Common options
complete -c lxc-attach -n '__fish_use_subcommand' -s o -l logfile -r -F -d 'Output log to FILE instead of stderr'
complete -c lxc-attach -n '__fish_use_subcommand' -s l -l logpriority -r -d 'Set log priority to LEVEL' -a 'FATAL ALERT CRIT WARN ERROR NOTICE INFO DEBUG TRACE'
complete -c lxc-attach -n '__fish_use_subcommand' -s q -l quiet -d "Don't produce any output"
complete -c lxc-attach -n '__fish_use_subcommand' -s P -l lxcpath -r -F -d 'Use specified container path'
complete -c lxc-attach -n '__fish_use_subcommand' -l help -d 'Show help information'
complete -c lxc-attach -n '__fish_use_subcommand' -l usage -d 'Show a short usage message'
complete -c lxc-attach -n '__fish_use_subcommand' -l version -d 'Print the version number'