]> git.madduck.net Git - etc/zsh.git/blob - .zsh/zshrc/80-zle_inplace_mkdir

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Minor fixes to accomodate Zsh4
[etc/zsh.git] / .zsh / zshrc / 80-zle_inplace_mkdir
1 #
2 # Provide a way to to create directories while composing the ZLE
3 #
4 # Copyright © 1994–2017 martin f. krafft <madduck@madduck.net>
5 # Released under the terms of the Artistic Licence 2.0
6 #
7 # Source repository: http://git.madduck.net/v/etc/zsh.git
8 #
9
10 _mkdir_inplace() {
11   emulate -L zsh
12   local pathtomkdir
13   if ((REGION_ACTIVE==1)); then
14     local F=$MARK T=$CURSOR
15     if [[ $F -gt $T ]]; then
16       F=${CURSOR}
17       T=${MARK}
18     fi
19     # get marked area from buffer and eliminate whitespace
20     pathtomkdir=${BUFFER[F+1,T]%%[[:space:]]##}
21     pathtomkdir=${pathtomkdir##[[:space:]]##}
22   else
23     local bufwords iword
24     bufwords=(${(z)LBUFFER})
25     iword=${#bufwords}
26     bufwords=(${(z)BUFFER})
27     pathtomkdir="${(Q)bufwords[iword]}"
28   fi
29   [[ -z "${pathtomkdir}" ]] && return 1
30   pathtomkdir=${~pathtomkdir}
31   if [[ -e "${pathtomkdir}" ]]; then
32     zle -M " path already exists, doing nothing"
33   else
34     zle -M "$(mkdir -p -v "${pathtomkdir}")"
35     zle end-of-line
36   fi
37 }
38 zle -N _mkdir_inplace
39 bindkey '\em' _mkdir_inplace
40
41 # vim:ft=zsh