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

📺 Add zsh completions #514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

📺 Add zsh completions #514

wants to merge 1 commit into from

Conversation

Logicer16
Copy link

#222 has been open for over 5 years now (🥳 congrats). About time someone took care of it, especially as it's the default shell.

Closes #222

Please let me know of any questions/suggestions you might have.

contrib/completion/mas-completion.zsh Show resolved Hide resolved
contrib/completion/mas-completion.zsh Show resolved Hide resolved
contrib/completion/mas-completion.zsh Show resolved Hide resolved
contrib/completion/mas-completion.zsh Show resolved Hide resolved
contrib/completion/mas-completion.zsh Show resolved Hide resolved
'1:name:__mas_list_available' \
&& ret=0
;;
open)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern never matches because of a previous pattern on line 17.

contrib/completion/mas-completion.zsh Show resolved Hide resolved
contrib/completion/mas-completion.zsh Outdated Show resolved Hide resolved
contrib/completion/mas-completion.zsh Show resolved Hide resolved
contrib/completion/mas-completion.zsh Show resolved Hide resolved
@@ -0,0 +1,165 @@
#! /usr/bin/env zsh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!

@Logicer16
Copy link
Author

Let me know if any of these reviews are an actual concern as most aren't applicable.

}

__mas_search_names() {
[[ -z "$words[-1]" ]] && return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument to -z is always false due to literal strings.

}

__mas_search_ids() {
[[ -z "$words[-1]" ]] && return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument to -z is always false due to literal strings.

contrib/completion/mas-completion.zsh Show resolved Hide resolved
@Logicer16 Logicer16 force-pushed the main branch 2 times, most recently from c6db308 to 63d0fe8 Compare May 17, 2024 10:13

case "$state" in
args)
case $words[1] in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use braces when expanding arrays, e.g. ${array[idx]} (or ${var}[.. to quiet).

@@ -0,0 +1,166 @@
#compdef mas
# shellcheck shell=zsh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shell type is unknown. Use e.g. sh or bash.

@Logicer16 Logicer16 marked this pull request as ready for review May 17, 2024 10:59
__mas_strip_price "$1" | sed -nEe 's/^[[:space:]]*([0-9\-]+)[[:space:]]*(.*)/\1:\2/pg'
}

__mas_strip_price() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__mas_strip_price seems to strip version, not price.

If that's correct, should it be renamed __mas_strip_version?

}

__mas_strip_price() {
echo "$1" | sed -nEe 's/[[:space:]]+\(.*\).*$//pg' | sed 's/:/\\:/g'
Copy link
Contributor

@rgoldberg rgoldberg Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you amenable to replacing sed usages here & elsewhere with native zsh expansions? It should be faster and also remove the external sed dependency.

The following should work here:

printf $'%s\n' "${${(*@F)${(f)1}%% ##\([^(]##}//:/\\:}"

If you're OK with that, I can write the zsh for the other functions, too, if you want.

'installedNames:apps:__mas_list_installed_names'
}

__mas_search_ids() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the purpose of this to allow you to type part of an app name (instead of an app ID) as the argument, have mas search search for matching app names, then allow you to autocomplete from the app name to the app ID?

If so, it's not working for me. Is it working for you? If so, what version of zsh are you using? How was it installed? What version of macOS? etc.

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

Successfully merging this pull request may close these issues.

📺 zsh command completion
3 participants