NixOS-Configs/home/bash_complition.nix
2023-09-23 17:48:37 -05:00

50 lines
1.4 KiB
Nix

{ pkgs, ... }: {
home.file = {
doascomplete = {
enable = true;
target = ".bash_completion.d/doas.sh";
text = ''
_doas()
{
local cur prev words cword split
_init_completion -s || return
local i mode=normal
[[ ''$1 == *doasedit ]] && mode=edit
[[ ''$mode == normal ]] &&
for ((i = 1; i <= cword; i++)); do
if [[ ''${words[i]} != -* ]]; then
local PATH=''$PATH:/sbin:/usr/sbin:/usr/local/sbin
local root_command=''${words[i]}
_command_offset ''$i
return
fi
[[ ''${words[i]} == -@(!(-*)[uUgCp]) ]] &&
((i++))
done
case "''$prev" in
-u)
COMPREPLY=(''$(compgen -u -- "''$cur"))
return
;;
esac
''$split && return
if [[ ''$cur == -* ]]; then
local opts=''$(_parse_help "''$1")
COMPREPLY=(''$(compgen -W ' ''${opts:-''$(_parse_usage "''$1")}' -- "''$cur"))
[[ ''${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
if [[ ''$mode == edit ]]; then
_filedir
fi
} &&
complete -F _doas doas
'';
};
};
}