Skip to content

Commit 46b4939

Browse files
committedDec 18, 2013
Allow for initial all spec based on major filetype
* Add sh file to calculate major filetype in current directory tree * Fallthrough to major filetype command if type of file not found
1 parent ef0cd9c commit 46b4939

File tree

2 files changed

+68
-20
lines changed

2 files changed

+68
-20
lines changed
 

‎bin/major_filetype

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Find the majority filetype
3+
# OSX Version (use sed -rn for Linux)
4+
5+
# Defaults: Ruby, Javascript, Coffeescript
6+
7+
filetypes="rb\|coffee\|js"
8+
9+
find . -type f | \
10+
tr '[:upper:]' '[:lower:]' | \
11+
sed -En "s|.*/[^/]+\.($filetypes)$|\1|p" | \
12+
sort | \
13+
uniq -c | \
14+
sort -nr | \
15+
head -n 1 | \
16+
awk "{ print \$2}"

‎plugin/spec.vim

+52-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,65 @@
11
" Get file path
22
let s:plugin_path = expand("<sfile>:p:h:h")
33

4+
" Set Ruby/RSpec
5+
function! s:SetRubyCommand()
6+
if !exists("g:rspec_command")
7+
let s:cmd = "rspec {spec}"
8+
call s:GUIRunning()
9+
else
10+
let g:spec_command = g:rspec_command
11+
endif
12+
endfunction
13+
14+
" Set Javascript
15+
function! s:SetJavascriptCommand()
16+
if !exists("g:mocha_js_command")
17+
let s:cmd = "mocha {spec}"
18+
call s:GUIRunning()
19+
else
20+
let g:spec_command = g:mocha_js_command
21+
endif
22+
endfunction
23+
24+
" Set Coffeescript
25+
function! s:SetCoffeescriptCommand()
26+
if !exists("g:mocha_coffee_command")
27+
let s:cmd = "mocha --compilers coffee:coffee-script {spec}"
28+
call s:GUIRunning()
29+
else
30+
let g:spec_command = g:mocha_coffee_command
31+
endif
32+
endfunction
33+
34+
" Initial Spec Command
35+
function! s:SetInitialSpecCommand()
36+
let l:spec = s:plugin_path . "/bin/major_filetype"
37+
let l:filetype = system(l:spec)
38+
if l:filetype =~ 'rb'
39+
call s:SetRubyCommand()
40+
elseif l:filetype =~ 'js'
41+
call s:SetJavascriptCommand()
42+
elseif l:filetype =~ 'coffee'
43+
call s:SetCoffeescriptCommand()
44+
else
45+
let g:spec_command = ""
46+
endif
47+
endfunction
48+
449
" Determine which command based on filetype
550
function! s:GetCorrectCommand()
651
" Set default {rspec} command (ruby/rails)
752
if &filetype ==? 'ruby'
8-
if !exists("g:rspec_command")
9-
let s:cmd = "rspec {spec}"
10-
call s:GUIRunning()
11-
else
12-
let g:spec_command = g:rspec_command
13-
endif
53+
call s:SetRubyCommand()
1454
" Set default {mocha} command (javascript)
1555
elseif &filetype ==? 'javascript'
16-
if !exists("g:mocha_js_command")
17-
let s:cmd = "mocha {spec}"
18-
call s:GUIRunning()
19-
else
20-
let g:spec_command = g:mocha_js_command
21-
endif
56+
call s:SetJavascriptCommand()
2257
" Set default {mocha} command (coffeescript)
2358
elseif &filetype ==? 'coffee'
24-
if !exists("g:mocha_coffee_command")
25-
let s:cmd = "mocha --compilers coffee:coffee-script {spec}"
26-
call s:GUIRunning()
27-
else
28-
let g:spec_command = g:mocha_coffee_command
29-
endif
59+
call s:SetCoffeescriptCommand()
3060
" Fallthrough default
3161
else
32-
let g:spec_command = ""
62+
call s:SetInitialSpecCommand()
3363
endif
3464
endfunction
3565

@@ -71,8 +101,10 @@ endfunction
71101
function! RunAllSpecs()
72102
if isdirectory('spec')
73103
let l:spec = "spec"
74-
else
104+
elseif isdirectory('test')
75105
let l:spec = "test"
106+
else
107+
let l:spec = ""
76108
endif
77109
call SetLastSpecCommand(l:spec)
78110
call RunSpecs(l:spec)

0 commit comments

Comments
 (0)
Please sign in to comment.