• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
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.
6
7# Source this file into your shell to gain the cr function and tab completion
8# for it
9
10# Make sure we're being sourced (possibly by another script). Check for bash
11# since zsh sets $0 when sourcing.
12if [[ -n "$BASH_VERSION" && "${BASH_SOURCE:-$0}" == "$0" ]]; then
13  echo "ERROR: cr-bash-helpers.sh must be sourced."
14  exit 1
15fi
16
17
18cr_base_dir=$(dirname $(realpath "${BASH_SOURCE:-$0}"))
19cr_main="${cr_base_dir}/main.py"
20cr_exec="PYTHONDONTWRITEBYTECODE=1 python ${cr_main}"
21
22# The main entry point to the cr tool.
23# Invokes the python script with pyc files turned off.
24function cr() {
25  env $cr_exec "$@"
26}
27
28# Attempts to cd to the root/src of the current client.
29function crcd() {
30  cd $(cr info -s CR_SRC)
31}
32
33# Add to your PS1 to have the current selected output directory in your prompt
34function _cr_ps1() {
35  cr info -s CR_OUT_FULL
36}
37
38# The tab completion handler, delegates into the python script.
39function _cr_complete() {
40  COMPREPLY=()
41  local cur="${COMP_WORDS[COMP_CWORD]}"
42  local main="python -B "${cr_main}")"
43  local completions="$(env COMP_CWORD=${COMP_CWORD} COMP_WORD=${cur} $cr_exec)"
44  COMPREPLY=( $(compgen -W "${completions}" -- ${cur}) )
45}
46
47# Setup the bash auto complete
48complete -F _cr_complete cr
49