Changes
3 changed files (+288/-0)
-
-
@@ -27,6 +27,7 @@ const update_snapshot = b.option(bool, "update-snapshot", "Update snapshot on snapshot tests") orelse false;const zsh_completion = b.option(bool, "zsh-completion", "Install Zsh completion file") orelse false; const fish_completion = b.option(bool, "fish-completion", "Install fish shell completion file") orelse false; const bash_completion = b.option(bool, "bash-completion", "Install bash completion file") orelse false; const exe = addExe(b, .{ .target = target,
-
@@ -103,6 +104,14 @@ if (fish_completion) {const install = b.addInstallFile( b.path("dist/completion.fish"), "share/fish/vendor_completions.d/sunwait.fish", ); root_step.dependOn(&install.step); } if (bash_completion) { const install = b.addInstallFile( b.path("dist/completion.bash"), "share/bash-completion/completions/sunwait", ); root_step.dependOn(&install.step); }
-
-
dist/completion.bash (new)
-
@@ -0,0 +1,243 @@# Copyright (C) 2025 Shota FUJI # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # # SPDX-License-Identifier: GPL-3.0-only # Overall architecture is from Jujutsu's bash completion script. # You can see it by `jj util completion bash` _sunwait() { local i current cmd prev opts common_opts COMPREPLY=() current="${COMP_WORDS[COMP_CWORD]}" cmd="" prev="$3" opts="" common_opts="-h --help -v --version --debug --utc --latitude --longitude --twilight -o --offset " for i in "${COMP_WORDS[@]:0:COMP_CWORD}" do case "${cmd},${i}" in ",$1") cmd="sunwait" ;; sunwait,poll) cmd="sunwait__poll" ;; sunwait,list) cmd="sunwait__list" ;; sunwait,report) cmd="sunwait__report" ;; sunwait,wait) cmd="sunwait__wait" ;; esac done case "${cmd}" in # sunwait [OPTIONS] sunwait) opts="${common_opts} poll list report wait" if [[ ${current} == -* || ${COMP_CWORD} -eq 1 ]]; then COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 fi case "${prev}" in --latitude) COMPREPLY=() return 0 ;; --longitude) COMPREPLY=() return 0 ;; -o) COMPREPLY=() return 0 ;; --offset) COMPREPLY=() return 0 ;; --twilight) COMPREPLY=($(compgen -W "daylight civil nautical astronomical" -- "${current}")) return 0 ;; esac COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 ;; # sunwait poll [OPTIONS] sunwait__poll) opts="${common_opts} --at" if [[ ${current} == -* || ${COMP_CWORD} -eq 2 ]]; then COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 fi case "${prev}" in --latitude) COMPREPLY=() return 0 ;; --longitude) COMPREPLY=() return 0 ;; -o) COMPREPLY=() return 0 ;; --offset) COMPREPLY=() return 0 ;; --twilight) COMPREPLY=($(compgen -W "daylight civil nautical astronomical" -- "${current}")) return 0 ;; --at) COMPREPLY=() return 0 ;; esac COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 ;; # sunwait wait [OPTIONS] sunwait__wait) opts="${common_opts} -e --event" if [[ ${current} == -* || ${COMP_CWORD} -eq 2 ]]; then COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 fi case "${prev}" in --latitude) COMPREPLY=() return 0 ;; --longitude) COMPREPLY=() return 0 ;; -o) COMPREPLY=() return 0 ;; --offset) COMPREPLY=() return 0 ;; --twilight) COMPREPLY=($(compgen -W "daylight civil nautical astronomical" -- "${current}")) return 0 ;; -e) COMPREPLY=($(compgen -W "sunrise sunset" -- "${current}")) return 0 ;; --event) COMPREPLY=($(compgen -W "sunrise sunset" -- "${current}")) return 0 ;; esac COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 ;; # sunwait report [OPTIONS] sunwait__report) opts="${common_opts} --date" if [[ ${current} == -* || ${COMP_CWORD} -eq 2 ]]; then COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 fi case "${prev}" in --latitude) COMPREPLY=() return 0 ;; --longitude) COMPREPLY=() return 0 ;; -o) COMPREPLY=() return 0 ;; --offset) COMPREPLY=() return 0 ;; --twilight) COMPREPLY=($(compgen -W "daylight civil nautical astronomical" -- "${current}")) return 0 ;; --date) COMPREPLY=() return 0 ;; esac COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 ;; # sunwait list [OPTIONS] sunwait__list) opts="${common_opts} --from -e --event" if [[ ${current} == -* || ${COMP_CWORD} -eq 2 ]]; then COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 fi case "${prev}" in --latitude) COMPREPLY=() return 0 ;; --longitude) COMPREPLY=() return 0 ;; -o) COMPREPLY=() return 0 ;; --offset) COMPREPLY=() return 0 ;; --twilight) COMPREPLY=($(compgen -W "daylight civil nautical astronomical" -- "${current}")) return 0 ;; --from) COMPREPLY=() return 0 ;; -e) COMPREPLY=($(compgen -W "sunrise sunset" -- "${current}")) return 0 ;; --event) COMPREPLY=($(compgen -W "sunrise sunset" -- "${current}")) return 0 ;; esac COMPREPLY=($(compgen -W "${opts}" -- "${current}")) return 0 ;; esac } complete -F _sunwait sunwait
-
-
-
@@ -70,6 +70,7 @@ zigBuildFlags = ["-Dman" "-Dzsh-completion" "-Dfish-completion" "-Dbash-completion" ]; };
-
@@ -135,6 +136,41 @@ in{ type = "app"; program = "${test-fish}/bin/fish"; }; # $ nix run .#bash # Bare-bone bash session for testing completion bash = let test-bash = pkgs.symlinkJoin { name = "sunwait-test-bash"; nativeBuildInputs = [ pkgs.makeWrapper ]; paths = [ pkgs.bash pkgs.bash-completion self.packages.${system}.default ]; postBuild = '' mkdir -p $out/share/$name echo 'if ! shopt -oq posix; then' >> $out/share/$name/.bashrc echo ' source ${pkgs.bash-completion}/share/bash-completion/bash_completion' >> $out/share/$name/.bashrc echo 'fi' >> $out/share/$name/.bashrc chmod +x $out/share/$name/.bashrc wrapProgram $out/bin/bash \ --set MANPATH :${sunwait}/share/man \ --prefix PATH : ${pkgs.lib.makeBinPath [ sunwait ]} \ --add-flags '--rcfile' \ --add-flags $out/share/$name/.bashrc ''; }; in { type = "app"; program = "${test-bash}/bin/bash"; }; };
-