Created
May 1, 2018 15:48
-
-
Save aoyama-val/5ae24d44f207914fdd2c2b3af1f5da08 to your computer and use it in GitHub Desktop.
A zsh widget that formats current command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# format current command line | |
format-line() { | |
local words=("${(z)BUFFER}") | |
local buf="" | |
for (( i = 1; i <= $#words; i++ )); do | |
if [ $i = 1 ]; then | |
buf=$'\n'"${words[$i]}" | |
else | |
buf="$buf \\"$'\n'" ${words[$i]}" | |
fi | |
if [[ "${words[$i]}" = -* && "${words[$((i+1))]}" != -* ]]; then | |
buf="$buf ${words[$((i+1))]}" | |
(( i++ )) | |
fi | |
done | |
BUFFER="$buf" | |
CURSOR=$#BUFFER | |
} | |
zle -N format-line | |
bindkey "^x^f" format-line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment