Adds alt+m zle shortcut to create the directory for the current arg

master
Jonathan Hodgson 5 years ago
parent 35cffff6f9
commit 72f8fa04cd
  1. 32
      shells/zsh/includes/keybindings.zsh
  2. 7
      shells/zsh/includes/urls.zsh

@ -29,6 +29,8 @@ key[ShiftTab]="${terminfo[kcbt]}"
[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history
[[ -n "${key[ShiftTab]}" ]] && bindkey -- "${key[ShiftTab]}" reverse-menu-complete
bindkey -M viins "^q" push-input
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
@ -89,3 +91,33 @@ rationalise-dot() {
}
zle -N rationalise-dot
bindkey . rationalise-dot
make_current_word_directory(){
tokens=(${(z)LBUFFER})
local folder="${tokens[-1]}" output
if [ "${folder[1]}" = '"' ] || [ "${folder[1]}" = "'" ]; then
folder=${folder:1}
else
folder="${folder//\\ / }"
fi
#folder="${folder%/*}"
if [ -e "$folder" ]; then
zle -M "$folder already exists"
else
output="$(mkdir -p "$folder" 2>&1)"
if [ $? -eq 0 ]; then
zle -M "$folder created"
else
zle -M "$output"
fi
fi
}
zle -N make_current_word_directory
# Alt + m
bindkey '\em' make_current_word_directory

@ -0,0 +1,7 @@
# This makes zsh automatically escape certain characters when typing a url
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
# This does the same for pasting a url
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
Loading…
Cancel
Save