X-Git-Url: https://git.madduck.net/etc/zsh.git/blobdiff_plain/e45b0db3d66ca9e041622db3d801d026fb4d3724..33230b65afa1076218abff057d0bbcc7486af0a8:/.zsh/zshrc/80-zle_inplace_mkdir diff --git a/.zsh/zshrc/80-zle_inplace_mkdir b/.zsh/zshrc/80-zle_inplace_mkdir new file mode 100644 index 0000000..eff5f13 --- /dev/null +++ b/.zsh/zshrc/80-zle_inplace_mkdir @@ -0,0 +1,41 @@ +# +# Provide a way to to create directories while composing the ZLE +# +# Copyright © 1994–2017 martin f. krafft +# Released under the terms of the Artistic Licence 2.0 +# +# Source repository: http://git.madduck.net/v/etc/zsh.git +# + +_mkdir_inplace() { + emulate -L zsh + 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="${(Q)bufwords[iword]}" + fi + [[ -z "${pathtomkdir}" ]] && return 1 + pathtomkdir=${~pathtomkdir} + 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 _mkdir_inplace +bindkey '\em' _mkdir_inplace + +# vim:ft=zsh