@jals1212/pi-spaces-cli 0.8.0 → 0.8.1

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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ commands and options and a patch version fixes.
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 0.8.1
10
+
11
+ ### Changed
12
+
13
+ - Completion lists the spaces first, in alphabetical order, then the
14
+ commands (also alphabetical), and keeps that order under fzf-tab: the
15
+ script sets `zstyle ':completion:*:pi-space:*' sort false`.
16
+ - A space's description says what it is and which program opens it:
17
+ `base home of gentle (gentle-shell --)`, `space of gentle (gentle-shell --)`,
18
+ instead of `the home gentle starts with` and the bare command.
19
+
9
20
  ## 0.8.0
10
21
 
11
22
  ### Changed
package/README.md CHANGED
@@ -203,7 +203,7 @@ It asks the command itself for the candidates each time, through the hidden `pi-
203
203
 
204
204
  | After | Candidates |
205
205
  | --- | --- |
206
- | `pi-space` (and the call options) | the commands, then `<profile>/base` and the spaces of every profile (`completion` is not offered, but works typed in full) |
206
+ | `pi-space` (and the call options) | `<profile>/base` and the spaces of every profile, in alphabetical order, then the commands (`completion` is not offered, but works typed in full) |
207
207
  | `--config`, `--dir` | files (the shell's own completion) |
208
208
  | `remove`, `rename` | the spaces of every profile (never `base`) |
209
209
  | `setup` | the spaces, `--every` ("every profile") and `<profile>/--every` |
@@ -212,7 +212,7 @@ It asks the command itself for the candidates each time, through the hidden `pi-
212
212
 
213
213
  There is no `--profile` to complete: the profile is the first word of the space. In first place the call options not typed yet come too, and `--help` and `--version` when nothing comes before. After a command word the options come too: `--help` for every command, and `--yes` and `--no-backup` after `remove`. zsh shows them once the word starts with `-`, so `pi-space new <TAB>` never fills in a lone `--help`.
214
214
 
215
- The candidates come in groups, each with a description, and zsh lists each group apart: commands, spaces, targets (`--every`), shells and options. The hidden `pi-space __complete` prints one `<group>\t<value>\t<description>` line per candidate (or the single line `__files__` when the shell should complete a file), so a script for another shell can use it.
215
+ The candidates come in groups, each with a description, and zsh lists each group apart: spaces, commands, targets (`--every`), shells and options. A space says what it is and which program opens it: `gentle/base -- base home of gentle (gentle-shell --)`, `gentle/work -- space of gentle (gentle-shell --)`. Spaces always come first, in alphabetical order, and the commands follow in alphabetical order: the script sets `zstyle ':completion:*:pi-space:*' sort false`, so neither zsh nor fzf-tab sorts them again into one list. The hidden `pi-space __complete` prints one `<group>\t<value>\t<description>` line per candidate (or the single line `__files__` when the shell should complete a file), so a script for another shell can use it.
216
216
 
217
217
  Completion also works through an abbreviation or alias: they expand first, so what the alias stands for is what completes. A config file that is wrong just gives no candidates; completion never prints an error.
218
218
 
package/dist/cli.js CHANGED
@@ -751,14 +751,18 @@ const ZSH_COMPLETION = [
751
751
  ' option) [[ "$PREFIX" == -* ]] && opts+=("$value:$text") ;;',
752
752
  " esac",
753
753
  " done",
754
+ // The spaces come first, as an unsorted group in pi-space's own (alphabetical) order; with the `sort false` style
755
+ // below, zsh and fzf-tab show every group in the order it is added here.
756
+ " (( $#spaces )) && _describe -t spaces 'space' spaces -V pi-space-spaces && ret=0",
754
757
  " (( $#cmds )) && _describe -t commands 'command' cmds && ret=0",
755
- " (( $#spaces )) && _describe -t spaces 'space' spaces && ret=0",
756
758
  " (( $#targets )) && _describe -t targets 'target' targets && ret=0",
757
759
  " (( $#shells )) && _describe -t shells 'shell' shells && ret=0",
758
760
  " (( $#opts )) && _describe -t options 'option' opts && ret=0",
759
761
  " return ret",
760
762
  "}",
761
763
  "compdef _pi_space pi-space",
764
+ // pi-space already gives its candidates in order (spaces first, alphabetical); zsh and fzf-tab must not resort them.
765
+ "zstyle ':completion:*:pi-space:*' sort false",
762
766
  "",
763
767
  ].join("\n");
764
768
 
@@ -785,10 +789,11 @@ function complete(words , io ) {
785
789
  return io.exit(0);
786
790
  }
787
791
 
788
- /** The commands with their summary; in first place `completion` is left out (it still works typed in full), after --help it is not. */
792
+ /** The commands with their summary, in alphabetical order; in first place `completion` is left out (it still works typed in full), after --help it is not. */
789
793
  function commandCandidates(withCompletion ) {
790
794
  return Object.entries(COMMANDS)
791
795
  .filter(([name]) => withCompletion || name !== "completion")
796
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
792
797
  .map(([name, help]) => candidate("command", name, help.summary));
793
798
  }
794
799
 
@@ -811,10 +816,13 @@ function firstOptions(call , alone ) {
811
816
 
812
817
  /** `<profile>/base`, if asked, then `<profile>/<name>`, for each profile in order. */
813
818
  function spaceCandidates(profiles , withBase ) {
814
- return profiles.flatMap((profile) => [
815
- ...(withBase ? [candidate("space", `${profile.name}/${BASE}`, `the home ${profile.name} starts with`)] : []),
816
- ...profile.spaces.map((name) => candidate("space", `${profile.name}/${name}`, profile.command)),
819
+ const spaces = profiles.flatMap((profile) => [
820
+ ...(withBase ? [{ value: `${profile.name}/${BASE}`, text: `base home of ${profile.name} (${profile.command})` }] : []),
821
+ ...profile.spaces.map((name) => ({ value: `${profile.name}/${name}`, text: `space of ${profile.name} (${profile.command})` })),
817
822
  ]);
823
+ // Alphabetical by the whole name, whatever the order of the profiles in the file.
824
+ spaces.sort((a, b) => (a.value < b.value ? -1 : a.value > b.value ? 1 : 0));
825
+ return spaces.map(({ value, text }) => candidate("space", value, text));
818
826
  }
819
827
 
820
828
  /** The `--every` targets: one for every profile, then one `<profile>/--every` for each. */
@@ -862,7 +870,7 @@ function candidates(words , io ) {
862
870
  return { name, command: profile.command ?? "pi", spaces: listSpaces(dirOverride ?? profile.dir) };
863
871
  });
864
872
  const rest = words.slice(index);
865
- if (rest.length === 0) return [...commandCandidates(false), ...spaceCandidates(profiles, true), ...firstOptions(call, index === 0)];
873
+ if (rest.length === 0) return [...spaceCandidates(profiles, true), ...commandCandidates(false), ...firstOptions(call, index === 0)];
866
874
  if (rest.length > 1) return [];
867
875
  if (isHelpFlag(rest[0])) return commandCandidates(true);
868
876
  if (!Object.hasOwn(COMMANDS, rest[0])) return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jals1212/pi-spaces-cli",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "The pi-space command: pick a space and start Pi in it. Companion to the Pi extension @jals1212/pi-spaces.",
5
5
  "license": "MIT",
6
6
  "author": "jals1212",