-
Notifications
You must be signed in to change notification settings - Fork 15
feat(zsh): add lazy-load initialization APIs #131
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
Merged
+1,582
−82
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1054d73
feat(zsh): add lazy-load initialization APIs
yuki-yano bd72506
test(zsh): format lazy-load shell tests
yuki-yano df73b46
fix(zsh): stabilize bootstrap root resolution
yuki-yano 048cffe
fix(config): search ~/.config when XDG home is unset
yuki-yano c22e8a6
fix(review): address lazy-load feedback
yuki-yano e51cc80
test(zsh): cover lightweight lazy bindings
yuki-yano d605fe1
fix(config): normalize XDG base dirs
yuki-yano 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #autoload | ||
|
|
||
| function zeno-bind-default-keys() { | ||
| emulate -L zsh | ||
|
|
||
| local lazy=0 arg | ||
| local -a lazy_widgets | ||
|
|
||
| for arg in "$@"; do | ||
| case "$arg" in | ||
| --lazy) | ||
| lazy=1 | ||
| ;; | ||
| *) | ||
| print -u2 -- "zeno-bind-default-keys: unsupported option: $arg" | ||
| return 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| lazy_widgets=( | ||
| zeno-auto-snippet | ||
| zeno-auto-snippet-and-accept-line | ||
| zeno-completion | ||
| zeno-insert-snippet | ||
| zeno-preprompt | ||
| zeno-preprompt-snippet | ||
| zeno-history-selection | ||
| ) | ||
|
|
||
| if (( lazy )); then | ||
| zeno-register-lazy-widgets "${(@)lazy_widgets}" || return $? | ||
| else | ||
| zeno-ensure-loaded || return $? | ||
| local widget_name | ||
| for widget_name in "${(@)lazy_widgets}"; do | ||
| zle -N -- "$widget_name" || return $? | ||
| done | ||
| fi | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| bindkey ' ' zeno-auto-snippet | ||
| bindkey '^m' zeno-auto-snippet-and-accept-line | ||
| bindkey '^i' zeno-completion | ||
| bindkey '^xx' zeno-insert-snippet | ||
| bindkey '^x ' zeno-insert-space | ||
| bindkey '^x^m' accept-line | ||
| bindkey '^x^z' zeno-toggle-auto-snippet | ||
| bindkey '^xp' zeno-preprompt | ||
| bindkey '^xs' zeno-preprompt-snippet | ||
| bindkey '^r' zeno-history-selection | ||
yuki-yano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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,11 @@ | ||
| #autoload | ||
|
|
||
| function zeno-ensure-loaded() { | ||
| emulate -L zsh | ||
|
|
||
| if [[ ${ZENO_LOADED-} == 1 ]]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| zeno-init "$@" | ||
| } |
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,48 @@ | ||
| #autoload | ||
|
|
||
| function zeno-init() { | ||
| emulate -L zsh | ||
|
|
||
| if [[ ${ZENO_LOADED-} == 1 ]]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| if [[ -z ${ZENO_ROOT-} ]]; then | ||
| print -u2 -- "zeno-init: ZENO_ROOT is not set; source zeno-bootstrap.zsh first" | ||
| return 1 | ||
| fi | ||
|
|
||
| if [[ -z ${ZENO_DISABLE_EXECUTE_CACHE_COMMAND-} ]]; then | ||
| command deno cache --node-modules-dir=auto --no-lock --no-check -- "${ZENO_ROOT}/src/cli.ts" || | ||
| return $? | ||
| fi | ||
|
|
||
| if [[ -z ${ZENO_DISABLE_SOCK-} ]]; then | ||
| local raw_deno_version deno_version | ||
| local -a v_parts | ||
| raw_deno_version=$(deno -V 2>/dev/null) | ||
| v_parts=(${(s:.:)${${(z)raw_deno_version}[2]-0.0.0}}) | ||
| v_parts[1]=${v_parts[1]//[^0-9]/} | ||
| v_parts[2]=${v_parts[2]//[^0-9]/} | ||
| v_parts[3]=${${v_parts[3]-0}%%[^0-9]*} | ||
| printf -v deno_version '%d%02d%02d' \ | ||
| ${v_parts[1]:-0} \ | ||
| ${v_parts[2]:-0} \ | ||
| ${v_parts[3]:-0} | ||
| if (( deno_version >= 11600 )); then | ||
| zeno-enable-sock || return $? | ||
| else | ||
| export ZENO_DISABLE_SOCK=1 | ||
| fi | ||
| fi | ||
|
|
||
| if (( $+functions[zeno-history-hooks] )); then | ||
| zeno-history-hooks || return $? | ||
| fi | ||
|
|
||
| if (( $+functions[zeno-preprompt-hooks] )); then | ||
| zeno-preprompt-hooks || return $? | ||
| fi | ||
|
|
||
| export ZENO_LOADED=1 | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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,22 @@ | ||
| #autoload | ||
|
|
||
| function zeno-lazy-widget-dispatch() { | ||
| emulate -L zsh | ||
|
|
||
| local widget_name="${WIDGET-}" | ||
| if [[ -z $widget_name ]]; then | ||
| return 1 | ||
| fi | ||
|
|
||
| if ! zeno-ensure-loaded; then | ||
| zeno-run-lazy-fallback "$widget_name" | ||
| return $? | ||
| fi | ||
|
|
||
| if (( $+functions[$widget_name] )); then | ||
| "$widget_name" | ||
| return $? | ||
| fi | ||
|
|
||
| return 1 | ||
| } |
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,7 @@ | ||
| #autoload | ||
|
|
||
| function zeno-preload() { | ||
| emulate -L zsh | ||
|
|
||
| zeno-ensure-loaded "$@" | ||
| } |
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,20 @@ | ||
| #autoload | ||
|
|
||
| function zeno-register-lazy-widget() { | ||
| emulate -L zsh | ||
|
|
||
| local widget_name="$1" | ||
| if [[ -z $widget_name ]]; then | ||
| print -u2 -- "zeno-register-lazy-widget: widget name is required" | ||
| return 1 | ||
| fi | ||
|
|
||
| if [[ ${ZENO_BOOTSTRAPPED-} != 1 ]]; then | ||
| print -u2 -- "zeno-register-lazy-widget: source zeno-bootstrap.zsh first" | ||
| return 1 | ||
| fi | ||
|
|
||
| typeset -gA ZENO_LAZY_WIDGETS | ||
| ZENO_LAZY_WIDGETS[$widget_name]=1 | ||
| zle -N -- "$widget_name" zeno-lazy-widget-dispatch | ||
| } |
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,10 @@ | ||
| #autoload | ||
|
|
||
| function zeno-register-lazy-widgets() { | ||
| emulate -L zsh | ||
|
|
||
| local widget_name | ||
| for widget_name in "$@"; do | ||
| zeno-register-lazy-widget "$widget_name" || return $? | ||
| done | ||
| } |
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,47 @@ | ||
| #autoload | ||
|
|
||
| function zeno-run-lazy-fallback() { | ||
| emulate -L zsh | ||
|
|
||
| local widget_name="$1" | ||
| local fallback_widget | ||
|
|
||
| case "$widget_name" in | ||
| zeno-completion) | ||
| fallback_widget=${ZENO_COMPLETION_FALLBACK:-${${widgets[fzf-completion]+fzf-completion}:-expand-or-complete}} | ||
| zle "$fallback_widget" | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ;; | ||
| zeno-auto-snippet) | ||
| fallback_widget=${ZENO_AUTO_SNIPPET_FALLBACK:-self-insert} | ||
| zle "$fallback_widget" | ||
| ;; | ||
| zeno-auto-snippet-and-accept-line) | ||
| zle accept-line | ||
| ;; | ||
| zeno-history-selection) | ||
| zle history-incremental-search-backward | ||
| ;; | ||
| zeno-smart-history-selection) | ||
| if (( $+widgets[zeno-history-selection] || $+functions[zeno-history-selection] )); then | ||
| zle zeno-history-selection | ||
| else | ||
| zle history-incremental-search-backward | ||
| fi | ||
| ;; | ||
| zeno-insert-space) | ||
| LBUFFER+=" " | ||
| if [[ -n ${RBUFFER+x} ]]; then | ||
| BUFFER="${LBUFFER}${RBUFFER}" | ||
| fi | ||
yuki-yano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (( $+CURSOR )); then | ||
| CURSOR=${#LBUFFER} | ||
| fi | ||
| ;; | ||
| zeno-insert-snippet|zeno-preprompt|zeno-preprompt-snippet|zeno-ghq-cd) | ||
| zle redisplay 2>/dev/null || true | ||
| ;; | ||
| *) | ||
| return 1 | ||
| ;; | ||
| esac | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.