From 4a336083bc64bef499992eb9716184d6691f8cef Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Wed, 20 Jul 2011 17:09:06 +0200 Subject: [PATCH] zsh: Added function inplaceMkDirs(). Thanks: Bernhard Tittelbach --- doc/grmlzshrc.t2t | 6 ++++++ etc/zsh/zshrc | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/doc/grmlzshrc.t2t b/doc/grmlzshrc.t2t index 7f62c1b..70573ca 100644 --- a/doc/grmlzshrc.t2t +++ b/doc/grmlzshrc.t2t @@ -424,6 +424,12 @@ Deletes a word left of the cursor; seeing '/' as additional word separator. : **CTRL-x-1** Jump right after the first word. +: **CTRL-x-M()** +Create directory under cursor or the selected area. +To select an area press ctrl-@ and use the cursor. +Use case: you type "mv abc ~/testa/testb/testc/" and remember that the +directory does not exist yet -> press **CTRL-xM** and problem solved. + : **CTRL-x-p** Searches the last occurence of string before the cursor in the command history. diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 3e20e5b..1f8cdaa 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -2667,6 +2667,40 @@ cdt() { mdiff() { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" } + +#f5# Create directory under cursor or the selected area +# Press ctrl-xM to create the directory under the cursor or the selected area. +# To select an area press ctrl-@ or ctrl-space and use the cursor. +# Use case: you type "mv abc ~/testa/testb/testc/" and remember that the +# directory does not exist yet -> press ctrl-XM and problem solved +inplaceMkDirs() { + local PATHTOMKDIR + if ((REGION_ACTIVE==1)); then + local F=$MARK T=$CURSOR + if [[ $F -gt $T ]]; then + F=${CURSOR} + T=${MARK} + fi + # get marked area from buffer and eliminate whitespace + PATHTOMKDIR=${BUFFER[F+1,T]%%[[:space:]]##} + PATHTOMKDIR=${PATHTOMKDIR##[[:space:]]##} + else + local bufwords iword + bufwords=(${(z)LBUFFER}) + iword=${#bufwords} + bufwords=(${(z)BUFFER}) + PATHTOMKDIR="$bufwords[iword]" + fi + [[ -z "${PATHTOMKDIR}" ]] && return 1 + if [[ -e "${PATHTOMKDIR}" ]]; then + zle -M " path already exists, doing nothing" + else + zle -M "$(mkdir -p -v "${PATHTOMKDIR}")" + zle end-of-line + fi +} +zle -N inplaceMkDirs && bindkey '^XM' inplaceMkDirs + #f5# Memory overview memusage() { ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc -- 2.1.4