Skip to content
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

[BUG] Shell completions scripts are broken #12

Open
LucasVanHaaren opened this issue Dec 10, 2024 · 1 comment
Open

[BUG] Shell completions scripts are broken #12

LucasVanHaaren opened this issue Dec 10, 2024 · 1 comment

Comments

@LucasVanHaaren
Copy link

LucasVanHaaren commented Dec 10, 2024

Hey,

Tying to play around with rfswift, I discovered that the wrapper generated completions scripts won't work (produced by rfswift completion).

I only tested on Linux with bash but I assume this won't work for any shell because scripts are embedding the cli greeter (the beautiful ASCII art) and the version information line.

Experiments to reproduce

1. The naive try

  • Here I try to generate the bash completion script but the header is printed on stdout :
❯ rfswift completion bash | sudo tee /etc/bash_completion.d/rfswift


                  -%@%-                     :==-.
                :%:*+=:+%.             .%@%#%+-:-=%@*
              %==#=: .  .+#          :@%:*==--:   .  =%.
            :@=::+#:.  .+-:%.       %@:*+==..=**+=-:::=#=
           +****=:+. +=::*#-%-    .@+:*.:.:=***:.::...:*#*
          ::%*#*:* :+- *:-.=%**. =@:+*+:.==.:::=::   .-:.:#+
          :*%#**%.-%%%+ :#:#+:.=#%%@@*.:==++.=:.-#@@@#:*==+=%
           %#@+*:       +%##+%@@@%=...==-+= ::%@*#@%#%%%@%=*=*
          :*#%#*.     .=: **@%%%%#==+=-=+: .+@:   %*+%=...*@+@:
           +=*+*@:   ::. .@*@@@@#*+*##%*::=@*    :%*-:-%*.  *@:
           ::.@=@=#=  . =@@@@%=*#*%@%===+%@+=*%*:*%=%.--*#-: %*
              ##@:==%%%@@@@#=#%#*-:-=*%@@@%+:::=%%=#-:-:-@:= .@
              .%@. :==@@@%#@@@*=*#===:: .:=+***=+**.::-:-%=+ :@
               *@:    %%@@@%+=*@@@%%%*====-::.    ::=-=:*%=-.@*
          .*%%%*=.   :@%:.  .*%=::*#@@@@%*=::::::::..:*@#-:.%%.
         **  =%.-  .  @@      :@%*=:::==+**%%@@@@@@@%*=:..*@*
         %: =@:       %@:      .@+%@%#==--::::----:::.:*@*:=#%@=
         -%*%.        :@* :.    :@.  :=%@@%%%#**#%%@@#-:#*:   %=
         .@=   ..      #@-**.    -@:        .#*#%.  :%=.    :@*
        :%.   --     =++@@=+*.    :%.       +**@@%@+-:::*  %@@.
        %@-  -*   =%@@@@@@%=**:    =%   :#@@=%@@@@-   .%.%@@*
        @@@+.=*:-@@@@%%%@%@%%@#:   :#@@=.   *#.:-@#   *@@@@%
        %@%@%=**@@%%%%@@@@@@@*.=@#:  .*%:+%*-    *@%@@@@@:*=
        :@@@@@#@@@@@@@@@@= :*:  :*@@=  ** *+====-@@@@@#. *=
          :@@@@@@@@@@+     .=%@@-    -#     :#@@@@@@@@--%.
           :@@@@@#:.:- .=@@%=       .%%%@@@@@@@*: :%@@%.
            #@*.:=-:=%@@*...:::::..         .=+***=#@%
            -@=--*@@@*            :=+#%%#+::       #@@=%:
            .@*%@@*.                        .-+=:.:@@@* -#=.
             *@%=                                          .:
              :


	888~-_   888~~        ,d88~~\                ,e,   88~\   d8
	888   \  888___       8888    Y88b    e    /  "  _888__ _d88__
	888    | 888          'Y88b    Y88b  d8b  /  888  888    888
	888   /  888           'Y88b,   Y888/Y88b/   888  888    888
	888_-~   888             8888    Y8/  Y8/    888  888    888
	888 ~-_  888          \__88P'     Y    Y     888  888    "88_/

                RF toolbox for HAMs and professionals

[+] You are running version: 0.5.5 (Up to date)
# bash completion V2 for rfswift                              -*- shell-script -*-

__rfswift_debug()
{
    if [[ -n ${BASH_COMP_DEBUG_FILE-} ]]; then
        echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
    fi
}

# Macs have bash3 for which the bash-completion package doesn't include
  • This result on these types of errors when resourcing the shell because it try to parse ASCII art chars :
[...]
bash: $'\E[33m': command not found
bash: $'\E[32m': command not found
bash: $'\E[36m': command not found
bash: $'\E[34m\E[0m': command not found
bash: $'\E[35m': command not found
bash: $'\E[31m': command not found
bash: $'\E[35m\E[0m': command not found
bash: $'\E[31m': command not found
bash: $'\E[33m\E[0m': command not found
bash: /etc/bash_completion.d/rfswift: line 45: syntax error near unexpected token `('
bash: /etc/bash_completion.d/rfswift: line 45: `[+] You are running version: 0.5.5 (Up to date)'

vh ~

2. Second fail

  • I also tried to strip this header to the completion script only, this obviously stop the errors on shell sourcing but I caught this error when tabbing after rfswift :
vh ~
❯ rfswift
^[[31m                                                                                                    ^[[0m
^[[31m            .@*%@@*.                        .-+=:.:@@@* -#=.                                                                                          ^[[0m
^[[31m           +****=:+. +=::*#-%-    .@+:*.:.:=***:.::...:*#*                                                                                            ^[[0m
^[[31m           ::.@=@=#=  . =@@@@%=*#*%@%===+%@+=*%*:*%=%.--*#-: %*                                                                                       ^[[0m
^[[31m         %: =@:       %@:      .@+%@%#==--::::----:::.:*@*:=#%@=                                                                                      ^[[0m
^[[31m        %@%@%=**@@%%%%@@@@@@@*.=@#:  .*%:+%*-    *@%@@@@@:*=                                                                                          ^[[0m
^[[31m  (888   \  888___       8888    Y88b    e    /  "  _888__ _d88__ ^[[0m)
^[[31m                RF toolbox for HAMs and professionals                                                                             ^[[0m
^[[32m                  -%@%-                     :==-.                                                                                                     ^[[0m
^[[32m              .%@. :==@@@%#@@@*=*#===:: .:=+***=+**.::-:-%=+ :@                                                                                       ^[[0m
^[[32m              :                                                                                                                                                                                                    ^[[0m
^[[32m          :*%#**%.-%%%+ :#:#+:.=#%%@@*.:==++.=:.-#@@@#:*==+=%                                                                                         ^[[0m
^[[32m          :@@@@@@@@@@+     .=%@@-    -#     :#@@@@@@@@--%.                                                                                            ^[[0m
^[[32m         .@=   ..      #@-**.    -@:        .#*#%.  :%=.    :@*                                                                                       ^[[0m
[...]

Note on setup

  • version: 0.5.5

Conclusion

  • Any hints about this issue ? I personally think header should be printed only for some commands (and surely not on the completion one).
  • I don't know too much about go but I can try to contribute !

Thanks for your work on this 💌

@FlUxIuS
Copy link
Contributor

FlUxIuS commented Dec 10, 2024

Hey thanks for the feedback!

Hmm that is a feature I never used to be honest as it is generated with the Go module cobra... I will try to fix it or maybe provide a clean auto completion on an independent file during install with install.sh :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants