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 "[email protected]" ${opts}
    esac
}

_bitrise "[email protected]"
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.
The Mobile DevOps Newsletter

Explore more topics

App Development

Learn how to optimize your mobile app deployment processes for iOS, Android, Flutter, ReactNative, and more

Bitrise & Community

Check out the latest from Bitrise and the community. Learn about the upcoming mobile events, employee spotlights, women in tech, and more

Bitrise Insights

Cache | Caching

Mobile App Releases

Learn how to release faster, better apps on the App Store, Google Play Store, Huawei AppGallery, and other app stores

Mobile DevOps

Learn Mobile DevOps best practices such as DevOps for iOS, Android, and industry-specific DevOps tips for mobile engineers

Mobile Testing & Security

Learn how to optimize mobile testing and security — from automated security checks to robust mobile testing and more.

Product Updates

Check out the latest product updates from Bitrise — Build Insights updates, product news, and more.

The Mobile DevOps Newsletter

Join 1000s of your peers. Sign up to receive Mobile DevOps tips, news, and best practice guides once every two weeks.