Never type your workflow IDs again!

We don't have full shell completion for the Bitrise CLI (yet!) but for now, we can show you some clever snippets with which you can enable completion at least for the bitrise run command.

Note: This feature requires Bitrise CLI 1.10.1 or higher to work.

We don't have full shell completion for the Bitrise CLI (yet!) but for now, we can show you some clever snippets with which you can enable completion at least for the bitrise run command. You don't have to remember long workflow IDs anymore if you spend a lot of time in the terminal - after inserting these shell functions into the right place you'll be able to do the following:

Opens in a new window

Bash


_bitrise() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    if ! opts="$(bitrise workflows --id-only 2> /dev/null)"; then
        opts=""
    fi

    if [[ ${prev} == "run" && ${cur} == * ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _bitrise bitrise
Copy code

You can insert this function into your .profile, .bash_profile or .bashrc file (depending on whichever you use) or you can place it along with other completion files in a directory (e.g. /usr/local/etc/bash_completion.d). To do the second, you can find some tips here.

Zsh


#compdef bitrise

_bitrise() {
    local state
    local -a opts
    if ! opts=( $(bitrise workflows --id-only 2> /dev/null) ); then
        opts=( )
    fi

    _arguments \
        '1: :->subcommand' \
        '2: :->workflow_name'

    case ${state} in
        (subcommand) _arguments '1:wf:(run)' ;;
	    (workflow_name) compadd -Q "$@" ${opts}
    esac
}

_bitrise "$@"
Copy code

Zsh loads completion functions from the directories present in the $fpath variable so paste the snippet into a file called _bitrise and place it into one of the directories listed in $fpath.


$ echo $fpath
/Users/gabortakacs/.oh-my-zsh/plugins/git /Users/gabortakacs/.oh-my-zsh/functions /Users/gabortakacs/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.3/functions
Copy code
Note: There is a good chance /usr/local/share/zsh/site-functions and /usr/share/zsh/site-functions are added to the $fpath variable by default, so those two directories may be the best candidates.

If you use vanilla zsh and don't have any extension tools installed (e.g. oh-my-zsh or prezto, both will do the completion init for you) remember to call autoload -U compinit && compinit from your .zshrc.

Update (2017/12/11):

You might have to force rebuild the .zcompdump file:


$ rm -f ~/.zcompdump; compinit
Copy code

Fish


complete -f -c bitrise -n '__fish_use_subcommand' -a run -d 'run specified workflow'
complete -f -c bitrise -n '__fish_seen_subcommand_from run' -a (bitrise workflows --id-only)
Copy code

Fish might be the simplest one: just copy the above snippet into ~/.config/fish/completions/bitrise.fish and you're good to go!

Happy shelling! 🐚

No items found.

Explore more topics

App development

Best practices from engineers on how to use Bitrise to build better apps, faster.

Community

Meet other Bitrise engineers, technology experts, power users, partners and join our BUGs.

Company

All the updates about Bitrise events, sponsorships, employees, and more.

Insights

Mobile development, latest tech, industry insights, and interviews with experts.

Mobile DevOps

Learn why mobile development is unique and requires a set of unique practices.

Releases

Stay tuned for the last updates, new features, and product improvements.

Get the latest from Bitrise

Join other Mobile DevOps engineers who receive regular emails from Bitrise, filled with tips, news, and best practices.