Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
document.onreadystatechange = function(){
// editor.on seems to require newer codemirror version
// var pending;
// editor.on("change", function() {
// clearTimeout(pending);
// pending = setTimeout(update, 400);
// });
function looksLike(code) {
var firstline = code.split('\n')[0];
if(firstline.indexOf('#!') == 0){
var shellpattern = /bin\/[\w]{0,2}sh/;
var shellpatternwin = /[\w]{0,2}sh\.exe/;
if(firstline.indexOf('python') > -1){
return "python";
// perl requires stapler-adjunct-codemirror > 1.3
}else if(firstline.indexOf('perl') > -1){
return "perl";
}else if(shellpattern.exec(firstline) || shellpatternwin.exec(firstline)){
return "shell";
}
}
}
function update() {
editor.setOption("mode", looksLike(editor.getValue()));
}
update();
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,6 @@ THE SOFTWARE.
org.kohsuke.stapler.codemirror.mode.shell.shell,
org.kohsuke.stapler.codemirror.mode.perl.perl,
"/>
<script>
document.onreadystatechange = function(){
// editor.on seems to require newer codemirror version
// var pending;
// editor.on("change", function() {
// clearTimeout(pending);
// pending = setTimeout(update, 400);
// });
function looksLike(code) {
var firstline = code.split('\n')[0];
if(firstline.indexOf('#!') == 0){
var shellpattern = /bin\/[\w]{0,2}sh/;
var shellpatternwin = /[\w]{0,2}sh\.exe/;
if(firstline.indexOf('python') > -1){
return "python";
// perl requires stapler-adjunct-codemirror > 1.3
}else if(firstline.indexOf('perl') > -1){
return "perl";
}else if(shellpattern.exec(firstline) || shellpatternwin.exec(firstline)){
return "shell";
}
}
}
function update() {
editor.setOption("mode", looksLike(editor.getValue()));
}
update();
};
</script>
<st:adjunct includes="org.jenkinsci.plugins.managedscripts.ScriptConfig.edit-config-codemirror"/>
</f:entry>
</j:jelly>