Skip to content

Instantly share code, notes, and snippets.

@aoyama-val
Created May 1, 2018 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aoyama-val/5ae24d44f207914fdd2c2b3af1f5da08 to your computer and use it in GitHub Desktop.
Save aoyama-val/5ae24d44f207914fdd2c2b3af1f5da08 to your computer and use it in GitHub Desktop.
A zsh widget that formats current command line
# 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