OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Source this file into your shell to gain the cr function and tab completion | 7 # Source this file into your shell to gain the cr function and tab completion |
8 # for it | 8 # for it |
9 | 9 |
10 # Make sure we're being sourced (possibly by another script). Check for bash | 10 # Make sure we're being sourced (possibly by another script). Check for bash |
11 # since zsh sets $0 when sourcing. | 11 # since zsh sets $0 when sourcing. |
12 if [[ -n "$BASH_VERSION" && "${BASH_SOURCE:-$0}" == "$0" ]]; then | 12 if [[ -n "$BASH_VERSION" && "${BASH_SOURCE:-$0}" == "$0" ]]; then |
13 echo "ERROR: cr-bash-helpers.sh must be sourced." | 13 echo "ERROR: cr-bash-helpers.sh must be sourced." |
14 exit 1 | 14 exit 1 |
15 fi | 15 fi |
16 | 16 |
17 READLINK_e=("readlink" "-e") | 17 READLINK_e=("readlink" "-e") |
18 if [[ -x `which greadlink` ]]; then | 18 if [[ -x `which greadlink` ]]; then |
19 READLINK_e=("greadlink" "-e") | 19 READLINK_e=("greadlink" "-e") |
20 fi | 20 fi |
21 | 21 |
22 cr_base_dir=$(dirname $(${READLINK_e[@]} "${BASH_SOURCE:-$0}")) | 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}")) |
| 26 fi |
| 27 |
23 cr_main="${cr_base_dir}/main.py" | 28 cr_main="${cr_base_dir}/main.py" |
24 cr_exec=("PYTHONDONTWRITEBYTECODE=1" "python" "${cr_main}") | 29 cr_exec=("PYTHONDONTWRITEBYTECODE=1" "python" "${cr_main}") |
25 | 30 |
26 # The main entry point to the cr tool. | 31 # The main entry point to the cr tool. |
27 # Invokes the python script with pyc files turned off. | 32 # Invokes the python script with pyc files turned off. |
28 function cr() { | 33 function cr() { |
29 env ${cr_exec[@]} "$@" | 34 env ${cr_exec[@]} "$@" |
30 } | 35 } |
31 | 36 |
32 # Attempts to cd to the root/src of the current client. | 37 # Attempts to cd to the root/src of the current client. |
(...skipping 12 matching lines...) Expand all Loading... |
45 local cur="${COMP_WORDS[COMP_CWORD]}" | 50 local cur="${COMP_WORDS[COMP_CWORD]}" |
46 local main="python -B "${cr_main}")" | 51 local main="python -B "${cr_main}")" |
47 local completions="$(env COMP_CWORD=${COMP_CWORD} \ | 52 local completions="$(env COMP_CWORD=${COMP_CWORD} \ |
48 COMP_WORD=${cur} \ | 53 COMP_WORD=${cur} \ |
49 ${cr_exec[@]})" | 54 ${cr_exec[@]})" |
50 COMPREPLY=( $(compgen -W "${completions}" -- ${cur}) ) | 55 COMPREPLY=( $(compgen -W "${completions}" -- ${cur}) ) |
51 } | 56 } |
52 | 57 |
53 # Setup the bash auto complete | 58 # Setup the bash auto complete |
54 complete -F _cr_complete cr | 59 complete -F _cr_complete cr |
OLD | NEW |