dotfiles

My dotfiles, nothing really interesting to see ...
git clone https://git.onna.be/dotfiles.git
Log | Files | Refs | README

commit f49655fe44d74c8d683d4d3848613b038e2b7579
parent f093ee7bcae6cd8731885b5e3d8d1cc0e50b5b00
Author: Paco Esteban <paco@onna.be>
Date:   Wed, 19 Sep 2018 20:10:58 +0200

making sh stuff in nvim closer to POSIX. And leaving some snippets for ocasional bash

Diffstat:
nvim/.config/nvim/UltiSnips/sh.snippets | 48++++++++++++++++++++++++++++++++++++++++--------
nvim/.config/nvim/templates/template.sh | 6++----
2 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/nvim/.config/nvim/UltiSnips/sh.snippets b/nvim/.config/nvim/UltiSnips/sh.snippets @@ -1,22 +1,30 @@ priority -10 snippet #! -#!/usr/bin/env bash +#!/bin/sh endsnippet -snippet sbash "safe bash options" +snippet bash "safe bash options" #!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' `!p snip.rv ='\n\n' ` endsnippet -snippet temp "Tempfile" -${1:TMPFILE}="$(mktemp -t ${3:--suffix=${4:.SUFFIX}} ${2:`!p +snippet tmpfile "Tempfile" +${1:TMPFILE}="$(mktemp -t ${2:`!p snip.rv = re.sub(r'[^a-zA-Z]', '_', snip.fn) or "untitled" `}.XXXXXX)" -${5:${6/(.+)/trap "/}${6:rm -f '$${1/.*\s//}'}${6/(.+)/" 0 # EXIT\n/}${7/(.+)/trap "/}${7:rm -f '$${1/.*\s//}'; exit 1}${7/(.+)/" 2 # INT\n/}${8/(.+)/trap "/}${8:rm -f '$${1/.*\s//}'; exit 1}${8/(.+)/" 1 15 # HUP TERM\n/}} +${3:trap "rm `!p snip.rv = t[1]`" EXIT} +$0 +endsnippet +snippet tmpdir "Tempdir" +${1:TMPDIR}="$(mktemp -d -t ${2:`!p +snip.rv = re.sub(r'[^a-zA-Z]', '_', snip.fn) or "untitled" +`}.XXXXXX)" +${3:trap "rm -rf `!p snip.rv = t[1]`" EXIT} +$0 endsnippet snippet case "case .. esac (case)" @@ -26,6 +34,12 @@ case ${1:word} in esac endsnippet +snippet func "Function ()" +${1:function}() { + ${0:#statements} +} +endsnippet + snippet elif "elif .. (elif)" elif ${2:[[ ${1:condition} ]]}; then ${0:#statements} @@ -50,25 +64,43 @@ ${1/['"`](.+)['"`]/$1/} endsnippet snippet if "if ... then (if)" -if ${2:[[ ${1:condition} ]]}; then +if ${2:[ ${1:condition} ]}; then ${0:#statements} fi endsnippet snippet until "until ... (done)" -until ${2:[[ ${1:condition} ]]}; do +until ${2:[ ${1:condition} ]}; do ${0:#statements} done endsnippet snippet while "while ... (done)" +while ${2:[ ${1:condition} ]}; do + ${0:#statements} +done +endsnippet + +snippet bashif "bash if ... then (if)" +if ${2:[[ ${1:condition} ]]}; then + ${0:#statements} +fi +endsnippet + +snippet bashuntil "bash until ... (done)" +until ${2:[[ ${1:condition} ]]}; do + ${0:#statements} +done +endsnippet + +snippet bashwhile "bash while ... (done)" while ${2:[[ ${1:condition} ]]}; do ${0:#statements} done endsnippet snippet cleanup "bash exit trap" -function cleanup { +cleanup() { ${0:#cleanup logic ...} } trap cleanup EXIT diff --git a/nvim/.config/nvim/templates/template.sh b/nvim/.config/nvim/templates/template.sh @@ -1,5 +1,3 @@ -#!/usr/bin/env bash +#!/bin/sh -set -euo pipefail -shopt -s nullglob globstar -IFS=$'\n\t' +set -eu