Better shell completion
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start in lib/src/installer/shell_completion_configuration.dart, especially the existing zsh completion generation linked in the issue, and compare it with the proposed standard script. The completed change should generate zsh completion files with the program directive and first-run behavior described, while preserving the existing completion command integration.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Intro
In this issue I will explain how to automatically provide your CLI app's shell completions to your users in a seamless way.
I've been recently investigating how shell completion works, and various approaches to it. I decided to write my findings down to share knowledge with others, and to (hopefully) improve this package's documentation and functionality so that we can improve how shell completions are distributed for Dart CLI apps.
Intended audience: authors of CLI tools written in Dart that depend on cli_completion package
Description
That's how the original zsh completion script provided by this package looks like this. Let's assume our CLI app name is foobar and that we called foobar install-completion-files, which generates the following zsh shell completion script in ~/.config/.dart-cli-completion/foobar.zsh:
Original zsh completion file for "foobar"
if type compdef &>/dev/null; then
_foobar_completion () {
local reply
local si=$IFS
IFS=$'
' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" foobar completion -- "${words[@]}"))
IFS=$si
if [[ -z "$reply" ]]; then
_path_files
else
_describe 'values' reply
fi
}
compdef _foobar_completion foobar
fi
I modified the script above a bit to be a "standard" zsh completion script, that is:
- it has
#compdef <program_name>at the top ->#compdef foobar - it is named
_<program_name>->_foobar - it works well on "first run" (you don't have to click TAB twice to initalize it on first run, like it is now) (another description of this issue)
Modified zsh completion file for "foobar"
#compdef foobar
local reply
local si=$IFS
IFS=$'
'
reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" foobar completion -- "${words[@]}"))
IFS=$si
if [[ -z "$reply" ]]; then
_path_files
else
_describe 'values' reply
fi
Now I put that script to zsh's conventional location for shell completion scripts - in case of my macOS, it's /opt/homebrew/share/zsh/site-functions:
cp _foobar /opt/homebrew/share/zsh/site-functions
Restart zsh by running exec zsh and voilà, the completion for foobar should work now!
If it does not, make sure you're adding opt/homebrew/share/zsh/site-function to your $FPATH - see relevant docs.
Distribution
With the above in mind, I can easily write e.g. a Homebrew formula for my CLI tool, and inside that formula put shell completion installation files:
# excerpt from a hypothetical foobar.rb Formula
def install
bin.install "foobar"
bash_completion.install "autocomplete/bash_autocomplete" => "foobar"
zsh_completion.install "autocomplete/zsh_autocomplete" => "_foobar"
end
Note that this automatic setup of completion files is only possible when your CLI app is installed through a proper package manager, like Homebrew or Pacman. If it is installed with dart pub global activate, the approach I described here won't work, because dart pub global activate only compiles the Dart source code to a JIT executable, and doesn't have any way of also copying files – which is required for automatical installation of shell completion.
But even if you prefer to install your Dart CLI app with dart pub global activate, you can distribute the completion scripts in different way – e.g. as an oh-my-zsh plugin – or you can just provide the completion script and tell your users "hey, install it at this-and-that path". I think it's much better than appending some code to ~/.zshrc or ~/.bashrc.
- Ngôn ngữ chính
- Dart
- Star
- 54
- Fork
- 6
- Merge trung bình
- 3 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của VeryGoodOpenSource/cli_completion
-
feature p3
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
VeryGoodOpenSource/cli_completion#91 · 2 bình luận · 1 reaction ·
-
feat: CLI-user configurable auto installCó thể làm lại được @vgvbot đã nhận 38 ngày trước và không có pull request nào đang mở. Đang mởfeature p2
VeryGoodOpenSource/cli_completion#55 · 1 bình luận · 1 reaction · 1 người được giao ·
-
feature p2
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
VeryGoodOpenSource/cli_completion#47 · 2 bình luận · 2 reaction ·
Tất cả issue của VeryGoodOpenSource/cli_completion
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
jiangtian616/JHenTai#833 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
decentespresso/decaid#913 ·
Maintainer thường phản hồi trong vòng 1 ngày