dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit a976e7c59c2d91993c9c883b4e9272bfcb0d95c9
parent feec128e474e64531b0f6efd539a049dc697fe8b
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 14 Jun 2019 12:12:42 +0200

Add binding for vis and external compiler script

Diffstat:
M.config/vis/visrc.lua | 26+++++++++-----------------
A.local/bin/compile | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua @@ -1,12 +1,12 @@ -- load standard vis module, providing parts of the Lua API require('vis') +leader = '<Space>' + vis.events.subscribe(vis.events.INIT, function() -- Your global configuration options vis:command('set theme adbasic') - --vis:map(vis.modes.INSERT, 'jk', '<Escape>') - local leader = '<Space>' vis:map(vis.modes.NORMAL, leader..'n', ':set numbers!<Enter>') vis:map(vis.modes.NORMAL, leader..'N', ':set relativenumbers!<Enter>') vis:map(vis.modes.NORMAL, leader..'l', ':set show-newline!<Enter>') @@ -20,19 +20,11 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) vis:command('set tabwidth 4') vis:command('set colorcolumn 80') - function detect_filetype(_, _, win, _, _) - if string.find(win.file.name, '%.') then - return string.gsub(win.file.name, '.*%.', '') - else -- no dot found in win.file.name - return false; - end - end - vis:command_register('filetype', function(_, _, win, _, _) - local ext = detect_filetype(_, _, win, _, _) - vis:info('filetype: ' .. ext) - end, 'detect file type from filename') - - if detect_filetype(_, _, win, _, _) == 'tex' then - --vis:map(vis.modes.INSERT, 'l', 'L') - end + vis:map(vis.modes.NORMAL, leader..'p', ( + function() + if win.file.name then + vis:info('return status: ' .. + tostring(os.execute('compile '..win.file.name))) + end + end)) end) diff --git a/.local/bin/compile b/.local/bin/compile @@ -0,0 +1,40 @@ +#!/bin/sh + +# By lukesmithxyz + +# This script will compile or run another finishing operation on a document. I +# have this script run via vis. +# +# Compiles .tex. groff (.mom, .ms), .rmd, .md. Opens .sent files as sent +# presentations. Runs scripts based on extention or shebang + +file=$(readlink -f "$1") +dir=$(dirname "$file") +base="${file%.*}" + +cd "$dir" || exit + +textype() { \ + command="pdflatex" + ( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex" + $command --output-directory="$dir" "$base" && + grep -i addbibresource "$file" >/dev/null && + biber --input-directory "$dir" "$base" && + $command --output-directory="$dir" "$base" && + $command --output-directory="$dir" "$base" + } + +case "$file" in + *\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf > "$base".pdf ;; + *\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf > "$base".pdf ;; + *\.[0-9]) refer -PS -e "$file" | groff -mandoc -T pdf > "$base".pdf ;; + *\.rmd) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;; + *\.tex) textype "$file" ;; + *\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;; + *config.h) sudo make install ;; + *\.c) cc "$file" -o "$base" && "$base" ;; + *\.py) python "$file" ;; + *\.go) go run "$file" ;; + *\.sent) setsid sent "$file" 2>/dev/null & ;; + *) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;; +esac