nix/home/program/bash/module/Su.nix

34 lines
668 B
Nix
Raw Normal View History

2024-04-06 03:03:58 +03:00
{ ... }: {
text = ''
# Su shortcut for lazy me.
# Root by default.
# Usage: s [USER]
function s() {
su - ''${1}
}
# Run something as root. Runs command as a current user if su is not available.
# Usage: sudo <COMMAND>
function sudo() {
if command -v su &> /dev/null; then
su -c "$(echo ''${*} | tr '\n' ' ')"
else
''${*}
fi
2024-04-08 18:52:11 +03:00
}
2024-04-06 03:03:58 +03:00
2024-04-08 18:52:11 +03:00
# Run something as current user. If fails, try to run with sudo.
# Usage: trysudo <COMMAND>
function trysudo() {
''${*} || sudo ''${*}
2024-04-06 03:03:58 +03:00
}
function _complete_s() {
_autocomplete_first $(_get_users)
}
complete -F _complete_s s
2024-04-08 18:52:11 +03:00
complete -F _autocomplete_nested sudo trysudo
2024-04-06 03:03:58 +03:00
'';
}