Add ICU message format support
[chromium-blink-merge.git] / tools / cr / cr-bash-helpers.sh
blob3fa6a8aa93b3089aff48ff51c14425aeac896ded
1 #!/bin/bash
3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # Source this file into your shell to gain the cr function and tab completion
8 # for it
10 # Make sure we're being sourced (possibly by another script). Check for bash
11 # since zsh sets $0 when sourcing.
12 if [[ -n "$BASH_VERSION" && "${BASH_SOURCE:-$0}" == "$0" ]]; then
13 echo "ERROR: cr-bash-helpers.sh must be sourced."
14 exit 1
17 READLINK_e=("readlink" "-e")
18 if [[ -x `which greadlink` ]]; then
19 READLINK_e=("greadlink" "-e")
22 if [[ $(uname) == "Darwin" ]]; then
23 cr_base_dir=$(dirname "${BASH_SOURCE:-$0}")
24 else
25 cr_base_dir=$(dirname $(${READLINK_e[@]} "${BASH_SOURCE:-$0}"))
28 cr_main="${cr_base_dir}/main.py"
29 cr_exec=("PYTHONDONTWRITEBYTECODE=1" "python" "${cr_main}")
31 # The main entry point to the cr tool.
32 # Invokes the python script with pyc files turned off.
33 function cr() {
34 env ${cr_exec[@]} "$@"
37 # Attempts to cd to the root/src of the current client.
38 function crcd() {
39 cd $(cr info -s CR_SRC)
42 # Add to your PS1 to have the current selected output directory in your prompt
43 function _cr_ps1() {
44 cr info -s CR_OUT_FULL
47 # The tab completion handler, delegates into the python script.
48 function _cr_complete() {
49 COMPREPLY=()
50 local cur="${COMP_WORDS[COMP_CWORD]}"
51 local main="python -B "${cr_main}")"
52 local completions="$(env COMP_CWORD=${COMP_CWORD} \
53 COMP_WORD=${cur} \
54 ${cr_exec[@]})"
55 COMPREPLY=( $(compgen -W "${completions}" -- ${cur}) )
58 # Setup the bash auto complete
59 complete -F _cr_complete cr