diff --git a/UltiSnips/sh.snippets b/UltiSnips/sh.snippets index 1085d86..915c0df 100644 --- a/UltiSnips/sh.snippets +++ b/UltiSnips/sh.snippets @@ -1,15 +1,32 @@ +global !p +import vim + +# Tests for the existence of a variable declared by Vim's filetype detection +# suggesting the type of shell script of the current file +def testShell(scope, shell): + return vim.eval("exists('" + scope + ":is_" + shell + "')") + +# Loops over the possible variables, checking for global variables +# first since they indicate an override by the user. +def getShell(): + for scope in ["g", "b"]: + for shell in ["bash", "sh", "kornshell"]: + if testShell(scope, shell) == "1": + if shell == "kornshell": + return "ksh" + return shell + return "sh" +endglobal ########################################################################### # TextMate Snippets # ########################################################################### snippet #! -#!/bin/sh - +`!p snip.rv = '#!/bin/' + getShell() + "\n\n" ` endsnippet snippet !env "#!/usr/bin/env (!env)" -#!/usr/bin/env bash - +`!p snip.rv = '#!/usr/bin/env ' + getShell() + "\n\n" ` endsnippet snippet temp "Tempfile" diff --git a/UltiSnips/zsh.snippets b/UltiSnips/zsh.snippets new file mode 100644 index 0000000..18a2989 --- /dev/null +++ b/UltiSnips/zsh.snippets @@ -0,0 +1,13 @@ +extends sh + +snippet #! "shebang" ! +#!/bin/zsh + +endsnippet + +snippet !env "#!/usr/bin/env (!env)" ! +#!/usr/bin/env zsh + +endsnippet + +# vim:ft=snippets: diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index 3ae7a72..a618ba6 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -1291,6 +1291,7 @@ Contributors listed in chronological order: Theocrite (theocrite) Ferdinand Majerech (kiith-sa) Vivien Didelot + Øystein Walle (osse) Thank you for your support.