@@ -151,6 +151,24 @@ function! SideSearchWinnr()
151
151
return s: my_buffer_winnr ()
152
152
endfunction
153
153
154
+ function ! s: guessProjectRoot ()
155
+ let l: splitsearchdir = split (getcwd (), " /" )
156
+
157
+ while len (l: splitsearchdir ) > 2
158
+ let l: searchdir = ' /' .join (l: splitsearchdir , ' /' ).' /'
159
+ for l: marker in [' .rootdir' , ' .git' , ' .hg' , ' .svn' , ' bzr' , ' _darcs' , ' build.xml' ]
160
+ " found it! Return the dir
161
+ if filereadable (l: searchdir .l: marker ) || isdirectory (l: searchdir .l: marker )
162
+ return l: searchdir
163
+ endif
164
+ endfor
165
+ let l: splitsearchdir = l: splitsearchdir [0 :-2 ] " Splice the list to get rid of the tail directory
166
+ endwhile
167
+
168
+ " Nothing found, fallback to current working dir
169
+ return getcwd ()
170
+ endfunction
171
+
154
172
" The public facing function.
155
173
" Accept 1 or 2 arguments which basically get passed directly
156
174
" to the `ag` command.
@@ -173,8 +191,10 @@ function! SideSearch(args) abort
173
191
174
192
call s: append_guide ()
175
193
194
+ " determine root directory
195
+ let l: cwd = s: guessProjectRoot ()
176
196
" execute showing summary of stuff read (without silent)
177
- let b: cmd = g: side_search_prg . ' ' . a: args
197
+ let b: cmd = g: side_search_prg . ' ' . a: args . ' ' . l: cwd
178
198
" Thanks: https://github.com/rking/ag.vim/blob/master/autoload/ag.vim#L154
179
199
let query = matchstr (a: args , " \\ v(-)\@ <!(\< )\@ <=\\ w+|['\" ]\\ zs.{-}\\ ze['\" ]" )
180
200
let b: escaped_query = shellescape (query)
0 commit comments