Skip to content

Instantly share code, notes, and snippets.

@rothgar
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rothgar/bdb3527626b13ad8bec4 to your computer and use it in GitHub Desktop.
Save rothgar/bdb3527626b13ad8bec4 to your computer and use it in GitHub Desktop.
bitch
# create bitch function
bitch() {
if [[ "${BUFFER}" == *" bitch" ]] && [[ "${BUFFER}" != su(do|)\ * ]]; then
# add sudo to beginning of line (remove bitch from end)
BUFFER="sudo ${BUFFER% bitch}"
elif [[ "${BUFFER}" == "bitch" ]]; then
LAST_CMD=$(fc -l -1)
BUFFER="sudo ${LAST_CMD#* }"
fi
# still need to run accept-line widget
zle .accept-line
}
# replace default accept line with bitch command
zle -N accept-line bitch
# If you want this functionality bound to a hotkey instead of needing to type
# you should use prezto or at implement their prepend-sudo function
# https://github.com/lildude/prezto/commit/6e5bb9788821ee6cea66c9b11bdfe43d8fc227e2
# both solutions can be used together
# Thanks stackexchange for helping me figure it out
# http://stackoverflow.com/questions/28099966/use-preexec-to-evaluate-entered-command/28101424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment