Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
745 B
Bash
Raw Permalink Normal View History

2023-03-21 23:22:37 +01:00
#! bash oh-my-bash.module
2023-04-09 21:27:04 -03:00
function _omb_plugin_sudo__is_inserted {
[[ "$READLINE_LINE" = 'sudo '* ]]
}
2023-03-21 23:22:37 +01:00
function _omb_plugin_sudo_add_sudo {
if [[ -z $READLINE_LINE ]]; then
READLINE_LINE="$(fc -ln -1 | command sed 's/^[[:space:]]\{1,\}//')"
2023-04-09 21:27:04 -03:00
READLINE_POINT=${#READLINE_LINE}
_omb_plugin_sudo__is_inserted && return
fi
if _omb_plugin_sudo__is_inserted; then
READLINE_LINE="${READLINE_LINE#sudo }"
((READLINE_POINT -= 5))
else
READLINE_LINE="sudo $READLINE_LINE"
((READLINE_POINT += 5))
2023-03-21 23:22:37 +01:00
fi
2023-04-09 21:27:04 -03:00
((READLINE_POINT < 0)) && READLINE_POINT=0
2023-03-21 23:22:37 +01:00
}
2023-04-09 00:05:00 +09:00
bind -m emacs -x '"\e\e": _omb_plugin_sudo_add_sudo'
bind -m vi-insert -x '"\e\e": _omb_plugin_sudo_add_sudo'
bind -m vi-command -x '"\e\e": _omb_plugin_sudo_add_sudo'