mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-23 12:01:30 +01:00
41eb8f1a5f
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.
19 lines
477 B
Bash
19 lines
477 B
Bash
# open vim with a scratch window that can be discarded on exit.
|
|
vimscratch() {
|
|
local args
|
|
# if running in a pipe, use stdin (-) as arg.
|
|
# -t checks if the given FD is a terminal
|
|
if [ ! -t 0 ] ; then
|
|
stdin_arg="-"
|
|
fi
|
|
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
|
|
|
|
}
|