File tree Expand file tree Collapse file tree 8 files changed +39
-51
lines changed
Expand file tree Collapse file tree 8 files changed +39
-51
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,7 @@ local relativize = require('wincent.commandt.private.relativize')
1111local ui = nil
1212
1313local function file_finder (directory )
14- directory = vim .trim (directory )
15- if directory == ' ' then
16- directory = require (' wincent.commandt.private.get_directory' )()
17- end
14+ directory = require (' wincent.commandt.get_directory' )(directory )
1815 pushd (directory )
1916 local options = require (' wincent.commandt.private.options' ):get ()
2017 local finder = require (' wincent.commandt.private.finders.file' )(' .' , options )
@@ -33,10 +30,7 @@ local function file_finder(directory)
3330end
3431
3532local function watchman_finder (directory )
36- directory = vim .trim (directory )
37- if directory == ' ' then
38- directory = require (' wincent.commandt.private.get_directory' )()
39- end
33+ directory = require (' wincent.commandt.get_directory' )(directory )
4034 local options = require (' wincent.commandt.private.options' ):get ()
4135 local finder = require (' wincent.commandt.private.finders.watchman' )(directory , options )
4236
Original file line number Diff line number Diff line change 1+ -- SPDX-FileCopyrightText: Copyright 2025-present Greg Hurrell and contributors.
2+ -- SPDX-License-Identifier: BSD-2-Clause
3+
4+ --- Infers which directory a scanner should operate in.
5+ ---
6+ --- - If passed a non-blank `directory`, returns that.
7+ --- - Otherwise, based on the `'traverse'` setting, either returns the nearest
8+ --- SCM root directory, or the current working directory.
9+ ---
10+ --- @param directory string | nil
11+ --- @return string
12+ local function get_directory (directory )
13+ if directory and vim .trim (directory ) ~= ' ' then
14+ return directory
15+ else
16+ local options = require (' wincent.commandt.private.options' ):get ()
17+ local find_root = require (' wincent.commandt.private.find_root' )
18+ if options .traverse == ' file' then
19+ local file = vim .fn .expand (' %:p:h' ) -- If no current file, returns current dir.
20+ return find_root (file , options .root_markers )
21+ elseif options .traverse == ' pwd' then
22+ return find_root (vim .fn .getcwd (), options .root_markers )
23+ else
24+ return vim .fn .getcwd ()
25+ end
26+ end
27+ end
28+
29+ return get_directory
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11-- SPDX-FileCopyrightText: Copyright 2025-present Greg Hurrell and contributors.
22-- SPDX-License-Identifier: BSD-2-Clause
33
4- local on_directory = require (' wincent.commandt.on_directory ' )
4+ local get_directory = require (' wincent.commandt.get_directory ' )
55local on_open = require (' wincent.commandt.on_open' )
66local popd = require (' wincent.commandt.popd' )
77local pushd = require (' wincent.commandt.pushd' )
@@ -18,7 +18,7 @@ local fd = {
1818 return options .scanners .fd .max_files
1919 end ,
2020 on_close = popd ,
21- on_directory = on_directory ,
21+ on_directory = get_directory ,
2222 open = on_open ,
2323}
2424
Original file line number Diff line number Diff line change 11-- SPDX-FileCopyrightText: Copyright 2025-present Greg Hurrell and contributors.
22-- SPDX-License-Identifier: BSD-2-Clause
33
4- local on_directory = require (' wincent.commandt.on_directory ' )
4+ local get_directory = require (' wincent.commandt.get_directory ' )
55local on_open = require (' wincent.commandt.on_open' )
66local popd = require (' wincent.commandt.popd' )
77local pushd = require (' wincent.commandt.pushd' )
@@ -18,7 +18,7 @@ local find = {
1818 return options .scanners .find .max_files
1919 end ,
2020 on_close = popd ,
21- on_directory = on_directory ,
21+ on_directory = get_directory ,
2222 open = on_open ,
2323}
2424
Original file line number Diff line number Diff line change 11-- SPDX-FileCopyrightText: Copyright 2025-present Greg Hurrell and contributors.
22-- SPDX-License-Identifier: BSD-2-Clause
33
4- local on_directory = require (' wincent.commandt.on_directory ' )
4+ local get_directory = require (' wincent.commandt.get_directory ' )
55local on_open = require (' wincent.commandt.on_open' )
66
77local git = {
@@ -26,7 +26,7 @@ local git = {
2626 max_files = function (options )
2727 return options .scanners .git .max_files
2828 end ,
29- on_directory = on_directory ,
29+ on_directory = get_directory ,
3030 open = on_open ,
3131}
3232
Original file line number Diff line number Diff line change 11-- SPDX-FileCopyrightText: Copyright 2025-present Greg Hurrell and contributors.
22-- SPDX-License-Identifier: BSD-2-Clause
33
4- local on_directory = require (' wincent.commandt.on_directory ' )
4+ local get_directory = require (' wincent.commandt.get_directory ' )
55local on_open = require (' wincent.commandt.on_open' )
66local popd = require (' wincent.commandt.popd' )
77local pushd = require (' wincent.commandt.pushd' )
@@ -18,7 +18,7 @@ local rg = {
1818 return options .scanners .rg .max_files
1919 end ,
2020 on_close = popd ,
21- on_directory = on_directory ,
21+ on_directory = get_directory ,
2222 open = on_open ,
2323}
2424
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments