@narumitw/pi-starship 0.49.3 → 0.49.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +2 -4
  2. package/package.json +4 -8
  3. package/src/command-contract.ts +13 -0
  4. package/src/command-inspector.ts +198 -0
  5. package/src/command-preview.ts +206 -0
  6. package/src/commands.ts +575 -0
  7. package/src/config.ts +794 -0
  8. package/src/format/formatter.ts +275 -0
  9. package/src/format/style.ts +278 -0
  10. package/src/index.ts +1 -1
  11. package/src/modules/activity.ts +38 -0
  12. package/src/modules/brand.ts +13 -0
  13. package/src/modules/cache.ts +23 -0
  14. package/src/modules/catalog.ts +124 -0
  15. package/src/modules/cloud.ts +74 -0
  16. package/src/modules/context.ts +33 -0
  17. package/src/modules/cost.ts +31 -0
  18. package/src/modules/deployment.ts +61 -0
  19. package/src/modules/development.ts +112 -0
  20. package/src/modules/directory.ts +151 -0
  21. package/src/modules/display.ts +14 -0
  22. package/src/modules/execution.ts +84 -0
  23. package/src/modules/extension-status.ts +93 -0
  24. package/src/modules/fill.ts +14 -0
  25. package/src/modules/git/branch.ts +31 -0
  26. package/src/modules/git/commit.ts +29 -0
  27. package/src/modules/git/metrics.ts +26 -0
  28. package/src/modules/git/runtime.ts +415 -0
  29. package/src/modules/git/state.ts +21 -0
  30. package/src/modules/git/status.ts +87 -0
  31. package/src/modules/git/worktree.ts +16 -0
  32. package/src/modules/github-pr.ts +24 -0
  33. package/src/modules/helpers.ts +5 -0
  34. package/src/modules/index.ts +31 -0
  35. package/src/modules/inspection.ts +138 -0
  36. package/src/modules/languages.ts +87 -0
  37. package/src/modules/model.ts +85 -0
  38. package/src/modules/package.ts +17 -0
  39. package/src/modules/provider.ts +13 -0
  40. package/src/modules/render.ts +166 -0
  41. package/src/modules/terminal.ts +60 -0
  42. package/src/modules/thinking.ts +13 -0
  43. package/src/modules/time.ts +20 -0
  44. package/src/modules/tokens.ts +18 -0
  45. package/src/modules/truncation.ts +37 -0
  46. package/src/modules/turn.ts +13 -0
  47. package/src/modules/types.ts +189 -0
  48. package/src/modules/workspace-helpers.ts +10 -0
  49. package/src/pi-starship.ts +609 -0
  50. package/src/runtime/cloud.ts +166 -0
  51. package/src/runtime/command.ts +123 -0
  52. package/src/runtime/deployment.ts +201 -0
  53. package/src/runtime/development.ts +153 -0
  54. package/src/runtime/execution.ts +151 -0
  55. package/src/runtime/github-pr.ts +332 -0
  56. package/src/runtime/helpers.ts +274 -0
  57. package/src/runtime/languages.ts +205 -0
  58. package/src/runtime/package.ts +112 -0
  59. package/src/runtime/refresh-controller.ts +107 -0
  60. package/src/runtime/types.ts +63 -0
  61. package/src/runtime/workspace.ts +147 -0
  62. package/src/usage.ts +53 -0
  63. package/dist/chunks/chunk-CKNSOLSW.ts +0 -10
  64. package/dist/chunks/chunk-CKNSOLSW.ts.map +0 -7
  65. package/dist/chunks/chunk-G2GG2V6Q.ts +0 -218
  66. package/dist/chunks/chunk-G2GG2V6Q.ts.map +0 -7
  67. package/dist/chunks/chunk-Q6DLIM7H.ts +0 -2492
  68. package/dist/chunks/chunk-Q6DLIM7H.ts.map +0 -7
  69. package/dist/chunks/cloud-JBSZWTB6.ts +0 -142
  70. package/dist/chunks/cloud-JBSZWTB6.ts.map +0 -7
  71. package/dist/chunks/commands-BSQZ2R4M.ts +0 -757
  72. package/dist/chunks/commands-BSQZ2R4M.ts.map +0 -7
  73. package/dist/chunks/deployment-ZNYM4B6W.ts +0 -172
  74. package/dist/chunks/deployment-ZNYM4B6W.ts.map +0 -7
  75. package/dist/chunks/development-TNWZ5SRC.ts +0 -132
  76. package/dist/chunks/development-TNWZ5SRC.ts.map +0 -7
  77. package/dist/chunks/execution-QHAP4U33.ts +0 -132
  78. package/dist/chunks/execution-QHAP4U33.ts.map +0 -7
  79. package/dist/chunks/languages-DPWDCH6Q.ts +0 -184
  80. package/dist/chunks/languages-DPWDCH6Q.ts.map +0 -7
  81. package/dist/chunks/package-MXN2YFLX.ts +0 -104
  82. package/dist/chunks/package-MXN2YFLX.ts.map +0 -7
  83. package/dist/pi-starship.ts +0 -1350
  84. package/dist/pi-starship.ts.map +0 -7
@@ -0,0 +1,124 @@
1
+ import { activityModule } from "./activity.js";
2
+ import { brandModule } from "./brand.js";
3
+ import { cacheModule } from "./cache.js";
4
+ import { cloudModules } from "./cloud.js";
5
+ import { contextModule } from "./context.js";
6
+ import { costModule } from "./cost.js";
7
+ import { deploymentModules } from "./deployment.js";
8
+ import { developmentModules } from "./development.js";
9
+ import { directoryModule } from "./directory.js";
10
+ import { executionModules } from "./execution.js";
11
+ import { extensionStatusModule } from "./extension-status.js";
12
+ import { fillModule } from "./fill.js";
13
+ import { gitBranchModule } from "./git/branch.js";
14
+ import { gitCommitModule } from "./git/commit.js";
15
+ import { gitMetricsModule } from "./git/metrics.js";
16
+ import { gitStateModule } from "./git/state.js";
17
+ import { gitStatusModule } from "./git/status.js";
18
+ import { gitWorktreeModule } from "./git/worktree.js";
19
+ import { githubPrModule } from "./github-pr.js";
20
+ import { languageModules } from "./languages.js";
21
+ import { modelModule } from "./model.js";
22
+ import { packageModule } from "./package.js";
23
+ import { providerModule } from "./provider.js";
24
+ import { thinkingModule } from "./thinking.js";
25
+ import { timeModule } from "./time.js";
26
+ import { tokensModule } from "./tokens.js";
27
+ import { turnModule } from "./turn.js";
28
+ import type { ModuleDefinition } from "./types.js";
29
+
30
+ const MODULE_IMPLEMENTATIONS = [
31
+ brandModule,
32
+ providerModule,
33
+ modelModule,
34
+ thinkingModule,
35
+ directoryModule,
36
+ gitWorktreeModule,
37
+ gitBranchModule,
38
+ githubPrModule,
39
+ gitCommitModule,
40
+ gitStateModule,
41
+ gitMetricsModule,
42
+ gitStatusModule,
43
+ packageModule,
44
+ ...languageModules,
45
+ ...developmentModules,
46
+ ...deploymentModules,
47
+ ...cloudModules,
48
+ ...executionModules,
49
+ activityModule,
50
+ contextModule,
51
+ tokensModule,
52
+ cacheModule,
53
+ costModule,
54
+ timeModule,
55
+ turnModule,
56
+ fillModule,
57
+ // Keep arbitrary third-party statuses after the native modules.
58
+ extensionStatusModule,
59
+ ] as const satisfies readonly ModuleDefinition<string>[];
60
+
61
+ export type ModuleName = (typeof MODULE_IMPLEMENTATIONS)[number]["name"];
62
+
63
+ const MODULE_DESCRIPTIONS = {
64
+ activity: "Current Pi activity or most recently completed tool.",
65
+ aws: "Active AWS profile and region.",
66
+ azure: "Active Azure subscription and optional username.",
67
+ brand: "pi-starship brand mark.",
68
+ bun: "Bun version detected in the current workspace.",
69
+ cache: "Prompt-cache usage and latest cache hit rate.",
70
+ conda: "Active Conda environment.",
71
+ container: "Current container or remote development environment.",
72
+ context: "Current model context-window usage.",
73
+ cost: "Reported estimated session cost or subscription state.",
74
+ deno: "Deno version detected in the current workspace.",
75
+ directory: "Current working directory.",
76
+ direnv: "Current direnv loading and permission state.",
77
+ docker_context: "Active Docker context.",
78
+ extension_status: "Statuses published through Pi's extension-neutral status map.",
79
+ fill: "Flexible spacing that aligns content within the footer width.",
80
+ gcloud: "Active Google Cloud project, account, and region.",
81
+ git_branch: "Current Git branch and upstream identity.",
82
+ git_commit: "Current Git commit hash or tag.",
83
+ git_metrics: "Added and deleted lines in the current Git worktree.",
84
+ git_state: "Current Git operation such as merge, rebase, or cherry-pick.",
85
+ git_status: "Current Git worktree and index status summary.",
86
+ git_worktree: "Current linked Git worktree identity.",
87
+ github_pr: "Current branch's GitHub pull request state, checks, and review.",
88
+ golang: "Go version detected in the current workspace.",
89
+ guix_shell: "Current Guix shell state.",
90
+ hostname: "Current host name, normally shown for remote sessions.",
91
+ kubernetes: "Active Kubernetes context, namespace, cluster, and user.",
92
+ mise: "Current mise configuration health.",
93
+ model: "Current Pi model.",
94
+ nix_shell: "Current Nix shell state, name, and nesting level.",
95
+ nodejs: "Node.js version detected in the current workspace.",
96
+ openstack: "Active OpenStack cloud and project.",
97
+ os: "Current operating system identity.",
98
+ package: "Current workspace package name and version.",
99
+ pixi: "Active Pixi environment and project.",
100
+ provider: "Current Pi model provider.",
101
+ python: "Python version, virtual environment, and pyenv state.",
102
+ rust: "Rust toolchain detected in the current workspace.",
103
+ terraform: "Active Terraform workspace and version.",
104
+ thinking: "Current Pi thinking level or streaming state.",
105
+ time: "Current local time.",
106
+ tokens: "Session input and output token totals.",
107
+ turn: "Current user-turn count.",
108
+ username: "Current user identity when configured to display.",
109
+ } as const satisfies Record<ModuleName, string>;
110
+
111
+ export type CatalogModuleDefinition<Name extends string = ModuleName> = ModuleDefinition<Name> & {
112
+ readonly description: string;
113
+ };
114
+
115
+ export const MODULE_DEFINITIONS: readonly CatalogModuleDefinition[] = MODULE_IMPLEMENTATIONS.map(
116
+ (definition) => ({
117
+ ...definition,
118
+ description: MODULE_DESCRIPTIONS[definition.name],
119
+ }),
120
+ );
121
+
122
+ export const MODULE_NAMES: readonly ModuleName[] = MODULE_IMPLEMENTATIONS.map(
123
+ (definition) => definition.name,
124
+ );
@@ -0,0 +1,74 @@
1
+ import { defineModule, type ModuleDefinition, type ModuleOptionSchema } from "./types.js";
2
+ import { workspaceModuleValues } from "./workspace-helpers.js";
3
+
4
+ function cloudModule<const Name extends string>(definition: {
5
+ name: Name;
6
+ variables: readonly string[];
7
+ format: string;
8
+ symbol: string;
9
+ style: string;
10
+ options: Readonly<Record<string, ModuleOptionSchema>>;
11
+ }): ModuleDefinition<Name> {
12
+ return defineModule({
13
+ name: definition.name,
14
+ variables: ["symbol", ...definition.variables],
15
+ defaults: {
16
+ format: definition.format,
17
+ symbol: definition.symbol,
18
+ style: definition.style,
19
+ disabled: false,
20
+ },
21
+ options: definition.options,
22
+ values: (context) => workspaceModuleValues(definition.name, context),
23
+ });
24
+ }
25
+
26
+ export const awsModule = cloudModule({
27
+ name: "aws",
28
+ variables: ["profile", "region"],
29
+ format: "on [$symbol($profile )(\\($region\\) )]($style)",
30
+ symbol: "☁️ ",
31
+ style: "bold yellow",
32
+ options: {
33
+ profile_aliases: { kind: "string-map", default: {} },
34
+ region_aliases: { kind: "string-map", default: {} },
35
+ },
36
+ });
37
+
38
+ export const gcloudModule = cloudModule({
39
+ name: "gcloud",
40
+ variables: ["active", "account", "domain", "project", "region"],
41
+ format: "on [$symbol$project]($style) ",
42
+ symbol: "☁️ ",
43
+ style: "bold blue",
44
+ options: {
45
+ project_aliases: { kind: "string-map", default: {} },
46
+ region_aliases: { kind: "string-map", default: {} },
47
+ },
48
+ });
49
+
50
+ export const azureModule = cloudModule({
51
+ name: "azure",
52
+ variables: ["subscription", "username"],
53
+ format: "on [$symbol$subscription]($style) ",
54
+ symbol: "󰠅 ",
55
+ style: "blue bold",
56
+ options: {
57
+ subscription_aliases: { kind: "string-map", default: {} },
58
+ show_username: { kind: "boolean", default: false },
59
+ },
60
+ });
61
+
62
+ export const openstackModule = cloudModule({
63
+ name: "openstack",
64
+ variables: ["cloud", "project"],
65
+ format: "on [$symbol$cloud( \\($project\\))]($style) ",
66
+ symbol: "☁️ ",
67
+ style: "bold yellow",
68
+ options: {
69
+ cloud_aliases: { kind: "string-map", default: {} },
70
+ project_aliases: { kind: "string-map", default: {} },
71
+ },
72
+ });
73
+
74
+ export const cloudModules = [awsModule, gcloudModule, azureModule, openstackModule] as const;
@@ -0,0 +1,33 @@
1
+ import { resolveDisplayStyle } from "./display.js";
2
+ import { formatCount } from "./helpers.js";
3
+ import { defineModule } from "./types.js";
4
+
5
+ export const contextModule = defineModule({
6
+ name: "context",
7
+ variables: ["symbol", "percentage", "tokens", "window"],
8
+ defaults: {
9
+ format: "[$symbol ctx $percentage ]($style)",
10
+ symbol: "🪟",
11
+ style: "none",
12
+ disabled: false,
13
+ },
14
+ displayDefaults: [
15
+ { threshold: 0, style: "bold green", hidden: true },
16
+ { threshold: 30, style: "bold green", hidden: false },
17
+ { threshold: 60, style: "bold yellow", hidden: false },
18
+ { threshold: 80, style: "bold red", hidden: false },
19
+ ],
20
+ styleVariables: ["style"],
21
+ resolveStyleVariables: ({ runtime, display }) => {
22
+ const style = resolveDisplayStyle(display, runtime.contextUsage?.percent);
23
+ return style === undefined ? undefined : { style };
24
+ },
25
+ values: ({ runtime }) => {
26
+ const percent = runtime.contextUsage?.percent;
27
+ return {
28
+ percentage: percent === null || percent === undefined ? "?" : `${percent.toFixed(1)}%`,
29
+ tokens: formatCount(runtime.contextUsage?.tokens ?? 0),
30
+ window: formatCount(runtime.contextUsage?.contextWindow ?? 0),
31
+ };
32
+ },
33
+ });
@@ -0,0 +1,31 @@
1
+ import { resolveDisplayStyle } from "./display.js";
2
+ import { defineModule } from "./types.js";
3
+
4
+ export const costModule = defineModule({
5
+ name: "cost",
6
+ variables: ["symbol", "cost", "subscription"],
7
+ defaults: {
8
+ format: "[ $symbol \\$$cost( $subscription) ]($style)",
9
+ symbol: "💸",
10
+ style: "none",
11
+ disabled: false,
12
+ },
13
+ displayDefaults: [
14
+ { threshold: 0, style: "bold green", hidden: true },
15
+ { threshold: 1, style: "bold yellow", hidden: false },
16
+ { threshold: 5, style: "bold red", hidden: false },
17
+ ],
18
+ styleVariables: ["style"],
19
+ resolveStyleVariables: ({ runtime, display }) => {
20
+ const style = resolveDisplayStyle(display, runtime.tokenTotals.cost);
21
+ return style === undefined ? undefined : { style };
22
+ },
23
+ values: ({ runtime }) => ({
24
+ cost: formatCost(runtime.tokenTotals.cost),
25
+ subscription: runtime.usingSubscription ? "(sub)" : "",
26
+ }),
27
+ });
28
+
29
+ function formatCost(value: number): string {
30
+ return value.toFixed(value >= 1 ? 2 : 3);
31
+ }
@@ -0,0 +1,61 @@
1
+ import { defineModule } from "./types.js";
2
+ import { workspaceModuleValues } from "./workspace-helpers.js";
3
+
4
+ const directDetection = {
5
+ detect_files: { kind: "string-array", default: [] },
6
+ detect_extensions: { kind: "string-array", default: [] },
7
+ detect_folders: { kind: "string-array", default: [] },
8
+ } as const;
9
+
10
+ export const dockerContextModule = defineModule({
11
+ name: "docker_context",
12
+ variables: ["symbol", "context"],
13
+ defaults: {
14
+ format: "via [$symbol$context]($style) ",
15
+ symbol: " ",
16
+ style: "blue bold",
17
+ disabled: false,
18
+ },
19
+ options: {
20
+ ...directDetection,
21
+ only_with_files: { kind: "boolean", default: false },
22
+ },
23
+ values: (context) => workspaceModuleValues("docker_context", context),
24
+ });
25
+
26
+ export const kubernetesModule = defineModule({
27
+ name: "kubernetes",
28
+ variables: ["symbol", "context", "namespace", "cluster", "user"],
29
+ defaults: {
30
+ format: "on [$symbol$context( \\($namespace\\))]($style) ",
31
+ symbol: "☸ ",
32
+ style: "cyan bold",
33
+ disabled: false,
34
+ },
35
+ options: {
36
+ context_aliases: { kind: "string-map", default: {} },
37
+ namespace_aliases: { kind: "string-map", default: {} },
38
+ cluster_aliases: { kind: "string-map", default: {} },
39
+ user_aliases: { kind: "string-map", default: {} },
40
+ max_config_files: { kind: "integer", default: 8, minimum: 1, maximum: 32 },
41
+ },
42
+ values: (context) => workspaceModuleValues("kubernetes", context),
43
+ });
44
+
45
+ export const terraformModule = defineModule({
46
+ name: "terraform",
47
+ variables: ["symbol", "workspace", "version"],
48
+ defaults: {
49
+ format: "via [$symbol$workspace]($style) ",
50
+ symbol: "💠 ",
51
+ style: "bold 105",
52
+ disabled: false,
53
+ },
54
+ options: {
55
+ ...directDetection,
56
+ version_format: { kind: "string", default: "v$raw" },
57
+ },
58
+ values: (context) => workspaceModuleValues("terraform", context),
59
+ });
60
+
61
+ export const deploymentModules = [dockerContextModule, kubernetesModule, terraformModule] as const;
@@ -0,0 +1,112 @@
1
+ import { truncatePathComponents } from "./truncation.js";
2
+ import { defineModule, type ModuleDefinition, type ModuleOptionSchema } from "./types.js";
3
+ import { workspaceModuleValues } from "./workspace-helpers.js";
4
+
5
+ function developmentModule<const Name extends string>(definition: {
6
+ name: Name;
7
+ variables: readonly string[];
8
+ format: string;
9
+ symbol: string;
10
+ style: string;
11
+ options?: Readonly<Record<string, ModuleOptionSchema>>;
12
+ }): ModuleDefinition<Name> {
13
+ return defineModule({
14
+ name: definition.name,
15
+ variables: ["symbol", ...definition.variables],
16
+ defaults: {
17
+ format: definition.format,
18
+ symbol: definition.symbol,
19
+ style: definition.style,
20
+ disabled: false,
21
+ },
22
+ options: definition.options,
23
+ values: (context) => workspaceModuleValues(definition.name, context),
24
+ });
25
+ }
26
+
27
+ const directDetection = {
28
+ detect_files: { kind: "string-array", default: [] },
29
+ detect_extensions: { kind: "string-array", default: [] },
30
+ detect_folders: { kind: "string-array", default: [] },
31
+ } as const;
32
+
33
+ export const miseModule = developmentModule({
34
+ name: "mise",
35
+ variables: ["health"],
36
+ format: "via [$symbol$health]($style) ",
37
+ symbol: "mise ",
38
+ style: "bold purple",
39
+ options: directDetection,
40
+ });
41
+
42
+ export const direnvModule = developmentModule({
43
+ name: "direnv",
44
+ variables: ["rc_path", "allowed", "loaded"],
45
+ format: "[$symbol$loaded]($style) ",
46
+ symbol: "direnv ",
47
+ style: "bold bright-yellow",
48
+ options: directDetection,
49
+ });
50
+
51
+ export const condaModule = defineModule({
52
+ name: "conda",
53
+ variables: ["symbol", "environment"],
54
+ defaults: {
55
+ format: "via [$symbol$environment]($style) ",
56
+ symbol: "🅒 ",
57
+ style: "green bold",
58
+ disabled: false,
59
+ },
60
+ options: {
61
+ ignore_base: { kind: "boolean", default: true },
62
+ truncation_length: { kind: "integer", default: 1, minimum: 0, maximum: 1_000_000 },
63
+ },
64
+ values: (context) => {
65
+ const values = workspaceModuleValues("conda", context);
66
+ const environment = values?.environment;
67
+ if (!environment) return undefined;
68
+ const length =
69
+ typeof context.options.truncation_length === "number" ? context.options.truncation_length : 1;
70
+ return {
71
+ environment: truncatePathComponents(environment, length).value,
72
+ };
73
+ },
74
+ });
75
+
76
+ export const pixiModule = developmentModule({
77
+ name: "pixi",
78
+ variables: ["version", "environment", "project_name"],
79
+ format: "via [$symbol$environment]($style) ",
80
+ symbol: "🧚 ",
81
+ style: "yellow bold",
82
+ options: {
83
+ ...directDetection,
84
+ version_format: { kind: "string", default: "v$raw" },
85
+ show_default_environment: { kind: "boolean", default: false },
86
+ },
87
+ });
88
+
89
+ export const nixShellModule = developmentModule({
90
+ name: "nix_shell",
91
+ variables: ["state", "name", "level"],
92
+ format: "via [$symbol$state( \\($name\\))]($style) ",
93
+ symbol: " ",
94
+ style: "bold blue",
95
+ });
96
+
97
+ export const guixShellModule = developmentModule({
98
+ name: "guix_shell",
99
+ variables: ["state"],
100
+ format: "via [$symbol]($style) ",
101
+ symbol: "🐃 ",
102
+ style: "yellow bold",
103
+ });
104
+
105
+ export const developmentModules = [
106
+ miseModule,
107
+ direnvModule,
108
+ condaModule,
109
+ pixiModule,
110
+ nixShellModule,
111
+ guixShellModule,
112
+ ] as const;
@@ -0,0 +1,151 @@
1
+ import { basename, isAbsolute, relative, sep } from "node:path";
2
+ import { sanitizeTerminalText } from "./terminal.js";
3
+ import {
4
+ graphemes,
5
+ toSlashPath,
6
+ truncatePathComponents,
7
+ useNativePathSeparator,
8
+ } from "./truncation.js";
9
+ import { defineModule, type ModuleOptionValue } from "./types.js";
10
+
11
+ export const directoryModule = defineModule({
12
+ name: "directory",
13
+ variables: ["symbol", "path", "full_path"],
14
+ defaults: {
15
+ format: "[ $symbol $path ]($style)",
16
+ symbol: "📁",
17
+ style: "cyan bold",
18
+ disabled: false,
19
+ },
20
+ options: {
21
+ truncation_length: { kind: "integer", default: 3, minimum: 0, maximum: 1_000_000 },
22
+ truncate_to_repo: { kind: "boolean", default: true },
23
+ fish_style_pwd_dir_length: { kind: "integer", default: 0, minimum: 0, maximum: 1_000 },
24
+ truncation_symbol: { kind: "string", default: "" },
25
+ home_symbol: { kind: "string", default: "~" },
26
+ use_os_path_sep: { kind: "boolean", default: true },
27
+ substitutions: { kind: "string-map", default: {} },
28
+ },
29
+ values: ({ runtime, options }) => {
30
+ const fullPath = runtime.cwd;
31
+ const home = runtime.homeDir;
32
+ const repoRoot = runtime.gitRoot;
33
+ const homeSymbol = stringOption(options, "home_symbol", "~");
34
+ const truncateToRepo = booleanOption(options, "truncate_to_repo", true);
35
+ const substitutions = mapOption(options, "substitutions");
36
+ const homeContracted = contractPath(fullPath, home, homeSymbol);
37
+ const repoContracted =
38
+ truncateToRepo && repoRoot && (!home || !samePath(repoRoot, home))
39
+ ? contractRepositoryPath(fullPath, repoRoot)
40
+ : undefined;
41
+ let path = sanitizeTerminalText(repoContracted ?? homeContracted);
42
+ let truncated = repoContracted !== undefined;
43
+
44
+ for (const [from, to] of Object.entries(substitutions)) {
45
+ if (from) path = path.replaceAll(from, to);
46
+ }
47
+
48
+ const componentResult = truncatePathComponents(
49
+ path,
50
+ numberOption(options, "truncation_length", 3),
51
+ );
52
+ path = componentResult.value;
53
+ truncated ||= componentResult.truncated;
54
+
55
+ if (truncated) {
56
+ const fishLength = numberOption(options, "fish_style_pwd_dir_length", 0);
57
+ if (fishLength > 0 && Object.keys(substitutions).length === 0) {
58
+ path = `${fishPrefix(homeContracted, path, fishLength)}${path}`;
59
+ } else {
60
+ path = `${stringOption(options, "truncation_symbol", "")}${path}`;
61
+ }
62
+ }
63
+
64
+ if (booleanOption(options, "use_os_path_sep", true)) path = useNativePathSeparator(path);
65
+ const fallback = basename(fullPath) || fullPath;
66
+ return {
67
+ path: sanitizeTerminalText(path || fallback),
68
+ full_path: sanitizeTerminalText(fullPath),
69
+ };
70
+ },
71
+ });
72
+
73
+ function contractPath(path: string, root: string | undefined, replacement: string): string {
74
+ if (!root) return toSlashPath(path);
75
+ const child = relativeWithin(path, root);
76
+ if (child === undefined) return toSlashPath(path);
77
+ return child ? `${replacement}/${child}` : replacement;
78
+ }
79
+
80
+ function contractRepositoryPath(path: string, root: string): string | undefined {
81
+ const child = relativeWithin(path, root);
82
+ if (child === undefined) return undefined;
83
+ const name = basename(root) || toSlashPath(root);
84
+ return child ? `${name}/${child}` : name;
85
+ }
86
+
87
+ function relativeWithin(path: string, root: string): string | undefined {
88
+ const child = relative(root, path);
89
+ if (child === "") return "";
90
+ if (child === ".." || child.startsWith(`..${sep}`) || isAbsolute(child)) return undefined;
91
+ return toSlashPath(child);
92
+ }
93
+
94
+ function samePath(left: string, right: string): boolean {
95
+ return relative(left, right) === "";
96
+ }
97
+
98
+ function fishPrefix(source: string, displayed: string, length: number): string {
99
+ const prefix = source.endsWith(displayed) ? source.slice(0, -displayed.length) : "";
100
+ if (!prefix) return "";
101
+ return prefix
102
+ .split("/")
103
+ .map((component) => abbreviateComponent(component, length))
104
+ .join("/");
105
+ }
106
+
107
+ function abbreviateComponent(component: string, length: number): string {
108
+ if (!component) return "";
109
+ const parts = graphemes(component);
110
+ if (parts.length <= length) return component;
111
+ return component.startsWith(".")
112
+ ? parts.slice(0, length + 1).join("")
113
+ : parts.slice(0, length).join("");
114
+ }
115
+
116
+ function numberOption(
117
+ options: Readonly<Record<string, ModuleOptionValue>>,
118
+ name: string,
119
+ fallback: number,
120
+ ): number {
121
+ const value = options[name];
122
+ return typeof value === "number" ? value : fallback;
123
+ }
124
+
125
+ function stringOption(
126
+ options: Readonly<Record<string, ModuleOptionValue>>,
127
+ name: string,
128
+ fallback: string,
129
+ ): string {
130
+ const value = options[name];
131
+ return typeof value === "string" ? value : fallback;
132
+ }
133
+
134
+ function booleanOption(
135
+ options: Readonly<Record<string, ModuleOptionValue>>,
136
+ name: string,
137
+ fallback: boolean,
138
+ ): boolean {
139
+ const value = options[name];
140
+ return typeof value === "boolean" ? value : fallback;
141
+ }
142
+
143
+ function mapOption(
144
+ options: Readonly<Record<string, ModuleOptionValue>>,
145
+ name: string,
146
+ ): Readonly<Record<string, string>> {
147
+ const value = options[name];
148
+ return value && typeof value === "object" && !Array.isArray(value)
149
+ ? (value as Readonly<Record<string, string>>)
150
+ : {};
151
+ }
@@ -0,0 +1,14 @@
1
+ import type { ModuleDisplayConfig } from "./types.js";
2
+
3
+ export function resolveDisplayStyle(
4
+ display: readonly ModuleDisplayConfig[],
5
+ value: number | null | undefined,
6
+ ): string | undefined {
7
+ if (value === null || value === undefined || !Number.isFinite(value)) return undefined;
8
+ let selected: ModuleDisplayConfig | undefined;
9
+ for (const entry of display) {
10
+ if (entry.threshold > value) continue;
11
+ if (!selected || entry.threshold >= selected.threshold) selected = entry;
12
+ }
13
+ return selected && !selected.hidden ? selected.style : undefined;
14
+ }
@@ -0,0 +1,84 @@
1
+ import { defineModule } from "./types.js";
2
+ import { workspaceModuleValues } from "./workspace-helpers.js";
3
+
4
+ export const osModule = defineModule({
5
+ name: "os",
6
+ variables: ["symbol", "type", "name", "version", "edition", "codename"],
7
+ defaults: {
8
+ format: "[$symbol($name )]($style)",
9
+ symbol: "",
10
+ style: "bold white",
11
+ disabled: true,
12
+ },
13
+ options: {
14
+ symbols: {
15
+ kind: "string-map",
16
+ default: { linux: "🐧 ", macos: "🍎 ", windows: " ", wsl: " " },
17
+ },
18
+ },
19
+ values: (context) => workspaceModuleValues("os", context),
20
+ });
21
+
22
+ export const containerModule = defineModule({
23
+ name: "container",
24
+ variables: ["symbol", "name", "type"],
25
+ defaults: {
26
+ format: "[$symbol$name]($style) ",
27
+ symbol: "⬢ ",
28
+ style: "bold red dimmed",
29
+ disabled: false,
30
+ },
31
+ values: (context) => workspaceModuleValues("container", context),
32
+ });
33
+
34
+ export const hostnameModule = defineModule({
35
+ name: "hostname",
36
+ variables: ["symbol", "hostname", "ssh_symbol"],
37
+ defaults: {
38
+ format: "[$ssh_symbol$hostname]($style) in ",
39
+ symbol: "",
40
+ style: "bold dimmed green",
41
+ disabled: false,
42
+ },
43
+ options: {
44
+ ssh_only: { kind: "boolean", default: true },
45
+ trim_at: { kind: "string", default: "." },
46
+ aliases: { kind: "string-map", default: {} },
47
+ },
48
+ values: (context) => workspaceModuleValues("hostname", context),
49
+ });
50
+
51
+ export const usernameModule = defineModule({
52
+ name: "username",
53
+ variables: ["symbol", "user"],
54
+ defaults: {
55
+ format: "[$user]($style) in ",
56
+ symbol: "",
57
+ style: "none",
58
+ disabled: false,
59
+ },
60
+ styleDefaults: {
61
+ style_user: "yellow bold",
62
+ style_root: "red bold",
63
+ },
64
+ styleVariables: ["style"],
65
+ resolveStyleVariables: ({ runtime, styles }) => ({
66
+ style:
67
+ runtime.workspace?.styleSelectors?.username === "root"
68
+ ? (styles.style_root ?? "")
69
+ : (styles.style_user ?? ""),
70
+ }),
71
+ options: {
72
+ show_always: { kind: "boolean", default: false },
73
+ aliases: { kind: "string-map", default: {} },
74
+ detect_env_vars: { kind: "string-array", default: [] },
75
+ },
76
+ values: (context) => workspaceModuleValues("username", context),
77
+ });
78
+
79
+ export const executionModules = [
80
+ osModule,
81
+ containerModule,
82
+ hostnameModule,
83
+ usernameModule,
84
+ ] as const;