zsh: vimscratch: add filetype arg

Allows setting filetype for vimscratch command.

Usage: `<command> | 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.
fix-ci
bretello 2023-10-25 11:45:54 +02:00
parent f4e960be35
commit 41eb8f1a5f
1 changed files with 9 additions and 1 deletions

View File

@ -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
}