From 41eb8f1a5f3e181ad4e6de4b21df634c23b8223c Mon Sep 17 00:00:00 2001 From: bretello Date: Wed, 25 Oct 2023 11:45:54 +0200 Subject: [PATCH] zsh: vimscratch: add filetype arg Allows setting filetype for vimscratch command. Usage: ` | vimscratch [filetype]`. For example: ```bash curl https://myip.wtf/json | vimscratch json ``` Will open the output of the curl command as a json temporary file in vim. --- functions/vim.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/functions/vim.zsh b/functions/vim.zsh index 34a30c7..c304098 100644 --- a/functions/vim.zsh +++ b/functions/vim.zsh @@ -6,5 +6,13 @@ vimscratch() { if [ ! -t 0 ] ; then stdin_arg="-" fi - vim -c "set buftype=nofile" $@ $stdin_arg + set +x + if [[ -n "$1" ]]; then + filetype=$1 + shift + vim -c "set buftype=nofile" -c "set filetype=$filetype" $@ $stdin_arg + else + vim -c "set buftype=nofile" $filetype_arg $@ $stdin_arg + fi + }