commit 2cda10b648ffa34a1d836c21f12217d9333507ef
Author: oscarbenedito <oscar@obenedito.org>
Date:   Sat, 16 Nov 2019 20:31:53 +0100

Initial commit

Diffstat:
A.chezmoi.toml.tmpl | 17+++++++++++++++++
A.chezmoiignore | 5+++++
A.gitignore | 1+
Adot_bash_aliases.tmpl | 28++++++++++++++++++++++++++++
Adot_gitconfig.tmpl | 8++++++++
Adot_scripts/executable_deploy-website.sh.tmpl | 14++++++++++++++
Adot_scripts/executable_tmux-website.sh | 17+++++++++++++++++
Adot_vimrc.md | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amarkion.py | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arun_markion.sh | 4++++
10 files changed, 216 insertions(+), 0 deletions(-)

diff --git a/.chezmoi.toml.tmpl b/.chezmoi.toml.tmpl @@ -0,0 +1,17 @@ +{{ $pgpkey := promptString "Is there a PGP key set up" -}} +{{ $website := promptString "Is the website repository under ~/Git/obenedito.org" -}} +{{ $backups := promptString "Set up backups" -}} +[data] + pgpkey = {{ $pgpkey }} + website = {{ $website }} +{{- if backups }} +{{- $backup_exclude := promptString "backup_exclude" }} +{{- $small_backup_exclude := promptString "small_backup_exclude" }} +{{- $backup_dir := promptString "backup_dir" }} + [data.backup] + backup_exclude = {{ $backup_exclude }} + small_backup_exclude = {{ $small_backup_exclude}} + backup_dir = "{{ $backup_dir }}" +{{- else }} + backup = false +{{- end }} diff --git a/.chezmoiignore b/.chezmoiignore @@ -0,0 +1,5 @@ +markion.py +*.md +{{ if not .website -}} +.scripts +{{- end }} diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +dot_vimrc diff --git a/dot_bash_aliases.tmpl b/dot_bash_aliases.tmpl @@ -0,0 +1,28 @@ +alias upgrade="sudo {{ if eq .chezmoi.osRelease.id "debian" }}apt-get update && sudo apt-get upgrade{{ else }}pacman -Syyu{{ end }}" + +{{- if .backup }} +alias backup="rsync -gloptruzvP --delete --exclude={ + {{- range $i, $dir := .backup.backup_exclude }} + {{- if $i -}} + , + {{- end -}} + "{{ $dir }}" + {{- end -}} +} {{ .chezmoi.homedir }}/ /media/oscar/OSCAR/.{{ .backup.backup_dir }}/" +alias backup_vc_10="rsync -gloptruzvP --delete --exclude={ + {{- range $i, $dir := .backup.backup_exclude }} + {{- if $i -}} + , + {{- end -}} + "{{ $dir }}" + {{- end -}} + {{ range $dir := .backup.small_backup_exclude -}} + ,"{{ $dir }}" + {{- end -}} +} {{ .chezmoi.homedir }}/ /media/veracrypt10/{{ .backup.backup_dir }}/" +{{- end }} + +{{- if .website }} +alias website="~/.scripts/tmux-website.sh" +alias deploy_website="~/.scripts/deploy-website.sh" +{{- end }} diff --git a/dot_gitconfig.tmpl b/dot_gitconfig.tmpl @@ -0,0 +1,8 @@ +[user] + email = oscar@obenedito.org + name = oscarbenedito +{{- if .pgpkey }} + signingkey = 827E5A8E3AE8A499 +[commit] + gpgsign = true +{{- end }} diff --git a/dot_scripts/executable_deploy-website.sh.tmpl b/dot_scripts/executable_deploy-website.sh.tmpl @@ -0,0 +1,14 @@ +#!/bin/bash + +HUGO_PATH="{{ .chezmoi.homedir }}/Git/obenedito.org" +TEMP_DIR="{{ .chezmoi.homedir }}/.tmp-webdav" +MOUNT_PATH="/media/obenedito" +WEBDAV_FOLDER="html-obenedito.org" + +rm -rf $HUGO_PATH/public +hugo -s $HUGO_PATH --minify +mount $MOUNT_PATH +mkdir $TEMP_DIR +rsync -ruvc --progress --delete --temp-dir=$TEMP_DIR $HUGO_PATH/public/ $MOUNT_PATH/$WEBDAV_FOLDER +rmdir $TEMP_DIR +umount $MOUNT_PATH diff --git a/dot_scripts/executable_tmux-website.sh b/dot_scripts/executable_tmux-website.sh @@ -0,0 +1,17 @@ +#!/bin/bash +SESSION=$USER + +setxkbmap es +tmux -2 new-session -d -s $SESSION + +# Setup window +tmux new-window -t $SESSION:1 -n 'hugo' +tmux send-keys "cd ~/Git/obenedito.org" C-m +tmux send-keys "hugo server" C-m +tmux select-window -t $SESSION:0 +tmux send-keys "cd ~/Git/obenedito.org" C-m +tmux send-keys "atom . &" C-m +tmux send-keys "firefox http://localhost:1313/ &" C-m + +# Attach to session +tmux -2 attach-session -t $SESSION diff --git a/dot_vimrc.md b/dot_vimrc.md @@ -0,0 +1,66 @@ +# File `.vimrc` + +## Latex-Suite +First of all we include the code required by `vim-latexsuite`. The following code is required and it makes vim invoke Latex-Suite when you open a tex file. +```python file dot_vimrc +filetype plugin on +``` + +The following code is important as grep will sometimes skip displaying the file name if you search in a singe file. This will confuse Latex-Suite. Set your grep program to always generate a file-name. +```python file dot_vimrc +set grepprg=grep\ -nH\ $* +``` + +The following code is optional and it enables automatic indentation as you type. +```python file dot_vimrc +filetype indent on +``` + +The following code is optional. Starting with Vim 7, the filetype of empty `.tex` files defaults to 'plaintex' instead of 'tex', which results in vim-latex not being loaded. The following changes the default filetype back to 'tex': +```python file dot_vimrc +let g:tex_flavor='latex' +let g:Tex_Folding=0 +let g:Tex_AutoFolding=0 +``` + +## Defaults +Configures indentation. +```python file dot_vimrc +set expandtab +set shiftwidth=2 +set tabstop=2 +``` + +Configures syntax coloring. +```python file dot_vimrc +syntax on +``` + +Show line number and other lines' relative number. +```python file dot_vimrc +set number +set relativenumber +``` + +Setting the folding method to marker (you should use `{{{` and `}}}` to delimit areas that should fold). +```python file dot_vimrc +set foldmethod=marker +``` + +Set modeline to be able to change defaults in a per file basis. +```python file dot_vimrc +set modeline +``` + +## Other useful commands +Shortcut to execute the make command. +```python file dot_vimrc +:command Make :w | :!make +``` + +Sets the filetype for Latex documents. +```python file dot_vimrc +autocmd BufRead,BufNewFile *.tex set filetype=tex +autocmd BufRead,BufNewFile *.cls set filetype=tex +autocmd BufRead,BufNewFile *.sty set filetype=tex +``` diff --git a/markion.py b/markion.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3.6 +# Copyright (C) 2019 Oscar Benedito +# +# This file is part of Markion. +# +# Markion is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Markion is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Markion. If not, see <https://www.gnu.org/licenses/>. +import os, sys, re, argparse +parser = argparse.ArgumentParser(description='Markion is a simple scripts that retrieves tangled code from Markdown.') +parser.add_argument('file', metavar='file', type=str, nargs=1, help='Input file.') +parser.add_argument('-d', '--output-directory', dest='out_dir', type=str, default=os.getcwd(), help='Change the output directory.') +parser.add_argument('-D', '--auto-directory', dest='auto_dir', action='store_true', help='Auto detect output directory.') +args = parser.parse_args() +with open(args.file[0], 'r') as f: + inp = f.read() +r_block = '```[\w\-.]*\s+block\s+([\w.-]+).*?\n(.*?)\n```\s*?\n' +r_file = '```[\w\-.]*\s+file\s+([\w.-]+).*?\n(.*?\n)```\s*?\n' +blocks = re.findall(r_block, inp, flags = re.DOTALL) +files = re.findall(r_file, inp, flags = re.DOTALL) +r_include = re.compile('([ \t]*)\[\[\s*include\s+([\w\-.]+)\s*\]\]', flags = re.DOTALL) +def resolve(content, blocks): + it = r_include.finditer(content) + for include in it: + block_name = include[2] + if blocks[block_name][0]: + raise Exception('Circular dependency in block ' + block_name) + blocks[block_name][0] = True + s = resolve(blocks[block_name][1], blocks) + blocks[block_name][0] = False + blocks[block_name][1] = s + s = include[1] + s.replace('\n', '\n' + include[1]) + content = r_include.sub(repr(s)[1:-1], content, count = 1) + return content +block_content = { b[0] : [False, b[1]] for b in blocks } +file_content = dict() +for f in files: + if f[0] not in file_content: + file_content[f[0]] = '' + file_content[f[0]] += resolve(f[1], block_content) +if args.auto_dir: + args.out_dir = os.path.dirname(args.file[0]) +if not os.path.exists(args.out_dir): + os.mkdirs(args.out_dir) +for fn, fc in file_content.items(): + with open(args.out_dir + '/' + fn, 'w') as f: + f.write(fc) diff --git a/run_markion.sh b/run_markion.sh @@ -0,0 +1,4 @@ +#!/bin/bash +for f in $(find $HOME/.local/share/chezmoi -name '*.md'); do + python3.6 $HOME/.local/share/chezmoi/markion.py -D $f +done