1ls 0.1.13 → 0.1.15
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/README.md +8 -0
- package/dist/browser/index.js +1 -1
- package/dist/completions/1ls.bash +6 -6
- package/dist/completions/1ls.zsh +109 -65
- package/dist/completions/constants.d.ts +124 -0
- package/dist/completions/constants.ts +41 -0
- package/dist/completions/index.d.ts +17 -0
- package/dist/completions/index.ts +197 -0
- package/dist/completions/install-completions.sh +8 -7
- package/dist/index.js +51 -51
- package/dist/version.d.ts +1 -1
- package/package.json +16 -10
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { SHORTCUTS, BUILTIN_SHORTCUTS } from "../shortcuts/constants";
|
|
2
|
+
import { BUILTIN_FUNCTIONS } from "../navigator/builtins/constants";
|
|
3
|
+
import { VALID_OUTPUT_FORMATS } from "../constants";
|
|
4
|
+
import { CLI_FLAGS, JSON_PATH_PATTERNS } from "./constants";
|
|
5
|
+
import type { CliFlag, JsonPathPattern } from "./constants";
|
|
6
|
+
import type { ShortcutMapping } from "../shortcuts/types";
|
|
7
|
+
|
|
8
|
+
export function getFlags(): string[] {
|
|
9
|
+
return CLI_FLAGS.flatMap((f) => (f.short ? [f.long, f.short] : [f.long]));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getFormatOptions(): string[] {
|
|
13
|
+
return [...VALID_OUTPUT_FORMATS];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getJsonPaths(): string[] {
|
|
17
|
+
return JSON_PATH_PATTERNS.map((p) => p.pattern);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getShortcutCompletions(): string[] {
|
|
21
|
+
return SHORTCUTS.map((s) => s.short);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getBuiltinCompletions(): string[] {
|
|
25
|
+
const builtinFns = Object.values(BUILTIN_FUNCTIONS);
|
|
26
|
+
const shortcutShorts = BUILTIN_SHORTCUTS.map((s) => s.short);
|
|
27
|
+
return [...new Set([...builtinFns, ...shortcutShorts])];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function formatZshFlag(flag: CliFlag): string {
|
|
31
|
+
const desc = flag.description.replace(/'/g, "\\'");
|
|
32
|
+
if (flag.long === "--format") {
|
|
33
|
+
return ` '${flag.long}[${desc}]:format:(${getFormatOptions().join(" ")})'`;
|
|
34
|
+
}
|
|
35
|
+
if (flag.long === "--list") {
|
|
36
|
+
return ` '${flag.long}[${desc}]:directory:_files -/'`;
|
|
37
|
+
}
|
|
38
|
+
if (flag.long === "--find") {
|
|
39
|
+
return ` '${flag.long}[${desc}]:path:_files'`;
|
|
40
|
+
}
|
|
41
|
+
return ` '${flag.long}[${desc}]'`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function formatZshShortcut(s: ShortcutMapping): string {
|
|
45
|
+
return ` '${s.short}:${s.full} - ${s.description}'`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function formatZshBuiltin(fn: string): string {
|
|
49
|
+
const alias = BUILTIN_SHORTCUTS.find((s) => s.full === fn);
|
|
50
|
+
const desc = alias ? `${alias.short} - ${alias.description}` : fn;
|
|
51
|
+
return ` '${fn}:${desc}'`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function formatZshPath(p: JsonPathPattern): string {
|
|
55
|
+
return ` '${p.pattern}:${p.description}'`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function generateZshOptsBlock(): string {
|
|
59
|
+
return CLI_FLAGS.map(formatZshFlag).join("\n");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function generateZshShortcutsBlock(): string {
|
|
63
|
+
return SHORTCUTS.map(formatZshShortcut).join("\n");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function generateZshBuiltinsBlock(): string {
|
|
67
|
+
return Object.values(BUILTIN_FUNCTIONS).map(formatZshBuiltin).join("\n");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function generateZshPathsBlock(): string {
|
|
71
|
+
return JSON_PATH_PATTERNS.map(formatZshPath).join("\n");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function generateZshCompletions(): string {
|
|
75
|
+
return `#compdef 1ls
|
|
76
|
+
|
|
77
|
+
_1ls() {
|
|
78
|
+
local -a opts shortcuts json_paths builtin_fns subcmds
|
|
79
|
+
|
|
80
|
+
opts=(
|
|
81
|
+
${generateZshOptsBlock()}
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
subcmds=(
|
|
85
|
+
'readFile:Read from file'
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
shortcuts=(
|
|
89
|
+
${generateZshShortcutsBlock()}
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
builtin_fns=(
|
|
93
|
+
${generateZshBuiltinsBlock()}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
json_paths=(
|
|
97
|
+
${generateZshPathsBlock()}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
local curcontext="$curcontext" state line
|
|
101
|
+
typeset -A opt_args
|
|
102
|
+
|
|
103
|
+
_arguments -C \\
|
|
104
|
+
"\${opts[@]}" \\
|
|
105
|
+
'1: :->subcmd' \\
|
|
106
|
+
'*:: :->args'
|
|
107
|
+
|
|
108
|
+
case $state in
|
|
109
|
+
subcmd)
|
|
110
|
+
_describe -t subcmds 'subcommands' subcmds
|
|
111
|
+
;;
|
|
112
|
+
args)
|
|
113
|
+
case $words[1] in
|
|
114
|
+
readFile)
|
|
115
|
+
_files
|
|
116
|
+
;;
|
|
117
|
+
*)
|
|
118
|
+
if [[ $words[$CURRENT] == .* ]]; then
|
|
119
|
+
_describe -t shortcuts 'shortcuts' shortcuts
|
|
120
|
+
_describe -t paths 'json paths' json_paths
|
|
121
|
+
else
|
|
122
|
+
_describe -t builtin_fns 'builtin functions' builtin_fns
|
|
123
|
+
fi
|
|
124
|
+
;;
|
|
125
|
+
esac
|
|
126
|
+
;;
|
|
127
|
+
esac
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
_1ls "$@"
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function generateBashCompletions(): string {
|
|
135
|
+
const opts = [...getFlags(), "readFile"].join(" ");
|
|
136
|
+
const formatOpts = getFormatOptions().join(" ");
|
|
137
|
+
const jsonPaths = getJsonPaths().join(" ");
|
|
138
|
+
const shortcuts = getShortcutCompletions().join(" ");
|
|
139
|
+
const builtinFns = getBuiltinCompletions().join(" ");
|
|
140
|
+
|
|
141
|
+
return `#!/bin/bash
|
|
142
|
+
|
|
143
|
+
_1ls_complete() {
|
|
144
|
+
local cur prev opts
|
|
145
|
+
COMPREPLY=()
|
|
146
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
147
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
148
|
+
|
|
149
|
+
opts="${opts}"
|
|
150
|
+
format_opts="${formatOpts}"
|
|
151
|
+
json_paths="${jsonPaths}"
|
|
152
|
+
shortcuts="${shortcuts}"
|
|
153
|
+
builtin_fns="${builtinFns}"
|
|
154
|
+
|
|
155
|
+
case "\${prev}" in
|
|
156
|
+
--format)
|
|
157
|
+
COMPREPLY=( $(compgen -W "\${format_opts}" -- \${cur}) )
|
|
158
|
+
return 0
|
|
159
|
+
;;
|
|
160
|
+
--list|--find|readFile)
|
|
161
|
+
COMPREPLY=( $(compgen -f -- \${cur}) )
|
|
162
|
+
return 0
|
|
163
|
+
;;
|
|
164
|
+
--ext)
|
|
165
|
+
COMPREPLY=( $(compgen -W "js ts tsx jsx json md txt yml yaml xml html css" -- \${cur}) )
|
|
166
|
+
return 0
|
|
167
|
+
;;
|
|
168
|
+
--shorten|--expand)
|
|
169
|
+
COMPREPLY=( $(compgen -W "\${json_paths}" -- \${cur}) )
|
|
170
|
+
return 0
|
|
171
|
+
;;
|
|
172
|
+
*)
|
|
173
|
+
;;
|
|
174
|
+
esac
|
|
175
|
+
|
|
176
|
+
if [[ \${cur} == -* ]]; then
|
|
177
|
+
COMPREPLY=( $(compgen -W "\${opts}" -- \${cur}) )
|
|
178
|
+
return 0
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
if [[ \${cur} == .* ]]; then
|
|
182
|
+
all_paths="\${json_paths} \${shortcuts}"
|
|
183
|
+
COMPREPLY=( $(compgen -W "\${all_paths}" -- \${cur}) )
|
|
184
|
+
return 0
|
|
185
|
+
fi
|
|
186
|
+
|
|
187
|
+
if [[ \${cur} =~ ^[a-zA-Z] ]]; then
|
|
188
|
+
COMPREPLY=( $(compgen -W "\${builtin_fns}" -- \${cur}) )
|
|
189
|
+
return 0
|
|
190
|
+
fi
|
|
191
|
+
|
|
192
|
+
COMPREPLY=( $(compgen -W "\${opts} \${builtin_fns}" -- \${cur}) )
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
complete -F _1ls_complete 1ls
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
echo "Installing 1ls shell completions..."
|
|
4
4
|
|
|
5
|
-
# Detect shell
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
# Detect shell from user's $SHELL, not the script interpreter
|
|
6
|
+
SHELL_NAME="$(basename "${SHELL:-}")"
|
|
7
|
+
if [ -z "$SHELL_NAME" ]; then
|
|
8
|
+
echo "Could not detect shell. Set the \$SHELL environment variable and re-run."
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
if [ "$SHELL_NAME" != "bash" ] && [ "$SHELL_NAME" != "zsh" ]; then
|
|
12
|
+
echo "Unsupported shell: $SHELL_NAME. Only bash and zsh are supported."
|
|
12
13
|
exit 1
|
|
13
14
|
fi
|
|
14
15
|
|