From a8667fdb91efb9c61e89b7a4843618bc38dbf967 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 15 Feb 2016 11:24:14 -0500 Subject: [PATCH] Add some custom functions to input module * ... -> ../.. expansion * sudo prefix * bind ^H to backward-kill-word --- modules/input/init.zsh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/input/init.zsh b/modules/input/init.zsh index a1f9458..bccd2bb 100644 --- a/modules/input/init.zsh +++ b/modules/input/init.zsh @@ -95,3 +95,26 @@ zle-line-finish() { } zle -N zle-line-init zle -N zle-line-finish + +# Expands ... to ../.. +function expand-dot-to-parent-directory-path { + if [[ $LBUFFER = *.. ]]; then + LBUFFER+='/..' + else + LBUFFER+='.' + fi +} +zle -N expand-dot-to-parent-directory-path +bindkey -M emacs "." expand-dot-to-parent-directory-path + +# Inserts 'sudo ' at the beginning of the line. +function prepend-sudo() { + if [[ "$BUFFER" != su(do|)\ * ]]; then + BUFFER="sudo $BUFFER" + (( CURSOR += 5 )) + fi +} +zle -N prepend-sudo +bindkey "^X^S" prepend-sudo + +bindkey '^H' backward-kill-word