From 5f1f8d67006d55c542d2fc2993c2d0d9a428a49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Walle?= Date: Sat, 3 Nov 2012 15:46:39 +0100 Subject: [PATCH 1/5] Add snippets for zsh zsh is a seperate filetype from sh in Vim. This uses the sh snippets while changing the shebang-related snippets. --- UltiSnips/zsh.snippets | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 UltiSnips/zsh.snippets 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: From 630b74872b275cc1f0cefc2472f66691755a75f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Walle?= Date: Sat, 3 Nov 2012 17:07:01 +0100 Subject: [PATCH 2/5] Add test to determine shell The 'sh' filetype in Vim covers sh, bash and ksh. This function looks for declared variables that results from Vim's own test. The global variables are checked first since they are typically specifed by the user in .vimrc --- UltiSnips/sh.snippets | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/UltiSnips/sh.snippets b/UltiSnips/sh.snippets index 1085d86..3771cab 100644 --- a/UltiSnips/sh.snippets +++ b/UltiSnips/sh.snippets @@ -1,3 +1,17 @@ +global !p +import vim +def testShell(scope, shell): + return vim.eval("exists('" + scope + ":is_" + shell + "')") + +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 # From 5eeef2c4d8336731edf8e63872ab96e7af2300ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Walle?= Date: Sat, 3 Nov 2012 17:13:22 +0100 Subject: [PATCH 3/5] Change snippets to use getShell() --- UltiSnips/sh.snippets | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/UltiSnips/sh.snippets b/UltiSnips/sh.snippets index 3771cab..a6e1316 100644 --- a/UltiSnips/sh.snippets +++ b/UltiSnips/sh.snippets @@ -17,13 +17,11 @@ 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" From d4b03a8195c2c8d76f4a01ba125d03e96c9f3b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Walle?= Date: Tue, 6 Nov 2012 17:21:31 +0100 Subject: [PATCH 4/5] Add comments to shell detection functions --- UltiSnips/sh.snippets | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UltiSnips/sh.snippets b/UltiSnips/sh.snippets index a6e1316..915c0df 100644 --- a/UltiSnips/sh.snippets +++ b/UltiSnips/sh.snippets @@ -1,8 +1,13 @@ 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"]: From a599a6ee6ae186d5fe91571b19011f57ddf32829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Walle?= Date: Thu, 8 Nov 2012 07:40:18 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Add=20=C3=98ystein=20Walle=20to=20contribut?= =?UTF-8?q?ors=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/UltiSnips.txt | 1 + 1 file changed, 1 insertion(+) 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.