-
Notifications
You must be signed in to change notification settings - Fork 247
feat: support XDG_CONFIG_HOME #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sebdanielsson
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
sebdanielsson:sebdanielsson-support-xdg-base-dirs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−81
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import path from "node:path"; | ||
| import { resolveConfigFilePath, resolveResourcesPath, resolveXdgConfigHome, resolveXdgDataHome } from "../../utils/constants.js"; | ||
|
|
||
| const homeDirectory = path.join(path.sep, "home", "tester"); | ||
| const xdgConfigDirectory = path.join(path.sep, "tmp", "xdg"); | ||
| const xdgDataDirectory = path.join(path.sep, "tmp", "xdg-data"); | ||
|
|
||
| describe("resolveXdgConfigHome", () => { | ||
| test("uses an absolute XDG config directory on Unix", () => { | ||
| expect(resolveXdgConfigHome(xdgConfigDirectory, "linux")).toBe(xdgConfigDirectory); | ||
| }); | ||
|
|
||
| test.each([undefined, "", "relative/xdg", "~/.config"])("ignores an unset, empty, or non-absolute XDG config directory", (value) => { | ||
| expect(resolveXdgConfigHome(value, "linux")).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("preserves the legacy location on Windows", () => { | ||
| expect(resolveXdgConfigHome(xdgConfigDirectory, "win32")).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveResourcesPath", () => { | ||
| test("uses the legacy hidden directory without XDG_CONFIG_HOME", () => { | ||
| expect(resolveResourcesPath(homeDirectory, undefined, false)).toBe(path.join(homeDirectory, ".inshellisense")); | ||
| }); | ||
|
|
||
| test("uses an unhidden directory below XDG_DATA_HOME for a new installation", () => { | ||
| expect(resolveResourcesPath(homeDirectory, xdgDataDirectory, false)).toBe(path.join(xdgDataDirectory, "inshellisense")); | ||
| }); | ||
|
|
||
| test("preserves an existing legacy resource directory", () => { | ||
| expect(resolveResourcesPath(homeDirectory, xdgDataDirectory, true)).toBe(path.join(homeDirectory, ".inshellisense")); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveXdgDataHome", () => { | ||
| test("uses an absolute XDG data directory on Unix", () => { | ||
| expect(resolveXdgDataHome(xdgDataDirectory, homeDirectory, "linux")).toBe(xdgDataDirectory); | ||
| }); | ||
|
|
||
| test.each([undefined, "", "relative/xdg", "~/.local/share"])("uses the XDG default for an unset, empty, or non-absolute data directory", (value) => { | ||
| expect(resolveXdgDataHome(value, homeDirectory, "linux")).toBe(path.join(homeDirectory, ".local", "share")); | ||
| }); | ||
|
|
||
| test("preserves the legacy location on Windows", () => { | ||
| expect(resolveXdgDataHome(xdgDataDirectory, homeDirectory, "win32")).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveConfigFilePath", () => { | ||
| test("uses the XDG default below the home directory", () => { | ||
| expect(resolveConfigFilePath(homeDirectory, undefined)).toBe(path.join(homeDirectory, ".config", "inshellisense", "rc.toml")); | ||
| }); | ||
|
|
||
| test("uses XDG_CONFIG_HOME when configured", () => { | ||
| expect(resolveConfigFilePath(homeDirectory, xdgConfigDirectory)).toBe(path.join(xdgConfigDirectory, "inshellisense", "rc.toml")); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { getShellSourceCommand, hasLegacyShellConfig, Shell } from "../../utils/shell.js"; | ||
|
|
||
| describe("getShellSourceCommand", () => { | ||
| test.each([ | ||
| [Shell.Bash, "~/.inshellisense/init/bash/init.sh", "[ -f ~/.inshellisense/init/bash/init.sh ] && source ~/.inshellisense/init/bash/init.sh"], | ||
| [ | ||
| Shell.Powershell, | ||
| "~/.inshellisense/init/powershell/init.ps1", | ||
| "if ( Test-Path '~/.inshellisense/init/powershell/init.ps1' -PathType Leaf ) { . ~/.inshellisense/init/powershell/init.ps1 }", | ||
| ], | ||
| [ | ||
| Shell.Pwsh, | ||
| "~/.inshellisense/init/pwsh/init.ps1", | ||
| "if ( Test-Path '~/.inshellisense/init/pwsh/init.ps1' -PathType Leaf ) { . ~/.inshellisense/init/pwsh/init.ps1 }", | ||
| ], | ||
| [Shell.Zsh, "~/.inshellisense/init/zsh/init.zsh", "[[ -f ~/.inshellisense/init/zsh/init.zsh ]] && source ~/.inshellisense/init/zsh/init.zsh"], | ||
| [Shell.Fish, "~/.inshellisense/init/fish/init.fish", "test -f ~/.inshellisense/init/fish/init.fish && source ~/.inshellisense/init/fish/init.fish"], | ||
| [Shell.Xonsh, "~/.inshellisense/init/xonsh/init.xsh", 'p"~/.inshellisense/init/xonsh/init.xsh".exists() && source "~/.inshellisense/init/xonsh/init.xsh"'], | ||
| [Shell.Nushell, "~/.inshellisense/init/nu/init.nu", "if ( '~/.inshellisense/init/nu/init.nu' | path exists ) { source ~/.inshellisense/init/nu/init.nu }"], | ||
| ])("preserves the legacy %s command", (shell, initFilePath, expected) => { | ||
| expect(getShellSourceCommand(shell, initFilePath)).toBe(expected); | ||
| }); | ||
|
|
||
| test.each([ | ||
| [ | ||
| Shell.Bash, | ||
| "/tmp/xdg home/inshellisense/init/bash/init.sh", | ||
| "[ -f '/tmp/xdg home/inshellisense/init/bash/init.sh' ] && source '/tmp/xdg home/inshellisense/init/bash/init.sh'", | ||
| ], | ||
| [ | ||
| Shell.Pwsh, | ||
| "/tmp/xdg home/inshellisense/init/pwsh/init.ps1", | ||
| "if ( Test-Path '/tmp/xdg home/inshellisense/init/pwsh/init.ps1' -PathType Leaf ) { . '/tmp/xdg home/inshellisense/init/pwsh/init.ps1' }", | ||
| ], | ||
| [ | ||
| Shell.Zsh, | ||
| "/tmp/xdg home/inshellisense/init/zsh/init.zsh", | ||
| "[[ -f '/tmp/xdg home/inshellisense/init/zsh/init.zsh' ]] && source '/tmp/xdg home/inshellisense/init/zsh/init.zsh'", | ||
| ], | ||
| [ | ||
| Shell.Fish, | ||
| "/tmp/xdg home/inshellisense/init/fish/init.fish", | ||
| "test -f '/tmp/xdg home/inshellisense/init/fish/init.fish' && source '/tmp/xdg home/inshellisense/init/fish/init.fish'", | ||
| ], | ||
| [ | ||
| Shell.Xonsh, | ||
| "/tmp/xdg home/inshellisense/init/xonsh/init.xsh", | ||
| 'p"/tmp/xdg home/inshellisense/init/xonsh/init.xsh".exists() && source "/tmp/xdg home/inshellisense/init/xonsh/init.xsh"', | ||
| ], | ||
| [ | ||
| Shell.Nushell, | ||
| "/tmp/xdg home/inshellisense/init/nu/init.nu", | ||
| 'if ( "/tmp/xdg home/inshellisense/init/nu/init.nu" | path exists ) { source "/tmp/xdg home/inshellisense/init/nu/init.nu" }', | ||
| ], | ||
| ])("quotes an XDG path for %s", (shell, initFilePath, expected) => { | ||
| expect(getShellSourceCommand(shell, initFilePath)).toBe(expected); | ||
| }); | ||
|
|
||
| test("escapes shell-specific quote characters", () => { | ||
| expect(getShellSourceCommand(Shell.Bash, "/tmp/user's config/init.sh")).toContain("'/tmp/user'\\''s config/init.sh'"); | ||
| expect(getShellSourceCommand(Shell.Pwsh, "/tmp/user's config/init.ps1")).toContain("'/tmp/user''s config/init.ps1'"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("hasLegacyShellConfig", () => { | ||
| test("detects the original shell plugin marker", () => { | ||
| expect(hasLegacyShellConfig("# inshellisense shell plugin", Shell.Zsh, false)).toBe(true); | ||
| }); | ||
|
|
||
| test("detects the original generated plugin path", () => { | ||
| expect(hasLegacyShellConfig("source ~/.inshellisense/zsh/init.zsh", Shell.Zsh, false)).toBe(true); | ||
| }); | ||
|
|
||
| test("detects the current legacy path after resources migrate", () => { | ||
| expect(hasLegacyShellConfig("source ~/.inshellisense/init/zsh/init.zsh", Shell.Zsh, true)).toBe(true); | ||
| }); | ||
|
|
||
| test("allows the current legacy path before resources migrate", () => { | ||
| expect(hasLegacyShellConfig("source ~/.inshellisense/init/zsh/init.zsh", Shell.Zsh, false)).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will break git bash on windows due to the different path separator. using cygpath to convert into a unix style path and then sourcing the preexec should fix the issue