Add tmpsrc plugin

This commit is contained in:
crater2150 2020-04-02 18:22:10 +02:00
parent 32842dcd00
commit 84cb259930
2 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,52 @@
#!/bin/zsh
tmpsrc() {
if [[ -z $1 ]]; then
echo "Usage: tmpsrc <LANGUAGE>"
return 1
fi
local confdir="${XDG_CONFIG_HOME:-$HOME/.config}/tmpsrc"
local template=$1
local templatepath=$confdir/$template
shift
local tempname=$(mktemp -u -t tmpsrc-XXXXXXXX)
if [[ -d $templatepath ]]; then
cp -r $templatepath $tempname
if [[ ! -v TMUX ]]; then
tmux new-session -d -s $tempname -c $tempname -- $EDITOR $(realpath $tempname/tmpsrc-mainfile)
if [[ -x $templatepath/tmpsrc-compiler ]]; then
tmux split -h -c $tempname -t $tempname $templatepath/tmpsrc-compiler "$@"
tmux select-pane -L -t $tempname
fi
tmux attach -t $tempname
else
pushd $tempname
if [[ -x $templatepath/tmpsrc-compiler ]]; then
tmux split -h -c $tempname $templatepath/tmpsrc-compiler "$@"
tmux select-pane -L
fi
$EDITOR $(realpath $tempname/tmpsrc-mainfile)
popd
fi
elif [[ -x $templatepath ]]; then
mkdir $tempname
pushd $tempname
if [[ ! -v TMUX ]]; then
tmux new-session -s $tempname -- $templatepath "$@"
else
$templatepath "$@"
fi
popd
elif [[ -e $templatepath ]]; then
cp $templatepath $tempname
$EDITOR $tempname
else
echo "No template for $template"
return 1
fi
rm -rf $tempname
}

View file

@ -9,6 +9,7 @@ zplug 'crater2150-zsh/chroma-z', as:theme
zplug $ZDOTDIR/plugins/highlight-config, from:local, defer:3
zplug $ZDOTDIR/plugins/bundled-compdefs, from:local
zplug $ZDOTDIR/plugins/tmpsrc, from:local
zplug 'molovo/revolver', \
as:command, \