Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit dace62c

Browse files
myan9starpit
authored andcommitted
fix(plugins/plugin-bash-like): ls ~ fails
Fixes #7008
1 parent fb35ffc commit dace62c

File tree

3 files changed

+51
-2
lines changed
  • plugins
    • plugin-bash-like
    • plugin-client-test/src/test/api2

3 files changed

+51
-2
lines changed

plugins/plugin-bash-like/fs/src/vfs/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717
import Debug from 'debug'
1818
import slash from 'slash'
1919
import { isAbsolute, join } from 'path'
20-
import { cwd, Arguments, ParsedOptions, REPL, Table, eventBus, getCurrentTab, inBrowser } from '@kui-shell/core'
20+
import {
21+
cwd,
22+
expandHomeDir,
23+
Arguments,
24+
ParsedOptions,
25+
REPL,
26+
Table,
27+
eventBus,
28+
getCurrentTab,
29+
inBrowser
30+
} from '@kui-shell/core'
2131

2232
import { FStat } from '../lib/fstat'
2333
import { KuiGlobOptions, GlobStats } from '../lib/glob'
@@ -183,7 +193,7 @@ export async function mount(vfs: VFS | VFSProducingFunction) {
183193

184194
/** @return the absolute path to `filepath` */
185195
export function absolute(filepath: string): string {
186-
return isAbsolute(filepath) ? filepath : join(cwd(), filepath)
196+
return isAbsolute(expandHomeDir(filepath)) ? filepath : join(cwd(), filepath)
187197
}
188198

189199
/** Lookup compiatible matching mount */

plugins/plugin-bash-like/src/test/bash-like/ls.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ describe(`directory listing ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
2828
.catch(Common.oops(this, true))
2929
)
3030

31+
it('should touch a test file in ~', () =>
32+
CLI.command(`touch ~/testls`, this.app)
33+
.then(ReplExpect.ok)
34+
.catch(Common.oops(this, true)))
35+
36+
it('should ls -l ~ and see ~/testls', () =>
37+
CLI.command('ls -l ~', this.app)
38+
.then(ReplExpect.okWith('testls'))
39+
.catch(Common.oops(this, true)))
40+
41+
it('should remove a test file in ~', () =>
42+
CLI.command(`rm -f ~/testls`, this.app)
43+
.then(ReplExpect.ok)
44+
.catch(Common.oops(this, true)))
45+
3146
it('should fail with 404 to ls a non-existing file', () =>
3247
CLI.command('ls fjdsioafjdsaioffsdaiofjdsaiofjdsaiofjdsaiofjdsaifjdsaiofsa', this.app)
3348
.then(ReplExpect.error(404))

plugins/plugin-client-test/src/test/api2/vfs.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,28 @@ describe('ls versus vfs', function(this: Common.ISuite) {
147147
CLI.command('ls -l F2', this.app)
148148
.then(ReplExpect.ok)
149149
.catch(Common.oops(this, true)))
150+
151+
// now try cd into ~
152+
it('should cd ~', () =>
153+
CLI.command('cd ~', this.app)
154+
.then(ReplExpect.ok)
155+
.catch(Common.oops(this, true)))
156+
it('should touch a testvfs file in ~', () =>
157+
CLI.command(`touch testvfs`, this.app)
158+
.then(ReplExpect.ok)
159+
.catch(Common.oops(this, true)))
160+
it('should ls -l ~ and see ~/testvfs', () =>
161+
CLI.command('ls -l ~', this.app)
162+
.then(ReplExpect.okWith('testvfs'))
163+
.catch(Common.oops(this)))
164+
it('should remove a testvfs file in ~', () =>
165+
CLI.command(`rm -f testvfs`, this.app)
166+
.then(ReplExpect.ok)
167+
.catch(Common.oops(this, true)))
168+
169+
// now try cd back to /kuifake/fake2
170+
it('should cd /kuifake/fake2', () =>
171+
CLI.command('cd /kuifake/fake2', this.app)
172+
.then(ReplExpect.okWithString('/kuifake/fake2'))
173+
.catch(Common.oops(this, true)))
150174
})

0 commit comments

Comments
 (0)