Last active
August 29, 2015 14:14
-
-
Save rothgar/bdb3527626b13ad8bec4 to your computer and use it in GitHub Desktop.
bitch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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