Skip to content

Commit 1b4099d

Browse files
committed
Fix: current directory option hidden when not needed
The current directory option is now shown only when selecting for a directory or file+directory.
1 parent b75e631 commit 1b4099d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default createPrompt<string, FileSelectorConfig>((config, done) => {
7474
)
7575

7676
const items = useMemo(() => {
77-
const files = getDirFiles(currentDir)
77+
const files = getDirFiles(currentDir, type)
7878

7979
for (const file of files) {
8080
file.isDisabled = config.filter ? !config.filter(file) : false

src/utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ export function getMaxLength(arr: string[]): number {
4343
/**
4444
* Get files of a directory
4545
*/
46-
export function getDirFiles(dir: string): FileStats[] {
47-
const filenames = ['.', ...fs.readdirSync(dir)];
48-
return filenames.map(filename => {
46+
export function getDirFiles(dir: string, type: string): FileStats[] {
47+
const files: string[] = fs.readdirSync(dir)
48+
if (type === 'directory' || type === 'file+directory') {
49+
files.unshift('.')
50+
}
51+
return files.map(filename => {
4952
const filepath = path.join(dir, filename)
5053
const fileStat = fs.statSync(filepath)
5154

0 commit comments

Comments
 (0)